Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // clock code, written by C.J. Winkler
- void setup() {
- size(500, 500);
- }
- void draw() {
- background(255);
- // get the current time
- int s = second(); // values from 0 - 59
- int m = minute(); // values from 0 - 59
- int h = hour(); // values from 0 - 23
- // move origin to center of the screen
- translate(250, 250);
- // draw the seconds hand
- pushMatrix();
- rotate(radians(map(s, 0, 59, 0, 360)));
- stroke(255, 0, 0);
- strokeWeight(1);
- line(0, 0, 0, -225);
- popMatrix();
- // draw the minutes hand
- pushMatrix();
- rotate(radians(map(m + s / 60.0, 0.0, 60.0, 0.0, 360.0)));
- stroke(0, 0, 255);
- strokeWeight(5);
- line(0, 0, 0, -200);
- popMatrix();
- // draw the hours hand
- pushMatrix();
- if (h > 12) h -= 12;
- rotate(radians(map(h + m / 60.0, 0.0, 24, 0.0, 360.0)));
- strokeWeight(5);
- stroke(0, 255, 0);
- line(0, 0, 0, -100);
- popMatrix();
- // "button" at the center
- fill(0);
- noStroke();
- ellipse(0, 0, 15, 15);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement