/* SPL Visualization - SPL Total CD checkin on Feb 1, 2008 ** Name: Yung-Ting Chuang ** Class: MAT259 ** Perm Number: 607-3217 ** In this project I collected all ** CDs that is being checkin on Feb 1, 2008 */ import proxml.*; // imports the proxml library import processing.opengl.*; import damkjer.ocd.*; PFont font; Camera camera1, camera2, camera3, camera4; int cameraONE=0, cameraTWO=0, cameraTHREE=0, cameraFOUR=0; //SET THE FLAG FOR DIFFERENT VERSION OF MY WORK... int readyToAnimate = 0; XMLInOut xml; // creates a variable named 'xml' that will hold an XMLInOut object boolean isXMLParsed = false; boolean shift = true; /* GRAPH STYLE INFORMATION */ int graphXPos = 100; // the x Position of the graph int graphYPos = 50; int graphWidth = 775; // graph width int graphHeight = 650; int graphMonth = 0; int nextMonth = 1; float monthDifference, monthDifference2, monthDifference3; float monthDifference_1, monthDifference2_1, monthDifference3_1; int animateCounter = 0; int initialCounter = 8; int initialB=1, initialC=8, initialMonth=0; String filename="yt_2007.csv"; String filenameShort; String[] filenameType; int zero=0, one=1, stop=0, dots=1, lines=1, caption=0; int[][][][] data = new int[12][31][24][2]; void setup() { frameRate(20); size(824,568, P3D); sphereDetail(8); noStroke(); camera1 = new Camera(this, 0,0,490); camera2 = new Camera(this, 0,0,490); camera3 = new Camera(this, 0,0,490); camera4 = new Camera(this, 0,0,490); camera1.truck(width/2); camera1.boom(height/2); camera2.truck(width/2); camera2.boom(height/2); camera3.truck(width/2); camera3.boom(height/2); camera4.truck(width/2); camera4.boom(height/2); for(int c=0; c<12; c++){ for(int a=0; a<31; a++){ for(int b=0; b<24; b++){ data[c][a][b][0]=0; data[c][a][b][1]=0; } } } font = loadFont("HelveticaNeue-CondensedBold-16.vlw"); importData(); } void importData(){ String[] dataLoad; dataLoad = loadStrings("yt_2007.csv"); int counter = 0; for(int l=0; l<12; l++){ for(int j=0; j<31; j++){ for(int k=0; k<24; k++){ String[] dataLine = split(dataLoad[counter], ','); data[l][j][k][0] = int(dataLine[4]); data[l][j][k][1] = int(dataLine[5]); counter++; } } } } void draw() { background(255); camera1.feed(); fill(0xFF775555); textFont(font); drawData(); // draw the datapoints } float animate(int position, int nm, int gm, int b, int c, int d){ float result=0; result = ((graphYPos+graphHeight-data[nm][b][c][0]-170) - (graphYPos+graphHeight-data[gm][b][c][d]-170))/20*position; return result; } void drawB(int bb, int pos){ for(int k=0; k<=bb; k++){ for(int j=8; j<=21; j++){ pushMatrix(); translate(graphXPos+(k-10)*18+180, graphYPos+graphHeight-data[initialMonth][k][j][pos]-170,-((j-8)*40)); sphere(3); popMatrix(); } } } void drawBShadow(int bb, int pos){ if(pos==0){ ambientLight(255,255,255); fill(166,220,247,100); beginShape(QUAD_STRIP); for(int k=0; k<=bb; k++){ for(int j=8; j<=21; j++){ vertex(graphXPos+(k-10)*18+180, graphYPos+graphHeight-data[initialMonth][k][j][pos]-170,-((j-8)*40)); if(k-1>0) vertex(graphXPos+(k-11)*18+180, graphYPos+graphHeight-data[initialMonth][k-1][j][pos]-170,-((j-8)*40)); } } endShape(); } else if(pos==1){ lightSpecular(255,132,25); fill(255,197,168,100); beginShape(QUAD_STRIP); for(int k=0; k<=bb; k++){ for(int j=8; j<=21; j++){ vertex(graphXPos+(k-10)*18+180, graphYPos+graphHeight-data[initialMonth][k][j][pos]-170,-((j-8)*40)); if(k-1>0) vertex(graphXPos+(k-11)*18+180, graphYPos+graphHeight-data[initialMonth][k-1][j][pos]-170,-((j-8)*40)); } } endShape(); } //drawing lines if(lines==0 || lines==2){ for(int b=0; b149) transparency=149; if(transparency2>249) transparency2=249; } fill(6+transparency2,149-transparency,179); if(zero==0 || zero==2){ drawB(initialB-1, 0); if(stop==0 || stop==2){ for(int j=8; j<=initialC; j++){ if(data[initialMonth][initialB][j][0]!=0){ pushMatrix(); translate(graphXPos+(initialB-10)*18+180, graphYPos+graphHeight-data[initialMonth][initialB][j][0]-170,-((j-8)*40)); sphere(3); popMatrix(); } } } if(initialB!=0) drawBShadow(initialB-1, 0); } //for book part if(initialB!=0){ transparency = abs(data[graphMonth][initialB][initialC][1]-data[graphMonth][initialB-1][initialC][1])/3; transparency2 = abs(data[graphMonth][initialB][initialC][1]-data[graphMonth][initialB-1][initialC][1])/3; if(transparency>149) transparency=149; if(transparency2>249) transparency2=249; } fill(6+transparency2,149-transparency,179); if(one ==0 || one==2){ drawB(initialB-1, 1); if(stop==0 || stop==2){ for(int j=8; j<=initialC; j++){ if(data[initialMonth][initialB][j][1]!=0){ pushMatrix(); translate(graphXPos+(initialB-10)*18+180, graphYPos+graphHeight-data[initialMonth][initialB][j][1]-170,-((j-8)*40)); sphere(3); popMatrix(); } } } if(initialB!=0) drawBShadow(initialB-1, 1); } //increase the counter for animation if(initialC!=21)initialC++; else{ initialC=8; if(initialB!=30)initialB++; else { initialB=0; if(initialMonth!=11) initialMonth++; else initialMonth=0; } } } //drawing dots if((dots==0 || dots==2) && readyToAnimate==1){ for(int b=0; b<31; b++){ for(int c=8; c<21; c++){ int d=c+1; if(b!=0){ transparency = abs(data[graphMonth][b][c][0]-data[graphMonth][b-1][c][0])/3; transparency2 = abs(data[graphMonth][b][c][0]-data[graphMonth][b-1][c][0])/3; if(transparency>149) transparency=149; if(transparency2>249) transparency2=249; } fill(6+transparency2,149-transparency,179); if((zero==0 || zero==2) && readyToAnimate==1){ pushMatrix(); monthDifference = animate(animateCounter, nextMonth, graphMonth, b, c,0); translate(graphXPos+(b-10)*18+180, graphYPos+graphHeight-data[graphMonth][b][c][0]-170+monthDifference,-((c-8)*40)); sphere(3); popMatrix(); } if(b!=0){ transparency3 = abs(data[graphMonth][b][c][1] - data[graphMonth][b-1][c][1])/3; if(transparency3>132) transparency3=132; } fill(255,132-transparency3,25); if((one==0 || one==2) && readyToAnimate==1){ pushMatrix(); monthDifference_1 = animate(animateCounter, nextMonth, graphMonth, b, c,1); translate(graphXPos+(b-10)*18+180, graphYPos+graphHeight-data[graphMonth][b][c][1]-170+monthDifference_1,-((c-8)*40)); sphere(3); popMatrix(); } } } } if(readyToAnimate==1){ //draw the shadow for media part ambientLight(255,255,255); fill(166,220,247,100); if((lines==0 || lines==2) && readyToAnimate==1){ stroke(6,149,179); } else { noStroke(); } beginShape(QUAD_STRIP); for(int b=1; b<31; b++){ for(int c=8; c<21; c++){ int d=c+1; if((zero==0 || zero==2) && readyToAnimate==1){ monthDifference2 = animate(animateCounter, nextMonth, graphMonth, b, c,0); vertex(graphXPos+(b-10)*18+180, graphYPos+graphHeight-data[graphMonth][b][c][0]-170+monthDifference2,-((c-8)*40)); monthDifference3 = animate(animateCounter, nextMonth, graphMonth, b-1, c,0); vertex(graphXPos+(b-11)*18+180, graphYPos+graphHeight-data[graphMonth][b-1][c][0]-170+monthDifference3,-((c-8)*40)); } } } endShape(); //draw the shadow for book part lightSpecular(255,132,25); fill(255,197,168,100); if((lines==0 || lines==2) && readyToAnimate==1){ stroke(255,132,25); } else { noStroke(); } beginShape(QUAD_STRIP); for(int b=1; b<31; b++){ for(int c=8; c<21; c++){ int d=c+1; if((one==0 || one==2)&& readyToAnimate==1){ monthDifference2_1 = animate(animateCounter, nextMonth, graphMonth, b, c,1); vertex(graphXPos+(b-10)*18+180, graphYPos+graphHeight-data[graphMonth][b][c][1]-170+monthDifference2_1,-((c-8)*40)); monthDifference3_1 = animate(animateCounter, nextMonth, graphMonth, b-1, c,1); vertex(graphXPos+(b-11)*18+180, graphYPos+graphHeight-data[graphMonth][b-1][c][1]-170+monthDifference3_1,-((c-8)*40)); } } } endShape(); } if(caption==0 || caption==2){ //now draw textbox for color information stroke(0xFFDDCCCC); // set the stroke (border) color for future drawing method calls fill(255); fill(6,149,179); text("Media=Blue", graphXPos+graphWidth+50-230, graphYPos+graphHeight+5 - (1*20)-400-170, 0); fill(255,132,25); text("Book=Orange", graphXPos+graphWidth+50-230, graphYPos+graphHeight+5 - (2*20)-400-170, 0); String monthName="", dayName=""; fill(0xFF775555); if(readyToAnimate==1){ if(graphMonth==0) monthName="January 2007"; else if(graphMonth==1) monthName="February 2007"; else if(graphMonth==2) monthName="March 2007"; else if(graphMonth==3) monthName="April 2007"; else if(graphMonth==4) monthName="May 2007"; else if(graphMonth==5) monthName="June 2007"; else if(graphMonth==6) monthName="July 2007"; else if(graphMonth==7) monthName="August 2007"; else if(graphMonth==8) monthName="September 2007"; else if(graphMonth==9) monthName="October 2007"; else if(graphMonth==10) monthName="November 2007"; else if(graphMonth==11) monthName="December 2007"; } else if(readyToAnimate==0){ if(initialMonth==0) monthName="January 2007"; else if(initialMonth==1) monthName="February 2007"; else if(initialMonth==2) monthName="March 2007"; else if(initialMonth==3) monthName="April 2007"; else if(initialMonth==4) monthName="May 2007"; else if(initialMonth==5) monthName="June 2007"; else if(initialMonth==6) monthName="July 2007"; else if(initialMonth==7) monthName="August 2007"; else if(initialMonth==8) monthName="September 2007"; else if(initialMonth==9) monthName="October 2007"; else if(initialMonth==10) monthName="November 2007"; else if(initialMonth==11) monthName="December 2007"; text("Day " + initialB, graphXPos+graphWidth+50-230, graphYPos+graphHeight+5 + (11*20)-400-170,0); } text(monthName, graphXPos+graphWidth+50-230, graphYPos+graphHeight+5 + (10*20)-400-170,0); drawGrid(); } } void drawGrid() { stroke(0xFFDDCCCC); // set the stroke (border) color for future drawing method calls fill(255); // set the fill to white line(graphXPos, graphYPos, 0, graphXPos, graphYPos+graphHeight-170, 0); line(graphXPos, graphYPos+graphHeight-170, 0, graphXPos+graphWidth-170, graphYPos+graphHeight-170, 0); line(graphXPos, graphYPos+graphHeight-170, 0, graphXPos, graphYPos+graphHeight-170, -500); fill(0xFFBB9999); // set the fill color for when we draw our text textFont(font); textAlign(RIGHT); // align our text flush right with the x coordinate we give when we call the text() method //this is for drawing Y-axis for(int i=0; i < 8; i++) { // this loops write the axis labels for the y axis if(i!=0){ text(str(int(pow(100, i*0.25))), 85, graphYPos+graphHeight - (i*65)-165, 0); line(90, graphYPos+graphHeight - (i*65)-170, 0, 100, graphYPos+graphHeight-(i*65)-170, 0); } } //this is for drawing X-axis for(int i=0; i <= 31; i++) { // this loops write the axis labels for the x axis if(i!=0) line(graphXPos+(i*18), graphYPos+graphHeight-170, 0, graphXPos+(i*18), graphYPos+graphHeight+10-170, 0); if(i%5==0) text(str(i), graphXPos+(i*18)+6, graphYPos+graphHeight+20-170, 0); } //this is for drawing Z-axis for(int i=8; i <= 20; i++) { // this loops write the axis labels for the x axis if(i!=0) line(graphXPos, graphYPos+graphHeight-170, -((i-8)*40), graphXPos, graphYPos+graphHeight-10-170, -((i-8)*40)); if(i%4==0) text(str(i), graphXPos, graphYPos+graphHeight-170, -((i-8)*40)); } textAlign(LEFT); fill(0xFF775555); filenameType = filename.split(","); filenameShort = filenameType[0]; text("Seattle Public Library's 2007 Check-in items (Total # checkin vs. Hour vs. Day)", 100, 30, 0); // write title text text("Day", graphXPos+graphWidth-20-170, graphYPos+graphHeight+40-180, 0); text("Hour", graphXPos, graphYPos+graphHeight-170, -(550)); text("Total", graphXPos-95, graphYPos+20, 0); } void keyPressed(){ if(keyPressed && key=='c' && caption==0){ redraw(); caption=1; } else if(keyPressed && key=='c' && caption==1){ redraw(); caption=2; } else if(keyPressed && key=='c' && caption==2){ redraw(); caption=1; } if(keyPressed && key=='0' && zero==0){ redraw(); zero=1; } else if(keyPressed && key=='0' && zero==1){ redraw(); zero=2; } else if(keyPressed && key=='0' && zero==2){ redraw(); zero=1; } if(keyPressed && key=='1' && one==0){ redraw(); one=1; } else if(keyPressed && key=='1' && one==1){ redraw(); one=2; } else if(keyPressed && key=='1' && one==2){ redraw(); one=1; } if(keyPressed && key=='d' && dots==0){ redraw(); dots=1; } else if(keyPressed && key=='d' && dots==1){ redraw(); dots=2; } else if(keyPressed && key=='d' && dots==2){ redraw(); dots=1; } if(keyPressed && key=='l' && lines==0){ redraw(); lines=1; } else if(keyPressed && key=='l' && lines==1){ redraw(); lines=2; } else if(keyPressed && key=='l' && lines==2){ redraw(); lines=1; } if(keyPressed && key=='s' && stop==0){ //stop noLoop(); stop = 1; } else if(keyPressed && key=='s' && stop==1){ loop(); stop=0; } //camera key if(keyPressed && key=='o'){ redraw(); cameraONE=1; cameraTWO=0; cameraTHREE=0; cameraFOUR=0; camera1.jump(410,292,490); camera2.jump(410,292,490); camera3.jump(410,292,490); camera4.jump(410,292,490); } if(keyPressed && key=='z'){ cameraONE=1; cameraTWO=0; cameraTHREE=0; cameraFOUR=0; camera1.zoom(-0.05); redraw(); } if(keyPressed && key=='y'){ cameraONE=1; cameraTWO=0; cameraTHREE=0; cameraFOUR=0; camera1.zoom(0.05); redraw(); } if(keyPressed && key=='t'){ cameraONE=0; cameraTWO=1; cameraTHREE=0; cameraFOUR=0; camera2.truck(10); redraw(); } if(keyPressed && key=='r'){ cameraONE=0; cameraTWO=1; cameraTHREE=0; cameraFOUR=0; camera2.truck(-10); redraw(); } if(keyCode == SHIFT){ shift = true; } if(keyCode == UP){ if(shift){ camera3.boom(10); cameraONE=0; cameraTWO=0; cameraTHREE=1; cameraFOUR=0; } else{ cameraONE=0; cameraTWO=0; cameraTHREE=1; cameraFOUR=0; camera3.boom(-10); } camera3.dolly(-30); cameraONE=0; cameraTWO=0; cameraTHREE=1; cameraFOUR=0; redraw(); } if(keyCode == DOWN){ camera3.dolly(30); cameraONE=0; cameraTWO=0; cameraTHREE=1; cameraFOUR=0; redraw(); } if(keyCode == LEFT){ camera4.pan(-.1); cameraONE=0; cameraTWO=0; cameraTHREE=0; cameraFOUR=1; redraw(); } if(keyCode == RIGHT){ camera4.pan(.1); cameraONE=0; cameraTWO=0; cameraTHREE=0; cameraFOUR=1; redraw(); } } void keyReleased(){ if(keyCode == SHIFT){ shift = false; } } void mouseDragged() { camera1.tumble(radians((mouseX - pmouseX)*PI/3), radians((mouseY - pmouseY)*PI/3)); cameraONE=1; cameraTWO=0; cameraTHREE=0; cameraFOUR=0; redraw(); }