//visualisation of info from the wikileaks iraq war logs //Jim Anning @jimanning December 2010 import org.json.*; import java.util.Calendar; JSONObject deathData; ArrayList deaths; int ballWidth = 48; int framesPerDay = 3; int currentFrame = 1; int numHandles = 2; int days = 0; RectButton ce, ea, eh, fa, nc, ff, o; float lonConvert = 561/12; float latConvert = 480/8.55; float fadeSpeed = 5; boolean clickable = true; boolean locked = false; Calendar currentDate = Calendar.getInstance(); PImage iraqmap; String currentDateStr = ""; String[] monthnames = new String[12]; String y = ""; String m = ""; String d = ""; Handle[] handles; void setup() { size(640, 480); // frameRate(60); smooth(); handles = new Handle[2]; int hsize = 10; for(int i=0; i= 0; i--) { // An ArrayList doesn't know what it is storing so we have to cast the object coming out Death death = (Death) deaths.get(i); // ball.move(); noStroke(); death.display(); if (death.finished()) { // Items can be deleted with remove() deaths.remove(i); } } currentFrame++; } class Death { float x; float y; int r; int g; int b; float w; float life = 255; float opacity = 10; Death(float tempX, float tempY, float tempW, int tr, int tg, int tb) { x = tempX; y = tempY; w = tempW; r = tr; g = tg; b = tb; } boolean finished() { // Balls fade out if (life > 230) { life = life-10; }else{ life=life-fadeSpeed; } if (life < 10) { return true; } else { return false; } } void display() { // Display the circle fill(r,g,b,life); //stroke(0,life); ellipse(x,y,5+(w/3),5+(w/3)); } } class Button { int x, y; int size; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; boolean switchedOn = true; void update() { if(over()) { currentcolor = highlightcolor; } else { currentcolor = basecolor; } } boolean pressed() { if(over) { locked = true; return true; } else { locked = false; return false; } } boolean over() { return true; } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } } class RectButton extends Button { String txt; RectButton(int ix, int iy, int isize, color icolor, color ihighlight, String itxt) { x = ix; y = iy; size = isize; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; txt = itxt; } boolean over() { if( overRect(x, y, size, size) ) { over = true; return true; } else { over = false; return false; } } void display() { stroke(255); strokeWeight(1); fill(currentcolor); rect(x, y, size, size); fill(128); text(txt, x+20, y+10); if(switchedOn){ stroke(0); strokeWeight(2); line(x+1,y+1,x+size-1, y+size-1); line(x+size-1, y+1, x+1, y+size-1); } } } void update(int x, int y) { if(locked == false) { ce.update(); ea.update(); eh.update(); fa.update(); nc.update(); ff.update(); o.update(); } else { locked = false; } if(mousePressed) { if(ce.pressed() && clickable) { ce.switchedOn = !ce.switchedOn; } else if(ea.pressed() && clickable) { ea.switchedOn = !ea.switchedOn; }else if(eh.pressed() && clickable){ eh.switchedOn = !eh.switchedOn; }else if(fa.pressed() && clickable){ fa.switchedOn = !fa.switchedOn; }else if(nc.pressed() && clickable){ nc.switchedOn = !nc.switchedOn; }else if(ff.pressed() && clickable){ ff.switchedOn = !ff.switchedOn; }else if(o.pressed() && clickable){ o.switchedOn = !o.switchedOn; } clickable = false; }else{ clickable = true; } } class Handle { int x, y; int boxx, boxy; int length; int size; int fullLength; boolean over; boolean press; boolean locked = false; boolean otherslocked = false; Handle[] others; Handle(int ix, int iy, int il, int is, Handle[] o) { x = ix; y = iy; length = il; size = is; fullLength = length; boxx = x+length - size/2; boxy = y - size/2; others = o; } void update() { boxx = x+length; boxy = y - size/2; for(int i=0; i= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } int lock(int val, int minv, int maxv) { return min(max(val, minv), maxv); } void mouseReleased() { for(int i=0; i