We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys! I need help on my clock project. Why is the hour hand not moving? Help!
void setup()
{
size(200, 200);
stroke(255);
}
void draw()
{
background(34, 40, 20);
fill(255, 255, 255);
ellipse(width/2, height/2, width, height);
pushMatrix();
translate(width/2, height/2);
rotate(radians(map(second(),0, 60, 0, 360)));
fill(255, second()*2, second()*2);
noStroke();
rect(0, -50, 10, 10);
popMatrix();
pushMatrix();
translate(width/2, height/2);
rotate(radians(minute()*6));
stroke(0);
line(0, 0, 0, -50);
popMatrix();
pushMatrix();
translate(width/2, height/2);
rotate(radians(hour()*5));
stroke(0);
line(0, 0, 0, -50);
popMatrix();
}
Answers
Line 30 should be
rotate(radians(hour()*30));
since there is a full rotation every 12 hours (i.e. 360/ 12 = 30° per hour)
Notice that since the method hour() return integers you will not get smooth movement of the hands but rather it will jump 30° every hour on te hour
To fix that you need to consider fractions of minutes and hours like this