-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic-Pen-Clock.py
74 lines (64 loc) · 1.33 KB
/
Basic-Pen-Clock.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import turtle, time
wn = turtle.Screen()
wn.bgcolor("black")
wn.setup(width=600, height=600)
wn.title("Simple Analog Clock")
wn.tracer(0)
pen=turtle.Turtle()
pen.hideturtle()
pen.speed(0)
pen.pensize(3)
def draw_clock(h, m, s, pen):
# Draw clock face
pen.up()
pen.goto(0, 210)
pen.setheading(180)
pen.color("green")
pen.pendown()
pen.circle(210)
# Draw 12 hour-lines of the clock
pen.penup()
pen.goto(0,0)
pen.setheading(90)
for i in range(12):
pen.fd(190)
pen.pendown()
pen.fd(20)
pen.penup()
pen.goto(0,0)
pen.rt(30)
# Draw hour hand
pen.penup()
pen.goto(0,0)
pen.color("red")
pen.setheading(90)
angle=(h/12)*360
pen.rt(angle)
pen.pendown()
pen.fd(75)
# Draw minute hand
pen.penup()
pen.goto(0,0)
pen.color("blue")
pen.setheading(90)
angle=(m/60)*360
pen.rt(angle)
pen.pendown()
pen.fd(175)
# Draw seconds hand
pen.penup()
pen.goto(0,0)
pen.color("yellow")
pen.setheading(90)
angle=(s/60)*360
pen.rt(angle)
pen.pendown()
pen.fd(150)
while True:
h = int(time.strftime("%I"))
m = int(time.strftime("%M"))
s = int(time.strftime("%S"))
draw_clock(h, m, s, pen)
wn.update()
pen.clear()
wn.mainloop()