forked from furas/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-1.py
More file actions
80 lines (52 loc) · 1.66 KB
/
Copy pathexample-1.py
File metadata and controls
80 lines (52 loc) · 1.66 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
#!/usr/bin/env python3
#
# http://stackoverflow.com/questions/21978044/clock-in-python
#
from pygame import *
from pygame.locals import *
from math import *
#----------------------------------------------------------------------
init()
screen = display.set_mode((800,600))
clock = time.Clock()
hours = 5
minutes = 59
seconds = 50
running=True
while running:
# events
for e in event.get():
if e.type == QUIT:
running = False
# (variable) modifications
seconds_ang = 270 + 6 * seconds
seconds_dx = int(cos(radians(-seconds_ang))*200)
seconds_dy = int(sin(radians(-seconds_ang))*200)
minutes_ang = 270 + 6 * minutes
#minutes_ang = 270 + 6 * (minutes + seconds/60.) # smoother move
minutes_dx = int(cos(radians(-minutes_ang))*200)
minutes_dy = int(sin(radians(-minutes_ang))*200)
hours_ang = 270 + 30 * hours
#hours_ang = 270 + 30 * (hours + minutes/60.) # smoother move
hours_dx = int(cos(radians(-hours_ang))*150)
hours_dy = int(sin(radians(-hours_ang))*150)
seconds += 1
if seconds == 60:
seconds = 0
minutes += 1
if minutes == 60:
minutes = 0
hours += 1
if hours == 12:
hours = 0
# draw
screen.fill((0,0,0))
draw.circle(screen, (255,255,255), (400,300), 200, 3)
draw.line(screen,(0,255,255), (400,300), (400 + hours_dx, 300 - hours_dy), 5)
draw.line(screen,(255,255,0), (400,300), (400 + minutes_dx, 300 - minutes_dy), 2)
draw.line(screen,(255,0,255), (400,300), (400 + seconds_dx, 300 - seconds_dy), 1)
# flip
display.flip()
# FPS (Frames Per Seconds)
clock.tick(1)
quit()