- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Turtle
More file actions
Latest commit
101 lines (88 loc) · 2.72 KB
/
Copy pathPython Turtle
File metadata and controls
101 lines (88 loc) · 2.72 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
importturtle
importtime
print("Python Turtle Analogue Clock")
#Deal with different time zones
ok=False
whilenot(ok):
print("\nFor example, for British summer time enter 1")
offset=int(input("Enter offset from GMT (-11 to 11) :"))
ifoffset>=-11andoffset<=11:
ok=True
wn=turtle.Screen()
wn.title("TURTLE CLOCK")
SCALE=1.7# size of clock scale factor (try 2.0 to 0.5)
#create dial
mark=turtle.Turtle()
mark.speed(200)
mark.shape("circle")
foriinrange(60):
ifi%5==0:
mark.pensize(10)
mark.penup()
mark.forward(200*SCALE)
mark.pendown()
mark.forward(10*SCALE)
mark.penup()
mark.backward(210*SCALE)
else:
mark.pensize(5)
mark.penup()
mark.forward(200*SCALE)
mark.pendown()
mark.forward(5*SCALE)
mark.penup()
mark.backward(205*SCALE)
mark.right(6)
update=True#controls whether minute and hour hand should update (once per minute)
updateSecond=True# controls whether the second hanbd should update
whileTrue:
b=time.gmtime(time.time()) # current GMT
m=b.tm_min# remember the current minute
s=b.tm_sec# rember the current second
ifupdate:
#hour hand
hour=turtle.Turtle()
hour.left(90)
hour.speed(100*SCALE)
hour.pensize(10)
hour.shape("blank")
hour.right(((b.tm_hour+offset) %12) *30+b.tm_min*0.5 )
hour.backward(30*SCALE)
hour.forward(160*SCALE)
#minute hand
minute=turtle.Turtle()
minute.speed(100)
minute.shape("blank")
minute.left(90)
minute.pensize(6)
minute.right((b.tm_min) *6)
minute.backward(30*SCALE)
minute.forward(180*SCALE)
update=False
ifupdateSecond:
#second hand
second=turtle.Turtle()
second.speed(100)
second.shape("blank")
second.color("red")
second.left(90)
second.pensize(3)
second.right((b.tm_sec) *6)
second.backward(30*SCALE)
second.forward(190*SCALE)
updateSecond=False
time.sleep(0.3)
b=time.gmtime(time.time())
new_min=b.tm_min
new_sec=b.tm_sec
ifnew_min!=m:
update=True
hour.clear() # Clear out the drawing (if any)
hour.reset()
minute.clear()
minute.reset()
ifnew_sec!=s:
updateSecond=True
second.clear()
second.reset()