President[] presidents; int i = 0; PFont font, font2; //To Do //Make rows thinner //Add more presidents //Change timeline to 1800 //Add white boxes in mouse overs //Include grad school, congress and govenor void setup(){ size(1200,515); background(0); presidents = getPresidentList(); font = loadFont("Garamond-20.vlw"); font = loadFont("Helvetica-18.vlw"); font = loadFont("HelveticaNeue-Light-18.vlw"); font2 = loadFont("HelveticaNeue-Light-14.vlw"); textFont(font); fill(0); } void draw(){ fill(0); noStroke(); rect(-1,-1, width+2, height+2); stroke(250); fill(250); line(30, 50, 20+1100, 50); noStroke(); makeTimeLine(1880,2010, 25, 50, 1100); makeLegend(50,height-50); } void makeLegend(int x, int y){ stroke(255); textFont(font2); int Z =150; textAlign(LEFT); fill(255,0,0); rect(x, y+15, 10,10); fill(255); text("Birth", x+15, y+25); fill(255,125,0); rect(x+75, y+15, 10,10); fill(255); text("College", x+15+75, y+25); fill(255,250,0); rect(x+170, y+15, 10,10); fill(255); text("Graduate School", x+160+25, y+25); fill(125,250,0); rect(x+330, y+15, 10,10); fill(255); text("Other Work", x+330+15, y+25); fill(0,220,0); rect(x+450, y+15, 10,10); fill(250); text("Congress", x+450+15, y+25); fill(0,210,210); rect(x+560, y+15, 10,10); fill(250); text("Govenor", x+560+15, y+25); fill(125,0,250); rect(x+670, y+15, 10,10); fill(250); text("Vice President", x+665+25, y+25); fill(0,0,250); rect(x+810, y+15, 10,10); fill(250); text("President", x+810+15, y+25); textFont(font); noFill(); line(x-20, y+5, x+1075, y+5); } void drawLifeMoment(int x, int y, int w, int h, int r, int g, int b, String label){ fill(r, g, b); stroke(255); rect(x,y, w, h); fill(255); if(mouseX>x && mouseY > y && mouseX < x+w && mouseY < y+h ){ stroke(r,g,b); float dn = textWidth(label); rect(x-5, y-43,dn+12, 39); fill(0); text(label, x, y-27); } } void drawPresident(President guy, int x, int y, int h, int w, int start, int stop){ int byear=guy.bdyear; int pyearstart=guy.pyearstart; int pyearend=guy.pyearend; int viceStart=guy.viceStart; int viceEnd = guy.viceEnd; noFill(); if(mouseY > y && mouseY < y + h){ fill(20); } stroke(0); rect(x, y+1, w, h-1); fill(255); textFont(font2); text(guy.name, x +20, y+24); drawLifeMoment(x+250+(w-250)*(byear-start)/(stop-start), y, 10,h, 255, 0, 0, guy.bdate + "\n" + guy.bloc); drawLifeMoment(x+250+(w-250)*(guy.colstart-start)/(stop-start), y, round((w-250)*(guy.colstop-guy.colstart)/(stop-start)), h, 255, 125, 0, guy.college + "\n" + Integer.toString(guy.colstart) + "-" + Integer.toString(guy.colstop)); drawLifeMoment(x+250+(w-250)*(guy.gradStart-start)/(stop-start), y, round((w-250)*(guy.gradEnd-guy.gradStart)/(stop-start)), h, 255, 255, 0, guy.gradName + "\n" + Integer.toString(guy.gradStart) + "-" + Integer.toString(guy.gradEnd)); drawLifeMoment(x+250+(w-250)*(guy.otherStart-start)/(stop-start), y, round((w-250)*(guy.otherEnd-guy.otherStart)/(stop-start)), h, 120, 250, 0, guy.otherName +"\n" + Integer.toString(guy.otherStart) + "-" + Integer.toString(guy.otherEnd)); drawLifeMoment(x+250+(w-250)*(guy.congressStart-start)/(stop-start), y, round((w-250)*(guy.congressEnd-guy.congressStart)/(stop-start)), h, 0, 180, 0, guy.congressState + "\n" + Integer.toString(guy.congressStart) + "-" + Integer.toString(guy.congressEnd)); drawLifeMoment(x+250+(w-250)*(guy.govenorStart-start)/(stop-start), y, round((w-250)*(guy.govenorEnd-guy.govenorStart)/(stop-start)), h, 0, 210, 210, guy.govenorState + "\n" + Integer.toString(guy.govenorStart) + "-" + Integer.toString(guy.govenorEnd)); drawLifeMoment(x+250+(w-250)*(viceStart-start)/(stop-start), y, round((w-250)*(viceEnd-viceStart)/(stop-start)), h, 125, 0, 250, Integer.toString(viceStart) + "-" + Integer.toString(viceEnd)); drawLifeMoment(x+250+(w-250)*(pyearstart-start)/(stop-start), y, round((w-250)*(pyearend-pyearstart)/(stop-start)), h, 0, 0, 250, Integer.toString(pyearstart) + "-" + Integer.toString(pyearend)); stroke(250); line(x+250, y, x+250, y+h); line(x+1099, y, x+1099, y+h); } void makeTimeLine(int start, int stop, int x, int y, int w){ stroke(255); textFont(font2); noFill(); fill(255); textAlign(LEFT); text(Integer.toString(start), x+210, y-10) ; textAlign(RIGHT); text(Integer.toString(stop), x+w, y-10) ; textAlign(CENTER); text(Integer.toString(round((start+start+stop+start)/4)), (w-250)/4+250+x, y-10); text(Integer.toString(round((stop+start)/2)), (w-250)/2+250+x, y-10); text(Integer.toString(round((start+stop+stop+stop)/4)), (w-250)*3/4+250+x, y-10); textAlign(LEFT); for(i= 0; i< presidents.length; i++){ drawPresident(presidents[i], x, y+i*35, 35, w, start, stop); } } XMLElement getRestService(String url) { try{ XMLElement xml = new XMLElement(this, url); return xml; }catch(Exception e) { XMLElement xml = new XMLElement(); return xml; } } President[] getPresidentList(){ XMLElement xml = getRestService("presidents.xml" ); XMLElement[] xm = xml.getChildren("president"); presidents = new President[xm.length]; for(int i = 0; i