/** * Bodycount * * visualizes the iraqi body count data from * http://www.iraqbodycount.net * * by Evan Raskob 2003_09_08 */ // the bodycount data String lines[]; BFont metaBold; //chody counter variable int cnt; //number of rows of data static final int ROWCOUNT = 177; //width of each rectangular box static final int RECTWIDTH = 2; //holds the data Integer min_max_dead[][]; BodyCountBox[] bcbs; float screens; int boxesPerScreen; float pixelsPerBox; int moveBoxes; void setup() { size(400, 600); println("STARTED"); screens = 1.0; boxesPerScreen = ROWCOUNT; pixelsPerBox = width/ROWCOUNT; moveBoxes = ROWCOUNT-boxesPerScreen; min_max_dead = new Integer[2][ROWCOUNT]; lines = loadStrings("iraqbodycount.txt"); background(#989898); metaBold = loadFont("Meta-Bold.vlw.gz"); setFont(metaBold, 40); hint(SMOOTH_IMAGES); for (cnt = 0; cnt < ROWCOUNT; cnt++) { min_max_dead[0][cnt] = new Integer((splitStrings(lines[cnt], '\t')[6])); min_max_dead[1][cnt] = new Integer((splitStrings(lines[cnt], '\t')[7])); /* println("min = " + min_max_dead[0][cnt]); println("max = " + min_max_dead[1][cnt]); println("size = " + min_max_dead[0].length); */ } bcbs = new BodyCountBox[ROWCOUNT]; for (cnt=0; cnt width) { xpos = width; } else if (mouseX < 0) { xpos = 0; } float rcount = ROWCOUNT+0.0; float crap = abs(xpos/width*boxesPerScreen); moveBoxes = int( max(0, crap) ); //println("screens="+screens+" boxesPerScreen="+boxesPerScreen+" pixelsPerBox="+pixelsPerBox+" moveBoxes="+moveBoxes); } void loop() { delay(20); int diff = 0; int redFill = 0; int textX = 0; int textY = 0; int maxcnt = min(boxesPerScreen+moveBoxes, ROWCOUNT); int i =0; for (cnt = moveBoxes; cnt < maxcnt; cnt++) { diff = getMaxDead(cnt) - getMinDead(cnt); // calculate red fill color value redFill = getMinDead(cnt)*2; if (redFill > 255) redFill =255; fill(redFill, 0, 0); bcbs[cnt].init(i*pixelsPerBox+50, width/2, pixelsPerBox, diff*pixelsPerBox, 18*pixelsPerBox); bcbs[cnt].draw(); i++; fill(230, 210, 120); textX = 25; textY = 55; text("the uncertainty of life and death", textX, textY); /* if (mouseX > 0 && mouseX < width) { textX+=20; textY+=50; setFont(metaBold, 20); text("max :"+getMaxDead(mouseX), textX, textY); textY+=16; text("min :"+getMinDead(mouseX), textX, textY); textX-=20; textY+=20; text("uncertainty :"+ getUncertainty(mouseX)+"%", textX, textY); setFont(metaBold, 40); } fill(#FFFFFF); */ } } int getRelativeIndex(float index) { int rindex = min(int(index/pixelsPerBox), ROWCOUNT); return rindex; } int getMaxDead(float index) { return min_max_dead[1][getRelativeIndex(index)].intValue(); } int getMaxDead(int index) { return min_max_dead[1][index].intValue(); } int getMinDead(int index) { return min_max_dead[0][index].intValue(); } int getMinDead(float index) { return min_max_dead[0][getRelativeIndex(index)].intValue(); } int getUncertainty(float index) { int retval = 0; if (getMinDead(index) > 0) retval = int( 100*(getMaxDead(index)-getMinDead(index))/getMinDead(index) ); return retval; } class BodyCountBox { float xpos; // box xposition float ypos ; // box yposition float W; // box width float H; // box height float D; // box depth BodyCountBox() { xpos = 0; ypos = 0; W = 0; H = 0; D = 0; } BodyCountBox(float xp, float yp, float w, float h, float d) { xpos = xp; ypos = yp; W = w; H = h; D = d; } void init(float xp, float yp, float w, float h, float d) { xpos = xp; ypos = yp; W = w; H = h; D = d; } void moveToY (float posY, float damping) { float dif = ypos - posY; if (abs(dif) > 1) { ypos -= dif/damping; } } void moveToX (float posX, float damping) { float dif = xpos - posX; if (abs(dif) > 1) { xpos -= dif/damping; } } void draw() { push(); translate(xpos, ypos, 0); rotateX(0.25); rotateZ(0.35); box(W, H, D); pop(); } }