Skip to content

Commit 788f6c3

Browse files
committed
PicoVector: Add clock example for PicoW Explorer.
1 parent 231ceb7 commit 788f6c3

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import time
2+
import gc
3+
4+
from picographics import PicoGraphics, DISPLAY_PICO_W_EXPLORER, PEN_RGB332
5+
from picovector import PicoVector, Polygon, RegularPolygon, Rectangle, ANTIALIAS_X4
6+
7+
8+
display = PicoGraphics(DISPLAY_PICO_W_EXPLORER, pen_type=PEN_RGB332)
9+
10+
vector = PicoVector(display)
11+
vector.set_antialiasing(ANTIALIAS_X4)
12+
13+
RED = display.create_pen(200, 0, 0)
14+
BLACK = display.create_pen(0, 0, 0)
15+
GREY = display.create_pen(200, 200, 200)
16+
WHITE = display.create_pen(255, 255, 255)
17+
18+
"""
19+
# Redefine colours for a Blue clock
20+
RED = display.create_pen(200, 0, 0)
21+
BLACK = display.create_pen(135, 159, 169)
22+
GREY = display.create_pen(10, 40, 50)
23+
WHITE = display.create_pen(14, 60, 76)
24+
"""
25+
26+
WIDTH, HEIGHT = display.get_bounds()
27+
28+
hub = RegularPolygon(int(WIDTH / 2), int(HEIGHT / 2), 24, 5)
29+
30+
face = RegularPolygon(int(WIDTH / 2), int(HEIGHT / 2), 48, int(HEIGHT / 2))
31+
32+
print(time.localtime())
33+
34+
last_second = None
35+
36+
while True:
37+
t_start = time.ticks_ms()
38+
year, month, day, hour, minute, second, _, _ = time.localtime()
39+
40+
if last_second == second:
41+
continue
42+
43+
last_second = second
44+
45+
display.set_pen(0)
46+
display.clear()
47+
48+
display.set_pen(BLACK)
49+
display.circle(int(WIDTH / 2), int(HEIGHT / 2), int(HEIGHT / 2))
50+
display.set_pen(WHITE)
51+
display.circle(int(WIDTH / 2), int(HEIGHT / 2), int(HEIGHT / 2) - 4)
52+
53+
display.set_pen(GREY)
54+
55+
for a in range(60):
56+
tick_mark = Rectangle(int(WIDTH / 2) - 3, 10, 6, int(HEIGHT / 48))
57+
vector.rotate(tick_mark, 360 / 60.0 * a, int(WIDTH / 2), int(HEIGHT / 2))
58+
vector.translate(tick_mark, 0, 2)
59+
vector.draw(tick_mark)
60+
61+
for a in range(12):
62+
hour_mark = Rectangle(int(WIDTH / 2) - 5, 10, 10, int(HEIGHT / 10))
63+
vector.rotate(hour_mark, 360 / 12.0 * a, int(WIDTH / 2), int(HEIGHT / 2))
64+
vector.translate(hour_mark, 0, 2)
65+
vector.draw(hour_mark)
66+
67+
angle_second = second * 6
68+
second_hand_length = int(HEIGHT / 2) - int(HEIGHT / 8)
69+
second_hand = Polygon((-2, -second_hand_length), (-2, int(HEIGHT / 8)), (2, int(HEIGHT / 8)), (2, -second_hand_length))
70+
vector.rotate(second_hand, angle_second, 0, 0)
71+
vector.translate(second_hand, int(WIDTH / 2), int(HEIGHT / 2) + 5)
72+
73+
angle_minute = minute * 6
74+
angle_minute += second / 10.0
75+
minute_hand_length = int(HEIGHT / 2) - int(HEIGHT / 24)
76+
minute_hand = Polygon((-5, -minute_hand_length), (-10, int(HEIGHT / 16)), (10, int(HEIGHT / 16)), (5, -minute_hand_length))
77+
vector.rotate(minute_hand, angle_minute, 0, 0)
78+
vector.translate(minute_hand, int(WIDTH / 2), int(HEIGHT / 2) + 5)
79+
80+
angle_hour = (hour % 12) * 30
81+
angle_hour += minute / 2
82+
hour_hand_length = int(HEIGHT / 2) - int(HEIGHT / 8)
83+
hour_hand = Polygon((-5, -hour_hand_length), (-10, int(HEIGHT / 16)), (10, int(HEIGHT / 16)), (5, -hour_hand_length))
84+
vector.rotate(hour_hand, angle_hour, 0, 0)
85+
vector.translate(hour_hand, int(WIDTH / 2), int(HEIGHT / 2) + 5)
86+
87+
display.set_pen(GREY)
88+
89+
vector.draw(minute_hand)
90+
vector.draw(hour_hand)
91+
vector.draw(second_hand)
92+
93+
display.set_pen(BLACK)
94+
95+
for a in range(60):
96+
tick_mark = Rectangle(int(WIDTH / 2) - 3, 10, 6, int(HEIGHT / 48))
97+
vector.rotate(tick_mark, 360 / 60.0 * a, int(WIDTH / 2), int(HEIGHT / 2))
98+
vector.draw(tick_mark)
99+
100+
for a in range(12):
101+
hour_mark = Rectangle(int(WIDTH / 2) - 5, 10, 10, int(HEIGHT / 10))
102+
vector.rotate(hour_mark, 360 / 12.0 * a, int(WIDTH / 2), int(HEIGHT / 2))
103+
vector.draw(hour_mark)
104+
105+
vector.translate(minute_hand, 0, -5)
106+
vector.translate(hour_hand, 0, -5)
107+
vector.draw(minute_hand)
108+
vector.draw(hour_hand)
109+
110+
display.set_pen(RED)
111+
vector.translate(second_hand, 0, -5)
112+
vector.draw(second_hand)
113+
vector.draw(hub)
114+
115+
display.update()
116+
gc.collect()
117+
118+
t_end = time.ticks_ms()
119+
print(f"Took {t_end - t_start}ms")

0 commit comments

Comments
 (0)