xxxxxxxxxx
var h, m, s;
var speedUp, speedUpScale;
var clockTypeText;
function setup() {
createCanvas(windowWidth, windowHeight);
// Font display information
fill(0);
textSize(48);
textFont('Georgia');
// Speed Up - if true, uses the current time for the initial time, but then
// advances it much more quickly from there based on the speedUpScale and the frameRate
speedUp = true;
speedUpScale = 60;
clockTypeText = "";
h = hour();
m = minute();
s = second();
}
function draw() {
background(100);
if (speedUp) {
frameRate(1);
clockTypeText = "Speed Clock: " + speedUpScale + "x";
s += speedUpScale;
if (s >= 60) {
s = 0;
}
if (m >= 60) {
m = 0;
h++;
}
if (h >= 24) {
h = 0;
}
} else {
clockTypeText = "Real Time";
h = hour();
m = minute();
s = second();
}
// Show the time, real or sped up
text(clockTypeText, width/2 - 200, height/2 - 100);
text(h + ":" + m + ":" + s, width/2 - 100, height/2);
}
function keyReleased() {
if (keyCode === UP_ARROW) {
speedUpScale+=10;
} else if (keyCode === DOWN_ARROW) {
speedUpScale-=10;
} else if (keyCode === RIGHT_ARROW || keyCode === LEFT_ARROW) {
speedUp = !speedUp;
}
}