/** A toy for playing with the SPL data set! */ /** MODIFIED SOME SAMPLE CODE FROM. * Flocking * by Daniel Shiffman. * An implementation of Craig Reynold's Boids program to simulate * the flocking behavior of birds. Each boid steers itself based on * rules of avoidance, alignment, and coherence. * * "BORROWED" MORE CODE from syed reza */ import processing.opengl.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import java.util.*; import java.math.*; import controlP5.*; /*BAGGAGE*/ ArrayList transactions = null; //global List of the data int idx = 0; int maxNum = 200; int[] deweyCount = new int[10]; int totalDeweys = 0; long timer = 0; float[] rotations = new float[3]; int gridInterval = 45; int PLOTX1, PLOTX2; int PLOTY1, PLOTY2; int PLOTZ1, PLOTZ2; int DATAMIN, DATAMAX; int DATAMINZ, DATAMAXZ; int XMIN, XMAX; int XINTERVAL; int YINTERVAL; int ZINTERVAL; PeasyCam cam; ControlP5 controlP5; PMatrix3D currCameraMatrix; PGraphics3D g3; ControlGroup l; Slider lineslider; Slider radiusslider; Slider maxslider; Slider zslider; Toggle rendercheck; Toggle textcheck; Toggle bigcheck; Toggle spacecheck; Toggle pausecheck; Toggle littlecheck; controlP5.Button rst; Textlabel mySmallTextlabel; Integrator slide; //My Declarations for thissun Basement basement; int framecount = 0; int transactionindex = 0; double transactioninc = 0; int transactioncount = 0; int spawned = 0; //Number of gremlins on the screen at any time int gremlincount = 50; int gremlincountmax = 600; //Radius of each gremlin int gradius = 70; float zscale = 40; boolean render = true; boolean renderg = true; boolean rendert = false; boolean renderb = true; boolean rendera = true; boolean renderl = true; boolean renderc = false; boolean pause = true; boolean littlecolors = false; float linet = 0; void reset() { basement.clear(); transactionindex = 0; transactioninc = 0; spawned = 0; transactioncount = 0; transactioninc = ( 2 * transactions.size() / gremlincountmax ); gremlincount = 0; } /* THIS RUNS BEFORE ANYTHING ELSE */ void setup() { size(1000,700, OPENGL); hint(DISABLE_OPENGL_2X_SMOOTH); hint(ENABLE_OPENGL_4X_SMOOTH); smooth(); frameRate(1000); //that is, as fast as possible PLOTX1 = 0; PLOTX2 = 1200; PLOTY1 = 0; PLOTY2 = 1000; PLOTZ1 = 0; PLOTZ2 = 1000; DATAMIN = 0; DATAMAX = 500; DATAMINZ = 0; DATAMAXZ = 250; XMIN = 0; XMAX = PLOTX2; XINTERVAL = 90; YINTERVAL = 90; ZINTERVAL = 90; cam = new PeasyCam(this,(PLOTX1+PLOTX2)*.5,(PLOTY1+PLOTY2)*.5,(PLOTZ1+PLOTZ2)*.5, 2500); cam.setMinimumDistance(1); cam.setMaximumDistance(5000); basement = new Basement(); slide = new Integrator(-180, 0.3, 0.8); textFont(loadFont("GillSans-24.vlw"),24); textAlign(CENTER,CENTER); background(0); setupGUI(); doVariables(); refillBasement(); } /* THIS RUNS EACH FRAME Draw draw draw draw... draw draw draw */ void draw() { rotations = cam.getRotations(); slide.update(); if(mouseY < 100) { slide.target(0); } else { slide.target(-80); } if(l.position().y != slide.value) { l.position().y = slide.value; } framecount++; //clearBackground background(40); if (pause == false) { //Go through the basement. // println("Running"); basement.run(); //Update the gremlins // println("moving + drawing"); basement.update(); if (gremlincount < gremlincountmax) { gremlincount++; } if (framecount >= 25) { //clean up and add more framecount = 0; basement.clean(); gremlincount = basement.getCount(); } refillBasement(); } //Draw the gremlins if (render == true) { axis(); drawXLabels(); drawYLabels(); drawZLabels(); basement.render(); } gui(); } void axis() { strokeWeight(2); stroke(255,255,255); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX2,PLOTY1,PLOTZ1); stroke(255,255,255); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX1,PLOTY2,PLOTZ1); stroke(255,255,255); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX1,PLOTY1,PLOTZ2); } void drawGrid() { stroke(255); strokeWeight(1); for(int i = PLOTX1; i <= PLOTX2; i = i + gridInterval) { line(i,PLOTY1,PLOTZ1, i,PLOTY2,PLOTZ1); for(int k = PLOTY1; k <= PLOTY2; k = k + gridInterval) { line(PLOTX1,k,PLOTZ1,PLOTX2,k,PLOTZ1); } } } void refillBasement() { while ( (basement.getCount() < gremlincount) && transactioncount < transactioninc ) { spawnGremlin((int) (transactionindex*transactioninc + transactioncount)); transactionindex++; if (transactionindex >= transactioninc ) { transactionindex = 0; transactioncount++; } } stroke(255); textAlign(LEFT); fill(150); text("Gremlins Spawned: "+ spawned, PLOTX2+100,50,0); } void keyPressed(){ switch (key){ case 'r': reset(); ; break; case 'g': renderg = !renderg ; break; case 't': rendert = !rendert ; break; case 'b': renderb = !renderb ; break; case 'a': rendera = !rendera ; break; case 'k': linet-= 0.5 ; break; case ';': linet+= 0.5 ; break; case 'p': pause = !pause; break; case 'y': renderc = !renderc; break; } } void doVariables() { long before = millis(); this.transactions = loadTransactions("Stripped.txt"); println("loaded " + this.transactions.size() + " transactions in " + (millis() - before) + " miiliseconds."); transactioninc = ( 2 * transactions.size() / gremlincount ); } /* THE STUFF DOWN HERE PARSES THE DATA*/ public ArrayList loadTransactions(String nameOfDataFileWithinDataDirectory) { ArrayList transactions = new ArrayList(); String[] lines = loadStrings(nameOfDataFileWithinDataDirectory); for (int i = 0; i < lines.length; i++) { transactions.add(parseTransaction(lines[i])); } return transactions; } //create a new transaction obejct from a comma separated line. public Transaction parseTransaction(String line) { String sections[] = split(line, ","); // Throw out entries with bad dewey numbers Transaction t = new Transaction(); //store all fields t.ckodate = sections[0]; t.ckotime = sections[1]; t.type = sections[2]; t.title = sections[3]; t.deweyClass = sections[4]; return t; }