-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (32 loc) · 1.1 KB
/
Copy pathmain.py
File metadata and controls
44 lines (32 loc) · 1.1 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
"""Application entry point for the PyDevices PyScript template.
Interactive touch/paint demo built on the PyDevices Board Contract
(``board_config`` and ``appdev.App``). Edit this file to make the app yours.
"""
import board_config
import appdev
from pyscript import document
display_drv = board_config.display_drv
app = appdev.App(board_config)
colors = [0xFFFF, 0xF800, 0x07E0, 0x001F, 0x07FF, 0xF81F, 0xFFE0, 0x0000]
block_size = display_drv.width // len(colors)
selected = 0
def draw_palette():
for i, color in enumerate(colors):
x = i * block_size
display_drv.fill_rect(x, 0, block_size, 30, color)
display_drv.show()
draw_palette()
document.querySelector("#status").textContent = (
"Running displaydev in Pyodide. Click the canvas to paint."
)
def on_touch(event):
global selected
x, y = event.pos
if y < 30:
selected = min(len(colors) - 1, x // block_size)
else:
display_drv.fill_rect(x - 3, y - 3, 6, 6, colors[selected])
display_drv.show()
app.on(app.events.MOUSEBUTTONDOWN, on_touch)
app.on(app.events.MOUSEMOTION, on_touch)
app.run()