Skip to content

Commit 5182e92

Browse files
committed
feat: #107 Added a Analog clock code
1 parent 5675c6d commit 5182e92

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

Clock/Clock.py

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
import time
2+
import turtle
3+
import datetime
4+
import threading
5+
6+
#set the arms at current time location
7+
8+
H = int(datetime.datetime.now().strftime("%I"))
9+
M = int(datetime.datetime.now().strftime("%M"))
10+
H = (H * 30) + (M * 12/30)
11+
M = M * 6
12+
P = str(datetime.datetime.now().strftime("%p"))
13+
14+
15+
# making of turtles
16+
a = turtle.Turtle()
17+
a.screen.bgcolor("lightgreen")
18+
a.hideturtle()
19+
a.speed(0)
20+
21+
b = turtle.Turtle()
22+
b.screen.bgcolor("lightgreen")
23+
b.hideturtle()
24+
b.speed(0)
25+
26+
c = turtle.Turtle()
27+
c.screen.bgcolor("lightgreen")
28+
c.hideturtle()
29+
c.speed(0)
30+
31+
32+
p = turtle.Turtle()
33+
p.color('darkblue')
34+
p.penup()
35+
p.right(90)
36+
p.fd(60)
37+
p.pendown()
38+
p.hideturtle()
39+
40+
turtle.setup(600,600)
41+
turtle.title("CLOCK")
42+
43+
def ap():
44+
45+
p.write(P,font = ('times of roman',20))
46+
47+
48+
#design a clock
49+
a.pensize(5)
50+
a.begin_fill()
51+
a.fillcolor('blue')
52+
a.penup()
53+
a.goto(0,-200)
54+
a.pendown()
55+
a.circle(200)
56+
a.penup()
57+
a.home()
58+
a.goto(0,-170)
59+
a.pendown()
60+
a.circle(170)
61+
a.end_fill()
62+
63+
64+
a.begin_fill()
65+
a.fillcolor('lightblue')
66+
a.penup()
67+
a.home()
68+
a.goto(0,-170)
69+
a.pendown()
70+
a.circle(170)
71+
a.end_fill()
72+
73+
a.penup()
74+
a.home()
75+
a.pendown()
76+
a.left(90)
77+
78+
#marking a clock numbers
79+
for i in range(0,12):
80+
81+
a.right(30)
82+
a.penup()
83+
a.fd(130)
84+
a.pendown()
85+
a.write((i+1), font=("Arial", 20, "normal"))
86+
a.penup()
87+
a.goto(-6,-7)
88+
a.pendown()
89+
90+
#second hand
91+
def second():
92+
angle = 0
93+
a.penup()
94+
a.home()
95+
a.left(90)
96+
a.pendown
97+
while True:
98+
a.right(angle)
99+
a.pendown()
100+
a.pensize(2)
101+
a.fd(100)
102+
time.sleep(1)
103+
a.undo()
104+
a.goto(0,0)
105+
angle = 6
106+
107+
#minute hand
108+
def minute():
109+
angleb = 0
110+
b.left(90)
111+
b.right(M)
112+
while True:
113+
b.right(angleb)
114+
b.pendown()
115+
b.pensize(3)
116+
b.fd(120)
117+
time.sleep(60)
118+
b.undo()
119+
b.goto(0,0)
120+
angleb = 6
121+
122+
#hour hand
123+
def hour():
124+
anglec = 0
125+
c.left(90)
126+
c.right(H)
127+
while True:
128+
c.right(anglec)
129+
c.pendown()
130+
c.pensize(6)
131+
c.fd(80)
132+
time.sleep(600)
133+
c.undo()
134+
c.goto(0,0)
135+
anglec = 1
136+
137+
#activate all three arm at once
138+
139+
thread1 = threading.Thread(target = second)
140+
thread1.start()
141+
142+
thread2 = threading.Thread(target = minute)
143+
thread2.start()
144+
145+
thread3 = threading.Thread(target = hour)
146+
thread3.start()
147+
148+
thread4 = threading.Thread(target = ap)
149+
thread4.start()
150+
151+
turtle.done()
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+

0 commit comments

Comments
 (0)