Skip to content

Commit 5b78ae1

Browse files
committed
stop_watch.py: visual changes
1 parent c8ffa11 commit 5b78ae1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

examples/stop_watch.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
CY = HEIGHT // 2
1818

1919
# Couple of colours for use later
20-
WHITE = display.create_pen(255, 255, 255)
21-
RED = display.create_pen(230, 60, 45)
22-
GREEN = display.create_pen(9, 185, 120)
2320
BLACK = display.create_pen(0, 0, 0)
21+
hue = 0.09
22+
background = display.create_pen_hsv(hue, 0.8, 1.0)
23+
foreground = display.create_pen_hsv(hue, 0.5, 1.0)
24+
text_colour = display.create_pen_hsv(hue, 0.2, 1.0)
2425

2526
# We'll need this for the touch element of the screen
2627
touch = presto.touch
@@ -36,17 +37,21 @@
3637
vector.set_transform(t)
3738

3839
# Touch buttons
39-
start_button = Button(1, HEIGHT - 50, CX - 2, 49)
40-
stop_button = Button(WIDTH - CX, HEIGHT - 50, CX - 2, 49)
40+
start_button = Button(3, HEIGHT - 55, CX - 5, 49)
41+
stop_button = Button((WIDTH - CX) + 1, HEIGHT - 55, CX - 5, 49)
4142

4243
start = Polygon()
43-
start.rectangle(*start_button.bounds, (5, 5, 5, 5))
44+
start.rectangle(*start_button.bounds, (10, 10, 10, 10))
4445

4546
stop = Polygon()
46-
stop.rectangle(*stop_button.bounds, (5, 5, 5, 5))
47+
stop.rectangle(*stop_button.bounds, (10, 10, 10, 10))
4748

4849
outline = Polygon()
49-
outline.rectangle(5, 20, WIDTH - 10, HEIGHT - 100, (5, 5, 5, 5), 2)
50+
outline.rectangle(5, 20, WIDTH - 10, HEIGHT - 100, (10, 10, 10, 10), 2)
51+
52+
# We'll use a rect with rounded corners for the background.
53+
background_rect = Polygon()
54+
background_rect.rectangle(0, 0, WIDTH, HEIGHT, (10, 10, 10, 10))
5055

5156

5257
class StopWatch(object):
@@ -87,28 +92,31 @@ def return_string(self):
8792

8893
while True:
8994

90-
display.set_pen(WHITE)
95+
display.set_pen(BLACK)
9196
display.clear()
9297

93-
display.set_pen(GREEN)
98+
display.set_pen(background)
99+
vector.draw(background_rect)
100+
101+
display.set_pen(foreground)
94102
vector.draw(start)
95103

96-
display.set_pen(RED)
104+
display.set_pen(foreground)
97105
vector.draw(stop)
98106

99-
display.set_pen(BLACK)
107+
display.set_pen(text_colour)
100108
vector.draw(outline)
101109

102110
vector.set_font_size(32)
103111
if timer.elapsed and timer.running is False:
104-
vector.text("Resume", start_button.bounds[0] + 10, start_button.bounds[1] + 33)
112+
vector.text("Resume", start_button.bounds[0] + 8, start_button.bounds[1] + 33)
105113
else:
106114
vector.text("Start", start_button.bounds[0] + 27, start_button.bounds[1] + 33)
107115

108116
if timer.running:
109117
vector.text("Stop", stop_button.bounds[0] + 30, stop_button.bounds[1] + 33)
110118
else:
111-
vector.text("Reset", stop_button.bounds[0] + 25, stop_button.bounds[1] + 33)
119+
vector.text("Reset", stop_button.bounds[0] + 23, stop_button.bounds[1] + 33)
112120

113121
if start_button.is_pressed() and timer.running is False:
114122
timer.start()

0 commit comments

Comments
 (0)