Clocks that rotate
in
Programming Questions
•
1 month ago
Hi everyone,
I started on my second project and i'm stuck. I need to make two clocks that rotate. I will try to explain this as good as possible.
I made two analog clocks. One will display the hours and the second one will display the minutes. The clocks dont have arms but will instead just rotate itself. The place where the two clocks touch is the place where the time is displayed.
e.g, If its 6: 30 , the hour and minute clocks will rotate untill the 6h and the 30m meet eachother. I think I can rotate them but I dont know how to rotate the clocks so that the time will always be at the place where the clocks meet eachother.
I hope that someone can help me or at least point me into the right direction
I started on my second project and i'm stuck. I need to make two clocks that rotate. I will try to explain this as good as possible.
I made two analog clocks. One will display the hours and the second one will display the minutes. The clocks dont have arms but will instead just rotate itself. The place where the two clocks touch is the place where the time is displayed.
e.g, If its 6: 30 , the hour and minute clocks will rotate untill the 6h and the 30m meet eachother. I think I can rotate them but I dont know how to rotate the clocks so that the time will always be at the place where the clocks meet eachother.
I hope that someone can help me or at least point me into the right direction
- void setup() {
size(500, 500);
stroke(255);
smooth();
int fontSize=16;
}
void draw() {
background(200);
fill(80);
noStroke();
// Angles for sin() and cos() start at 3 o'clock;
// subtract HALF_PI to make them start at the top
ellipse(100, 100, 160, 160);
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
float m = map(minute(), 0, 60, 0, TWO_PI) - HALF_PI;
float h = map(hour() % 12, 0, 12, 0, TWO_PI) - HALF_PI;
stroke(255);
strokeWeight(1);
line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100);
strokeWeight(2);
line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100);
strokeWeight(4);
line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100);
fill(255);
float angle = -HALF_PI + HALF_PI / 3;
float angle_inc = TWO_PI / 12;
for ( int i = 1; i <= 12; i++, angle += angle_inc ) {
text(i,95 + cos(angle) * 70,105 + sin(angle) * 70);
}
ellipse(270, 270, 300, 300);
}
1