Skip to content

Commit d3c2842

Browse files
committed
Examples: Adding vector_clock_full.py
1 parent 02ed8cc commit d3c2842

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

examples/vector_clock_full.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
from interstate75 import Interstate75, DISPLAY_INTERSTATE75_128X128
2+
import time
3+
import gc
4+
from picovector import PicoVector, Polygon, Transform, ANTIALIAS_X16
5+
6+
i75 = Interstate75(display=DISPLAY_INTERSTATE75_128X128)
7+
display = i75.display
8+
9+
WIDTH = i75.width
10+
HEIGHT = i75.height
11+
12+
vector = PicoVector(display)
13+
t = Transform()
14+
vector.set_transform(t)
15+
vector.set_antialiasing(ANTIALIAS_X16)
16+
17+
RED = display.create_pen(200, 0, 0)
18+
BLACK = display.create_pen(0, 0, 0)
19+
DARKGREY = display.create_pen(100, 100, 100)
20+
GREY = display.create_pen(200, 200, 200)
21+
WHITE = display.create_pen(255, 255, 255)
22+
23+
"""
24+
# Redefine colours for a Blue clock
25+
RED = display.create_pen(200, 0, 0)
26+
BLACK = display.create_pen(135, 159, 169)
27+
GREY = display.create_pen(10, 40, 50)
28+
WHITE = display.create_pen(14, 60, 76)
29+
"""
30+
31+
WIDTH, HEIGHT = display.get_bounds()
32+
MIDDLE = (int(WIDTH / 2), int(HEIGHT / 2))
33+
34+
hub = Polygon()
35+
hub.circle(int(WIDTH / 2), int(HEIGHT / 2), 5)
36+
37+
face = Polygon()
38+
face.circle(int(WIDTH / 2), int(HEIGHT / 2), int(HEIGHT / 2))
39+
40+
tick_mark = Polygon()
41+
tick_mark.rectangle(int(WIDTH / 2) - 3, 10, 6, int(HEIGHT / 48))
42+
43+
hour_mark = Polygon()
44+
hour_mark.rectangle(int(WIDTH / 2) - 5, 10, 10, int(HEIGHT / 10))
45+
46+
minute_hand_length = int(HEIGHT / 2) - int(HEIGHT / 24)
47+
minute_hand = Polygon()
48+
minute_hand.path((-5, -minute_hand_length), (-10, int(HEIGHT / 16)), (10, int(HEIGHT / 16)), (5, -minute_hand_length))
49+
50+
hour_hand_length = int(HEIGHT / 2) - int(HEIGHT / 8)
51+
hour_hand = Polygon()
52+
hour_hand.path((-5, -hour_hand_length), (-10, int(HEIGHT / 16)), (10, int(HEIGHT / 16)), (5, -hour_hand_length))
53+
54+
second_hand_length = int(HEIGHT / 2) - int(HEIGHT / 8)
55+
second_hand = Polygon()
56+
second_hand.path((-2, -second_hand_length), (-2, int(HEIGHT / 8)), (2, int(HEIGHT / 8)), (2, -second_hand_length))
57+
58+
print(time.localtime())
59+
60+
last_second = None
61+
62+
display.set_pen(BLACK)
63+
display.clear()
64+
display.set_pen(WHITE)
65+
vector.draw(face)
66+
67+
68+
while True:
69+
t_start = time.ticks_ms()
70+
year, month, day, hour, minute, second, _, _ = time.localtime()
71+
72+
if last_second == second:
73+
time.sleep_ms(10)
74+
continue
75+
76+
last_second = second
77+
78+
t.reset()
79+
80+
display.set_pen(WHITE)
81+
display.circle(int(WIDTH / 2), int(HEIGHT / 2), int(HEIGHT / 2) - 4)
82+
83+
display.set_pen(GREY)
84+
85+
for a in range(60):
86+
t.rotate(360 / 60.0 * a, MIDDLE)
87+
t.translate(0, 2)
88+
vector.draw(tick_mark)
89+
t.reset()
90+
91+
for a in range(12):
92+
t.rotate(360 / 12.0 * a, MIDDLE)
93+
t.translate(0, 2)
94+
vector.draw(hour_mark)
95+
t.reset()
96+
97+
display.set_pen(GREY)
98+
99+
x, y = MIDDLE
100+
y += 5
101+
102+
angle_minute = minute * 6
103+
angle_minute += second / 10.0
104+
t.rotate(angle_minute, MIDDLE)
105+
t.translate(x, y)
106+
vector.draw(minute_hand)
107+
t.reset()
108+
109+
angle_hour = (hour % 12) * 30
110+
angle_hour += minute / 2
111+
t.rotate(angle_hour, MIDDLE)
112+
t.translate(x, y)
113+
vector.draw(hour_hand)
114+
t.reset()
115+
116+
angle_second = second * 6
117+
t.rotate(angle_second, MIDDLE)
118+
t.translate(x, y)
119+
vector.draw(second_hand)
120+
t.reset()
121+
122+
display.set_pen(BLACK)
123+
124+
for a in range(60):
125+
t.rotate(360 / 60.0 * a, MIDDLE)
126+
vector.draw(tick_mark)
127+
t.reset()
128+
129+
for a in range(12):
130+
t.rotate(360 / 12.0 * a, MIDDLE)
131+
vector.draw(hour_mark)
132+
t.reset()
133+
134+
x, y = MIDDLE
135+
136+
t.rotate(angle_minute, MIDDLE)
137+
t.translate(x, y)
138+
vector.draw(minute_hand)
139+
t.reset()
140+
141+
t.rotate(angle_hour, MIDDLE)
142+
t.translate(x, y)
143+
vector.draw(hour_hand)
144+
t.reset()
145+
146+
display.set_pen(RED)
147+
t.rotate(angle_second, MIDDLE)
148+
t.translate(x, y)
149+
vector.draw(second_hand)
150+
151+
t.reset()
152+
vector.draw(hub)
153+
154+
i75.update()
155+
gc.collect()
156+
157+
t_end = time.ticks_ms()
158+
print(f"Took {t_end - t_start}ms")

0 commit comments

Comments
 (0)