34. /* Clock.pde */
class Clock {
float s, m, h;
float lastSecond=0;
Ring[] rings;
int numRings = 60;
int currentRing = 0;
Clock(){
rings = new Ring[numRings];
for(int i = 0; i < numRings; i++){
rings[i] = new Ring();
}
}
void getTime(){
s = second();
m = minute();
h = hour()%12;
}
35. void display(){
background(0);
for(int i = 0; i < numRings; i++){
rings[i].grow();
rings[i].display();
}
if(lastSecond != s){
float r = width/4.0;
float posX = r * cos(radians(s*6.0)) + width/2;
float posY = r * sin(radians(s*6.0)) + height/2;
rings[int(s)].start(posX, posY);
lastSecond = s;
}
}
}
36. /* Ring.pde */
class Ring {
float x, y, diameter;
boolean on = false;
color col;
void start(float _x, float _y){
x = _x;
y = _y;
on = true;
diameter = 1;
col = color(random(360), 50, 100, 50);
}
void grow() {
if(on) {
diameter+=0.1;
if(diameter > width){
on = false;
}
}
}