// function to demonstrate the use of the peasycam library // for 3D camera interaction // If the OpenGL render is used this line should be uncommented. //import processing.opengl.*; import de.bezier.data.sql.*; import peasy.*; // Camera PeasyCam cam; int mCount=0; int MaxScale =0; MySQL msql; int [][] Veg2009 = new int[6][12]; float plotX1, plotY1; float plotX2, plotY2; float labelX, labelY; String [] Veglabel = {"Bean","Carrot","Lemon","Potato","Pumpkin","Tomato"}; String [] Months = {"January","February","March","April","May","June","July","August","September","October","November","December"}; PFont font; int [] SixValues = new int[6]; void setup() { size(500,500,P3D); // If OpenGl render wanted change previous line with: // size(500,500,OPENGL); //creating a new cam cam = new PeasyCam(this,300,0,-600, 1200); cam.setMinimumDistance(10); cam.setMaximumDistance(1600); font = loadFont("UniversLTStd-Cn-14.vlw"); // connecting to the database String user = "mat259"; String pass = "V1sual1zat1on"; String database = "spl_all"; String TheQuery =""; String TextToSearch =""; String TheFile = "2009Monthly.txt"; String lines[] = loadStrings(TheFile); msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass ); if ( msql.connect() ) { for(int t =0; t<6;t++){ for (int k =0 ; k < 12; k++){ TheQuery="SELECT count(*) FROM transactionsallID WHERE id BETWEEN " + lines[2*k] + " and " + lines[2*k+1] ; TheQuery+= " and (title like '%" + Veglabel[t] + "%')"; msql.query( TheQuery); msql.next(); Veg2009[t][k]= msql.getInt(1); // Saving the Maximum if (Veg2009[t][k] > MaxScale){ MaxScale = Veg2009[t][k]; } println(k + " " + Veglabel[t]+ " " + msql.getInt(1)); } } } else { println(" connection failed "); } frameRate(20); smooth(); } void draw(){ drawBar3D(); } void drawBar3D(){ float Hside; float Vside; float Zside; background(230); strokeWeight(1); Hside = 100; Vside = 100; Zside = 100; fill(160,220); stroke(0); for (int k=0; k <12; k++){ for (int t =0;t<6;t++){ float NewHeigh = map(Veg2009[t][k],0,MaxScale,0,Vside); // Drawing an array of boxes with the data // Every box is translated independently pushMatrix(); translate(t*Hside,Vside-NewHeigh/2.0,-100*k); box(Hside*.95,NewHeigh,95); popMatrix(); } } // Labeling textFont(font); fill(80); for (int t =0;t<6;t++){ textAlign(CENTER,CENTER); pushMatrix(); translate(t*Hside,Vside,100); rotateX(PI/2.0); text(Veglabel[t], 0,0); popMatrix(); } for (int k =0;k<12;k++){ textAlign(CENTER,CENTER); pushMatrix(); translate(6*Hside+20,Vside,-k*100); rotateX(PI/2.0); rotateZ(-PI/2.0); text(Months[k],0,0); popMatrix(); } } void keyPressed() { if (key == 'r') { cam.reset(5000); } if (key == 'a') { cam.rotateY(PI/2.0); } }