/* DO NOT TOUCH */
float mill = 0;
int prevSec = 0;
void setup() {
size(640, 640);
fill(0);
noStroke();
// Set up the clock for the current second
prevSec = second();
}
void draw() {
fill(0, 30);
rect(0, 0, width, height);
translate(width/2, height/2);
// If this second (30) minus the previous second (29) is less than 1 than add one (milliseconds) or if seconds are 0
if (second()-prevSec < 1 || mill == 0) {
// Adding 1 will count up to 60
mill+=2;
} else if (second()-prevSec == 1) {
// If we have reached the next second, restart the milliseconds and make prevSec equal to the second
mill = 0;
prevSec = second();
} else {
mill+=2;
}
// If we have completed the second, reset millis timer
if (mill >= 120)mill = 0;
// If we have reached the end of the minute (It never reaches 60, after 59 it goes straight to 0)
// and we are at the start of the second, reset millis timer. We need to do this manually because
// our original if statement says if second - previous second. But because our second is will be 0 and our
// previous second will be 59 we will skip the animation of the first second.
if (second() == 59 && mill == 0) {
prevSec = 0;
}
for (int i = 0; i < 360; i+=6) {
float angle = 0; //sin(radians(i*3+frameCount)) * 30;
float x = sin(radians(i));
float y = cos(radians(i));
fill(map(i, 0, 360, 0, 255), map(i, 0, 360, 255, 0), 0);
/* Moving ellipse from center to posision */
if (second()*6 == i) clockDot(x*(mill-angle), y*(mill-angle), 6, 30, i);
/* Show the ellipse if the second has passed */
if (i < second()*6){
clockDot(x*(120-angle), y*(120-angle), 6, 30, i);
}
}
}
void clockDot(float x, float y, float w, float h, float angle) {
pushMatrix();
translate(x, y);
rotate(radians(-angle));
rect(0, 0, w, h, w);
popMatrix();
}