Last active
February 9, 2016 05:32
-
-
Save sasaki-shigeo/20abfbeedc516042e449 to your computer and use it in GitHub Desktop.
analogue clock / アナログ時計
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float r; | |
| void setup() { | |
| size(500, 500); | |
| r = min(width, height) * 7 / 16; | |
| frameRate(1); | |
| smooth(); | |
| } | |
| void draw() { | |
| background(255); | |
| float s = second(); | |
| float m = minute() + s/60; | |
| float h = hour() + m/60; | |
| float rs = 0.9 * r; | |
| float rm = 0.8 * r; | |
| float rh = 0.7 * r; | |
| translate(width / 2, height / 2); | |
| rotate(radians(-90)); | |
| // the hour hand | |
| stroke(0); | |
| strokeWeight(4); | |
| line(0, 0, rh * cos(radians(30 * h)), rh * sin(radians(30 * h))); | |
| // the minute hand | |
| strokeWeight(2); | |
| line(0, 0, rm * cos(radians(6 * m)), rm * sin(radians(6 * m))); | |
| // the second hand | |
| stroke(255, 0, 0); | |
| strokeWeight(1); | |
| line(0, 0, rs * cos(radians(6 * s)), rs * sin(radians(6 * s))); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment