boolean playing = true; void draw() { background(0); time(); if (currentTime > end) { currentTime = end; playing = false; } pushMatrix(); scale(0.9); translate(30, 0); drawProtest(); popMatrix(); drawCounter(); translate(10, 520); drawChrome(); translate(10, 86); drawTimeline(); translate(412, -15); drawButton(); } void time() { if (playing) { if (currentTime < end) { currentTime += 100000 * 4; } } } int absolute = 0; void drawCounter() { textAlign(RIGHT); fill(255); text(str(absolute), width - 20 - 70, 20, 70, 20); absolute = 0; } void drawTimeline() { int added = 0; while (added < votesPerHour.length) { if (added < currentHour() || currentTime == end) { fill(51, 173, 163); int h = (int) map(votesPerHour[added], 0, maxVotesPerHour, 0, 75); rect(16 * added, -h - 1, 15, h); } fill(72, 246, 230); rect(16 * added, 0, 15, 4); added++; } int xPos = (int) map(currentTime, start, end, 0, 383); textAlign(CENTER); fill(0, 80); text(nowAsString(), xPos - 34, -17, 70, 20); fill(255); text(nowAsString(), xPos - 35, -18, 70, 20); image(pointer, xPos - 7, 8); } void drawProtest() { pushMatrix(); for (int i = 0; i < visualizations.size(); i++) { pushMatrix(); Vis vis = (Vis) visualizations.get(i); vis.draw(); popMatrix(); } popMatrix(); } void drawChrome() { //image(chromeBg, 0, 0); } void drawButton() { if (playing) { image(buttonPause, 0, 0); } else { image(buttonPlay, 0, 0); } } void mouseDragged() { if (mouseX > 10 && mouseX < 402 && mouseY > 606) { long newTime = (long) map(mouseX, 10, 402, start, end); currentTime = newTime; playing = false; } } void mouseReleased() { if (dist(mouseX, mouseY, 455, 606) < 20) { if (currentTime == end && playing == false) { currentTime = start; playing = true; } else { playing = !playing; } } } String nowAsString() { SimpleDateFormat sdf = new SimpleDateFormat("H.mm"); Date d = new Date(currentTime); return sdf.format(d); } int currentHour() { return new Date(currentTime).getHours(); }