-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockProject.py
More file actions
106 lines (89 loc) · 1.89 KB
/
ClockProject.py
File metadata and controls
106 lines (89 loc) · 1.89 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
102
103
104
105
106
import time
import turtle
import math
t = turtle.Turtle()
c = turtle.Turtle()
t.hideturtle()
t.speed(10) # for hands
c.speed(10) # for drawing clock
# turtle.Screen().bgcolor(0,0,0)
def polygon(s, l):
for _ in range(s):
c.fd(l)
c.rt(360 / s)
def circle(r):
c = math.pi * 2 * r
polygon(int(c), 3)
def outer():
c.penup()
c.goto(-300, 300)
c.pendown()
c.begin_fill()
c.fillcolor(0, 0, 0)
polygon(4, 600)
c.end_fill()
def draw_clock():
outer()
c.penup()
c.goto(0, 300)
c.pendown()
c.begin_fill()
c.fillcolor(1, 1, 1)
circle(100)
c.end_fill()
c.penup()
c.goto(0, 0)
c.setheading(90)
for x in range(13):
c.fd(299)
c.pendown()
# c.bk(10) # to revert back to lines you need to go back 5 again to write the number
c.rt(90) # for triangle
c.bk(5) # for triangle
c.begin_fill()
c.fillcolor(0, 0, 0)
polygon(3, 10)
c.end_fill()
c.penup()
c.fd(5) # for triangle
c.lt(90) # for triangle
c.bk(20) # for triangle
if x == 0:
h = 12
else:
h = x
c.write(str(h), align='center', font=('Arial', 12, 'normal'))
c.fd(20)
c.goto(0, 0)
c.rt(360 / 12)
c.hideturtle()
def reset_turtle():
t.pensize(2)
t.penup()
t.goto(0, 0)
t.setheading(90)
t.pendown()
def clockface(h, m, s):
t.speed(0)
reset_turtle()
h = h + (m / 60)
t.rt(h * 30)
t.fd(190)
reset_turtle()
t.rt(m * 6)
t.fd(260)
reset_turtle()
t.rt(s * 6)
t.pensize(1)
t.fd(300)
def clock():
draw_clock()
tm = time.localtime()
while True:
t.clear()
tm = time.localtime()
# turtle.tracer(1,100)
clockface(tm.tm_hour, tm.tm_min, tm.tm_sec)
turtle.update()
time.sleep(0.7)
clock()