Analog Clock

아날로그 시계를 만들어보았다.

흘러가는 세월아…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
int s; // size
float r;
void setup() {
s = 300;
r = s / 2;
size(s, s);
smooth();
frameRate(15);
}
void draw() {
strokeWeight(1.5);
// translate to center
translate(s / 2, s / 2);
rotate(radians(270));
// draw circle
stroke(#000000);
fill(#FFFFFF);
ellipse(0, 0, s, s);
// draw hour numbers
float u = radians(360 / 12);
for(int h = 0; h < 12; h++) {
pushMatrix();
float x = (r * 0.9) * cos(h * u);
float y = (r * 0.9) * sin(h * u);
translate(x, y);
rotate(radians(90));
fill(#000000);
textAlign(CENTER, CENTER);
text(h, 0, 0);
popMatrix();
}
// second needle
float ts = radians(second() * (360 / 60));
stroke(#FF0000);
line(0, 0, (r * 0.9) * cos(ts), (r * 0.9) * sin(ts));
// minute needle
float tm = radians(minute() * (360 / 60));
stroke(#00FF00);
line(0, 0, (r * 0.8) * cos(tm), (r * 0.8) * sin(tm));
// hour needle
float th = radians(hour() * (360 / 12));
stroke(#0000FF);
line(0, 0, (r * 0.7) * cos(th), (r * 0.7) * sin(th));
}
Share Comments