int HOUR = 12, MIN = 00, SEC = 00, reset = millis() + 1000; PFont norm, big; void setup() { size(1368+35, 1024+30); norm = createFont("bogus", 12); big = loadFont("Digital-7Mono-250.vlw"); textAlign(CENTER, CENTER); textFont(big); background(0); } void draw() { //Calculate time to launch, in seconds int time = 3600*(HOUR - hour()) + 60*(MIN - minute()) + (SEC - second()); if (time < -12*3600) time += 24*3600; if (time > 12*3600) time -= 24*3600; //Calculate the hours, minutes, and seconds to launch. String preamble = "T-"; if (time<0) { preamble = "T+"; time *= -1; } int hour = int(time/3600); int min = int((time - 3600*hour)/60); int sec = int(time - 3600*hour - min*60.0); //If reset is active, display the target time instead of the timer. if (reset > millis()) { hour = HOUR; min = MIN; sec = SEC; background(0); preamble = "ST"; textFont(norm); textAlign(LEFT, TOP); fill(255); text("Time adjustment H: +q -a M: +w-s S: +e-d Current time: n Press space to return to countdown.", 0, 0); textAlign(CENTER, CENTER); textFont(big); } fill(0, 50); rect(-1, -1, width+2, height+2); fill(255, 0, 0, 10); //Background fade text("T-88:88:88", width/2, height/2); fill(255, 0, 0); //Active characters. if (hour == 0 && min == 0 && sec <= 10 && preamble.equals("T-") && (millis() % 1000) <= 500) return; text(preamble + f(hour) + ":" + f(min) + ":" + f(sec), width/2, height/2); } String f(int num) { if (num >= 10) return str(num); else return "0" + str(num); } void keyPressed() { //Keyboard used to change time. reset = millis() + 5000; if (key == 'q') HOUR += 1; if (key == 'a') HOUR -= 1; if (key == 'w') MIN += 1; if (key == 's') MIN -= 1; if (key == 'e') SEC += 1; if (key == 'd') SEC -= 1; if (key == ' ') reset = 0; if (key == 'n') { SEC = second(); MIN = minute(); HOUR = hour(); } if (SEC > 59) {SEC = 0; MIN += 1;} if (SEC < 0) {SEC = 59; MIN -= 1;} if (MIN > 59) {MIN = 0; HOUR += 1;} if (MIN < 0) {MIN = 59; HOUR -= 1;} if (HOUR > 23) HOUR = 0; if (HOUR < 0) HOUR = 23; }