-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtouchscreen_dots.py
More file actions
72 lines (55 loc) · 1.95 KB
/
touchscreen_dots.py
File metadata and controls
72 lines (55 loc) · 1.95 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
import time
from random import randint
from presto import Presto
# Setup for the Presto display
presto = Presto(ambient_light=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
# Couple of colours for use later
BLUE = display.create_pen(28, 181, 202)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(230, 60, 45)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(9, 185, 120)
PINK = display.create_pen(250, 125, 180)
PURPLE = display.create_pen(118, 95, 210)
BLACK = display.create_pen(0, 0, 0)
COLOURS = [BLUE, RED, ORANGE, GREEN, PINK, PURPLE]
# We'll need this for the touch element of the screen
touch = presto.touch
class DOT(object):
def __init__(self, x, y, size, colour):
self.x = x
self.y = y
self.size = size
self.colour = colour
# We'll store any dots in this array
dots = []
while True:
# Poll the touch so we can see if anything changed since the last time
touch.poll()
# If the user is touching the screen we'll do the following
if touch.state:
# set the base size to 10 for a single tap
s = 10
# While the user is still touching the screen, we'll make the dot bigger!
while touch.state:
touch.poll()
time.sleep(0.02)
s += 0.5
# Once the user stops touching the screen
# We'll add a new dot with the x and y position of the touch,
# size and a random colour!
dots.append(DOT(touch.x, touch.y, round(s), COLOURS[randint(0, len(COLOURS) - 1)]))
# Clear the screen
display.set_pen(WHITE)
display.clear()
# Draw the dots in our array
for dot in dots:
display.set_pen(dot.colour)
display.circle(dot.x, dot.y, dot.size)
# Some text to let the user know what to do!
display.set_pen(BLACK)
display.text("Tap the screen!", 45, 110, WIDTH, 2)
# Finally we update the screen with our changes :)
presto.update()