import processing.opengl.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import controlP5.*; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import javax.media.opengl.*; void setup() { ///Set up Canvas size(800,600, OPENGL); //setup a 500 by 500 Pixel Space to work with 280 transactions...for you want to show more make sure you have enough transacti smooth(); //smooth(); background(bgcolor); //set background to white (255) frameRate(60); //set the frameRate of the Visualization itemTypes = new HashMap(); itemTypes = getItemTable("itemTypes.html"); this.transactions = loadTransactions("splxmldata_jan8.txt"); //load the transactions from the splxmldata.txt file cam = new PeasyCam(this, 1000); cam.setMinimumDistance(100); cam.setMaximumDistance(20000); lg = false; dr = false; ln = true; still = false; inout = false; spherical = true; ax = false; lb = false; mo = 3; lx = 0; ly = 0; lz = 0; xdp = 0; ydp = 0; zdp = 0; stillPos = 0; frame = 0; modval = 60; zoom = 3200; opacity = 35; bgcolor = 0; animationSpeed = 0; cam.lookAt(0,0,0,4800,2000); rotateZ(90); rotateY(90); slide = new Integrator(700, 0.3, 0.8); flyFont = loadFont("LilyUPCBold-255.vlw"); setupGUI(); } void draw() //draw loop that runs over and over until user quits { background(bgcolor); rotations = cam.getRotations(); if(zoom !=lastZoom){ lastZoom = zoom; cam.lookAt(0,0,0,zoom,0); } slide.update(); //this moves the interface up and down if(mouseY > height-100) { cam.setMouseControlled(false); cam.setResetOnDoubleClick(false); slide.target(height-100); } else { cam.setMouseControlled(true); cam.setResetOnDoubleClick(true); slide.target(height-20); } if(l.position().y != slide.value) { l.position().y = slide.value; checkbox.position().y = slide.value + 20 ; } DetailedTransaction t; //create a transaction object t = (DetailedTransaction) transactions.get(stillPos); while(!(t.format.equals(formats[mo]) || mo > formatsPresent)){ stillPos++; if (stillPos >= transactions.size()){ stillPos = 0; } t = (DetailedTransaction) transactions.get(stillPos); } //println(rgb[0] +"\t" + rgb[1]+"\t" +rgb[2]); int rgb[] = getColor(t.label); color c1 = color(rgb[0], rgb[1], rgb[2]); strokeWeight(1); value = 90; noFill(); stroke(c1); if(dr){ if(inout){ x = t.dayOfWeekIn; y = t.checkInTime; } else{ x = t.dayOfWeekOut; y = t.checkOutTime; } if (lg) z = map (log(ceil(t.durDays)),0,60,0,100*XI); else z = map (t.durDays,0,60,0,100*XI); if(!spherical){ x = map (x,1,7,0,200*XI); y = map (y,8,20,0,-200*YI); } else{ float xtemp = map(x,1,7,0,2.0*(6.0/7.0)*PI); float ytemp = map(y,8,20,0,PI); float ztemp = z; x = ztemp*sin(ytemp)*cos(xtemp); y = ztemp*sin(ytemp)*sin(xtemp); z = ztemp*cos(ytemp); } drawUpFrom(0,stillPos-1); counter = 500001; still = true; //line(lx,ly,lz,x,y,z); modval = 61-animationSpeed; xd = map ((frameCount-frame)%modval,0,modval-1,lx,x); yd = map ((frameCount-frame)%modval,0,modval-1,ly,y); zd = map ((frameCount-frame)%modval,0,modval-1,lz,z); strokeWeight(1); value = 90; noFill(); stroke(c1); if( ln ){ line(lx,ly,lz,xd,yd,zd); } strokeWeight(4); point(xd,yd,zd); if(lb){ pushMatrix(); translate(xd,yd,zd); rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); // imageMode(CENTER); // tint(map(counter,0,300,0,255),255,117); // image(orb,0,0,value/10.0,value/10.0); // tint(255); fill(255); textAlign(LEFT, CENTER); textFont(flyFont); //String[] title = split(t.title, " "); if(lg) textFont(flyFont,24); String flyLabel; if(t.checkOutTime > 12) flyLabel = daysOfWeek[t.dayOfWeekOut] + " "+ ((int)t.checkOutTime -12) + "PM"; else if (t.checkOutTime == 12) flyLabel = daysOfWeek[t.dayOfWeekOut] + " "+ (int)t.checkOutTime + "PM"; else flyLabel = daysOfWeek[t.dayOfWeekOut] + " "+ (int)t.checkOutTime + "AM"; if(((int)xd!=(int)lx) && ((int)yd!=(int)ly) && ((int)zd!=(int)lz)) text(flyLabel,10,0,0); popMatrix(); } noFill(); // strokeWeight(value/100); // stroke(map(counter,0,300,0,255),255,117,100); // line(i,k,value,pt.x,pt.y,pt.z); // // pt.set(i,k,value); // if (frameCount - frame >= modval){ frame = frameCount; lx = x; ly = y; lz = z; stillPos++; // point(xd,yd,zd); if (stillPos >= transactions.size()) stillPos = 0; while(!(t.format.equals(formats[mo]) || mo > formatsPresent)){ stillPos++; if (stillPos >= transactions.size()){ stillPos = 0; } t = (DetailedTransaction) transactions.get(stillPos); } } } else{ still = false; drawUpFrom(0,transactions.size()-1); } strokeWeight(1); if(ax) axis(); if(lb) drawLabels(); gui(); } void axis() { int mul = 1; if(!lg) mul = 10; stroke(255,255,255); line(1000*mul,0,0,0,0,0); //stroke(0,255,0); line(0,-1000*mul,0,0,0,0); // stroke(0,0,255); line(0,0,1000*mul,0,0,0); if(spherical){ line(-1000*mul,0,0,0,0,0); //stroke(0,255,0); line(0,1000*mul,0,0,0,0); // stroke(0,0,255); line(0,0,-1000*mul,0,0,0); } } void drawUpFrom(int bottom, int top){ int count = bottom; DetailedTransaction ot; float dufx,dufy,dufz,duflx,dufly,duflz,dufxd,dufyd,dufzd,dufxdp,dufydp,dufzdp; duflx = 0; dufly = 0; duflz = 0; while ((count<=top) && (count < transactions.size())){ ot = (DetailedTransaction) transactions.get(count); if(ot.format.equals(formats[mo]) || mo > formatsPresent){ int rgb[] = getColor(ot.label); color c1 = color(rgb[0], rgb[1], rgb[2], opacity); // if(ot.checkOutTime > maxTime){ // maxTime = ot.checkOutTime; // } // // if(ot.checkOutTime < minTime){ // minTime = ot.checkOutTime; // } // println(maxTime + "\t"+minTime); //println(rgb[0] +"\t" + rgb[1]+"\t" +rgb[2]); if(inout){ dufx = ot.dayOfWeekIn; dufy = ot.checkInTime; } else{ dufx = ot.dayOfWeekOut; dufy =ot.checkOutTime; } if (lg) dufz = map (log(ceil(ot.durDays)),0,60,0,100*XI); else dufz = map (ot.durDays,0,60,0,100*ZI); if(!spherical){ dufx = map (dufx,1,7,0,200*XI); dufy = map (dufy,8,20,0,-200*YI); } else{ float xtemp = map(dufx,1,7,0,2.0*(6.0/7.0)*PI); float ytemp = map(dufy,8,20,0,PI); float ztemp = dufz; dufx = ztemp*sin(ytemp)*cos(xtemp); dufy = ztemp*sin(ytemp)*sin(xtemp); dufz = ztemp*cos(ytemp); } strokeWeight(1); value = 90; noFill(); stroke(c1); if(ln && (count > bottom) ){ stroke(c1); line(duflx,dufly,duflz,dufx,dufy,dufz); } strokeWeight(4); point(dufx,dufy,dufz); duflx = dufx; dufly = dufy; duflz = dufz; } count++; } } void drawLabels(){ if(!spherical){ textFont(flyFont); textAlign(CENTER,CENTER); fill(255); for(int i = 0; i< 7; i++){ text(wk[i],i*200*XI/6 ,80); } for(int i = 7; i< 20; i++){ text((i)%12 + 1,-80,-(i-7)*200*YI/12 ); } if(!lg){ for(int i = 0; i< 6; i++){ textAlign(LEFT, CENTER); if (i!=0) text(i*10,-80,80,i*100*ZI); } rotateX(-90); } } }