omnipython-apps 0.1.4.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/bit_world/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "bit_world", "title": "Bit World", "category": "Desk", "icon": "sports_esports", "color": "#106C80", "script": "bit_world"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Where Bit World's music plays: the sound outputs, listed and picked from the script.
|
|
6
|
+
|
|
7
|
+
Needs: boarddev; endpointkit and appkit to list and pick, without which the
|
|
8
|
+
music plays through the board's audio out as always.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from boarddev import env_get
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def pick_audio_out():
|
|
15
|
+
"""Print the sound outputs, choose the one ``BIT_WORLD_AUDIO`` names, and
|
|
16
|
+
return the device to open: None for the default.
|
|
17
|
+
|
|
18
|
+
A word of the output's name is enough (``BIT_WORLD_AUDIO=USB``). Without
|
|
19
|
+
it the music plays where the device's choice is, from the connections
|
|
20
|
+
picker or an earlier script. A script picks the same way::
|
|
21
|
+
|
|
22
|
+
import endpointkit
|
|
23
|
+
from appkit import connections
|
|
24
|
+
|
|
25
|
+
connections.register()
|
|
26
|
+
for ep in endpointkit.endpoints("audio.out"):
|
|
27
|
+
print(ep.id, ep.label)
|
|
28
|
+
endpointkit.select("audio.out", ep.id)
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
import endpointkit
|
|
32
|
+
from appkit import connections
|
|
33
|
+
except ImportError: # no endpointkit: the board's audio out, as always
|
|
34
|
+
return None
|
|
35
|
+
connections.register()
|
|
36
|
+
want = env_get("BIT_WORLD_AUDIO")
|
|
37
|
+
for ep in endpointkit.endpoints("audio.out"):
|
|
38
|
+
print("Bit World: audio out %r (%s)" % (ep.label, ep.id))
|
|
39
|
+
if want and want.lower() in ep.label.lower():
|
|
40
|
+
endpointkit.select("audio.out", ep.id)
|
|
41
|
+
want = None
|
|
42
|
+
chosen = endpointkit.selected("audio.out")
|
|
43
|
+
if chosen:
|
|
44
|
+
print("Bit World: playing to %r" % chosen[0].label)
|
|
45
|
+
return connections.device(chosen)
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Provide the color palette, layout scaler, and math helpers for Bit World.
|
|
6
|
+
|
|
7
|
+
Declares the 32-color Cozy Sci-Fi and Solarpunk palette for the palettes
|
|
8
|
+
library, with portable random number and integer trigonometry helpers, a responsive layout scaler for
|
|
9
|
+
landscape screens from 480x320 to 800x480, and dithered transition routines.
|
|
10
|
+
|
|
11
|
+
Needs: palettes, pygraphics.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from array import array
|
|
15
|
+
from random import getrandbits, seed
|
|
16
|
+
from palettes import Palette
|
|
17
|
+
from pygraphics import RGB565, Draw, FrameBuffer
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
import framebuf
|
|
21
|
+
except ImportError: # CPython and CircuitPython: pygraphics draws everything
|
|
22
|
+
framebuf = None
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from offheap import Buffer as OffHeapBuffer
|
|
26
|
+
except ImportError: # CPython, CircuitPython and firmware without offheap
|
|
27
|
+
OffHeapBuffer = None
|
|
28
|
+
|
|
29
|
+
# Change these to match your setup.
|
|
30
|
+
REF_WIDTH = 800 # Reference landscape design width in pixels
|
|
31
|
+
REF_HEIGHT = 480 # Reference landscape design height in pixels
|
|
32
|
+
KEY = 0x0020 # Transparent color key; rgb565() shifts any matching color by +1
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class BitPalette(Palette):
|
|
36
|
+
"""Bit World's 32 hand-tuned colors, each under the name the art code uses.
|
|
37
|
+
|
|
38
|
+
The palettes library turns each ``(0xRRGGBB, name)`` pair into an RGB565
|
|
39
|
+
attribute named in capitals (``BitPalette().DEEP_SLATE``).
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
_names = (
|
|
43
|
+
# Deep space, chassis shadow, and metallic slate tones.
|
|
44
|
+
(0x060812, "Void"),
|
|
45
|
+
(0x0B1022, "Abyss"),
|
|
46
|
+
(0x121A34, "Night"),
|
|
47
|
+
(0x1C2848, "Deep Slate"),
|
|
48
|
+
(0x2E4068, "Slate"),
|
|
49
|
+
(0x4E6694, "Steel"),
|
|
50
|
+
(0x84A0CC, "Mist"),
|
|
51
|
+
(0xC0D4EE, "Silver"),
|
|
52
|
+
# Maker-lab warm brass, copper, amber, gold, and cream highlights.
|
|
53
|
+
(0x201410, "Dark Wood"),
|
|
54
|
+
(0x3A241A, "Oak"),
|
|
55
|
+
(0x623C20, "Bronze"),
|
|
56
|
+
(0x9C582A, "Copper"),
|
|
57
|
+
(0xE0882C, "Amber"),
|
|
58
|
+
(0xFAC040, "Gold"),
|
|
59
|
+
(0xFFEA78, "Sun Yellow"),
|
|
60
|
+
(0xF8F2E0, "Cream"),
|
|
61
|
+
(0xFFFFFF, "White"),
|
|
62
|
+
# Bioluminescent cyan and hologram teal tones.
|
|
63
|
+
(0x083444, "Deep Teal"),
|
|
64
|
+
(0x106C80, "Teal"),
|
|
65
|
+
(0x20B8D4, "Cyan"),
|
|
66
|
+
(0x5CEEF8, "Aqua Glow"),
|
|
67
|
+
(0xBCFCFF, "Ice Cyan"),
|
|
68
|
+
# Solarpunk flora and mossy ruin greens.
|
|
69
|
+
(0x0E3024, "Dark Moss"),
|
|
70
|
+
(0x185838, "Forest"),
|
|
71
|
+
(0x308E4E, "Moss"),
|
|
72
|
+
(0x54CC6C, "Emerald"),
|
|
73
|
+
(0x9EF484, "Lime Glow"),
|
|
74
|
+
# Plasma, crystal, and sunset accent colors.
|
|
75
|
+
(0x301444, "Plum"),
|
|
76
|
+
(0x683094, "Violet"),
|
|
77
|
+
(0xBC40B0, "Magenta"),
|
|
78
|
+
(0xF86CC6, "Neon Pink"),
|
|
79
|
+
(0xC42A44, "Crimson"),
|
|
80
|
+
(0xF86054, "Coral"),
|
|
81
|
+
(0xFC8E38, "Orange"),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def __init__(self):
|
|
85
|
+
super().__init__("bit_world", 16)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
PALETTE = BitPalette()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Move a color that equals the transparent key off it by one step.
|
|
92
|
+
def keyed(c):
|
|
93
|
+
return c + 1 if c == KEY else c
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Convert 8-bit red, green, and blue channels into a 16-bit RGB565 integer.
|
|
97
|
+
def rgb565(r, g, b):
|
|
98
|
+
return keyed(PALETTE.color565(int(r), int(g), int(b)))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Interpolate linearly between two RGB tuples and return an RGB565 color.
|
|
102
|
+
def lerp565(rgb_a, rgb_b, t):
|
|
103
|
+
if t <= 0.0:
|
|
104
|
+
return rgb565(rgb_a[0], rgb_a[1], rgb_a[2])
|
|
105
|
+
if t >= 1.0:
|
|
106
|
+
return rgb565(rgb_b[0], rgb_b[1], rgb_b[2])
|
|
107
|
+
r = rgb_a[0] + (rgb_b[0] - rgb_a[0]) * t
|
|
108
|
+
g = rgb_a[1] + (rgb_b[1] - rgb_a[1]) * t
|
|
109
|
+
b = rgb_a[2] + (rgb_b[2] - rgb_a[2]) * t
|
|
110
|
+
return rgb565(r, g, b)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# Look up a palette color's red, green, and blue channels by its name.
|
|
114
|
+
def rgb_of(name):
|
|
115
|
+
for value, entry in BitPalette._names:
|
|
116
|
+
if entry == name:
|
|
117
|
+
return (value >> 16, value >> 8 & 0xFF, value & 0xFF)
|
|
118
|
+
raise KeyError(name)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# The gradients blend between these, so they need the channels, not RGB565.
|
|
122
|
+
VOID_RGB = rgb_of("Void")
|
|
123
|
+
ABYSS_RGB = rgb_of("Abyss")
|
|
124
|
+
NIGHT_RGB = rgb_of("Night")
|
|
125
|
+
DEEP_SLATE_RGB = rgb_of("Deep Slate")
|
|
126
|
+
SLATE_RGB = rgb_of("Slate")
|
|
127
|
+
STEEL_RGB = rgb_of("Steel")
|
|
128
|
+
MIST_RGB = rgb_of("Mist")
|
|
129
|
+
SILVER_RGB = rgb_of("Silver")
|
|
130
|
+
|
|
131
|
+
# Each color as RGB565, from the palette.
|
|
132
|
+
VOID = keyed(PALETTE.VOID)
|
|
133
|
+
ABYSS = keyed(PALETTE.ABYSS)
|
|
134
|
+
NIGHT = keyed(PALETTE.NIGHT)
|
|
135
|
+
DEEP_SLATE = keyed(PALETTE.DEEP_SLATE)
|
|
136
|
+
SLATE = keyed(PALETTE.SLATE)
|
|
137
|
+
STEEL = keyed(PALETTE.STEEL)
|
|
138
|
+
MIST = keyed(PALETTE.MIST)
|
|
139
|
+
SILVER = keyed(PALETTE.SILVER)
|
|
140
|
+
DARK_WOOD = keyed(PALETTE.DARK_WOOD)
|
|
141
|
+
OAK = keyed(PALETTE.OAK)
|
|
142
|
+
BRONZE = keyed(PALETTE.BRONZE)
|
|
143
|
+
COPPER = keyed(PALETTE.COPPER)
|
|
144
|
+
AMBER = keyed(PALETTE.AMBER)
|
|
145
|
+
GOLD = keyed(PALETTE.GOLD)
|
|
146
|
+
SUN_YELLOW = keyed(PALETTE.SUN_YELLOW)
|
|
147
|
+
CREAM = keyed(PALETTE.CREAM)
|
|
148
|
+
WHITE = keyed(PALETTE.WHITE)
|
|
149
|
+
DEEP_TEAL = keyed(PALETTE.DEEP_TEAL)
|
|
150
|
+
TEAL = keyed(PALETTE.TEAL)
|
|
151
|
+
CYAN = keyed(PALETTE.CYAN)
|
|
152
|
+
AQUA_GLOW = keyed(PALETTE.AQUA_GLOW)
|
|
153
|
+
ICE_CYAN = keyed(PALETTE.ICE_CYAN)
|
|
154
|
+
DARK_MOSS = keyed(PALETTE.DARK_MOSS)
|
|
155
|
+
FOREST = keyed(PALETTE.FOREST)
|
|
156
|
+
MOSS = keyed(PALETTE.MOSS)
|
|
157
|
+
EMERALD = keyed(PALETTE.EMERALD)
|
|
158
|
+
LIME_GLOW = keyed(PALETTE.LIME_GLOW)
|
|
159
|
+
PLUM = keyed(PALETTE.PLUM)
|
|
160
|
+
VIOLET = keyed(PALETTE.VIOLET)
|
|
161
|
+
MAGENTA = keyed(PALETTE.MAGENTA)
|
|
162
|
+
NEON_PINK = keyed(PALETTE.NEON_PINK)
|
|
163
|
+
CRIMSON = keyed(PALETTE.CRIMSON)
|
|
164
|
+
CORAL = keyed(PALETTE.CORAL)
|
|
165
|
+
ORANGE = keyed(PALETTE.ORANGE)
|
|
166
|
+
|
|
167
|
+
# Flat 75-entry uint16 lookup table mapping byte (b - 46) for '.'..'x' to RGB565.
|
|
168
|
+
PALETTE_LUT = array(
|
|
169
|
+
"H",
|
|
170
|
+
(
|
|
171
|
+
KEY, KEY, # '.' (46), '/' (47)
|
|
172
|
+
VOID, ABYSS, NIGHT, DEEP_SLATE, SLATE, STEEL, MIST, SILVER, WHITE, CREAM, # '0'..'9'
|
|
173
|
+
KEY, KEY, KEY, KEY, KEY, KEY, KEY, # ':'..'@'
|
|
174
|
+
KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, # 'A'..'M'
|
|
175
|
+
KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, KEY, # 'N'..'Z'
|
|
176
|
+
KEY, KEY, KEY, KEY, KEY, KEY, # '['..'`'
|
|
177
|
+
DARK_WOOD, OAK, BRONZE, COPPER, AMBER, GOLD, SUN_YELLOW, # 'a'..'g'
|
|
178
|
+
DEEP_TEAL, TEAL, CYAN, AQUA_GLOW, ICE_CYAN, # 'h'..'l'
|
|
179
|
+
DARK_MOSS, FOREST, MOSS, EMERALD, LIME_GLOW, # 'm'..'q'
|
|
180
|
+
PLUM, VIOLET, MAGENTA, NEON_PINK, CRIMSON, CORAL, ORANGE, # 'r'..'x'
|
|
181
|
+
),
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
# Precomputed 256-entry sine table (-1024..1024) as a single constant buffer.
|
|
185
|
+
SIN256 = array(
|
|
186
|
+
"h",
|
|
187
|
+
b"\x00\x00\x19\x00\x32\x00\x4b\x00\x64\x00\x7d\x00\x96\x00\xaf\x00\xc7\x00\xe0\x00\xf8\x00\x11\x01\x29\x01\x41\x01\x58\x01\x70\x01\x87\x01\x9e\x01\xb5\x01\xcc\x01\xe2\x01\xf8\x01\x0e\x02\x23\x02\x38\x02\x4d\x02\x61\x02\x75\x02\x89\x02\x9c\x02\xaf\x02\xc2\x02"
|
|
188
|
+
b"\xd4\x02\xe5\x02\xf6\x02\x07\x03\x17\x03\x27\x03\x36\x03\x45\x03\x53\x03\x61\x03\x6e\x03\x7a\x03\x87\x03\x92\x03\x9d\x03\xa8\x03\xb2\x03\xbb\x03\xc4\x03\xcc\x03\xd3\x03\xda\x03\xe1\x03\xe7\x03\xec\x03\xf0\x03\xf4\x03\xf8\x03\xfb\x03\xfd\x03\xfe\x03\xff\x03"
|
|
189
|
+
b"\x00\x04\xff\x03\xfe\x03\xfd\x03\xfb\x03\xf8\x03\xf4\x03\xf0\x03\xec\x03\xe7\x03\xe1\x03\xda\x03\xd3\x03\xcc\x03\xc4\x03\xbb\x03\xb2\x03\xa8\x03\x9d\x03\x92\x03\x87\x03\x7a\x03\x6e\x03\x61\x03\x53\x03\x45\x03\x36\x03\x27\x03\x17\x03\x07\x03\xf6\x02\xe5\x02"
|
|
190
|
+
b"\xd4\x02\xc2\x02\xaf\x02\x9c\x02\x89\x02\x75\x02\x61\x02\x4d\x02\x38\x02\x23\x02\x0e\x02\xf8\x01\xe2\x01\xcc\x01\xb5\x01\x9e\x01\x87\x01\x70\x01\x58\x01\x41\x01\x29\x01\x11\x01\xf8\x00\xe0\x00\xc7\x00\xaf\x00\x96\x00\x7d\x00\x64\x00\x4b\x00\x32\x00\x19\x00"
|
|
191
|
+
b"\x00\x00\xe7\xff\xce\xff\xb5\xff\x9c\xff\x83\xff\x6a\xff\x51\xff\x39\xff\x20\xff\x08\xff\xef\xfe\xd7\xfe\xbf\xfe\xa8\xfe\x90\xfe\x79\xfe\x62\xfe\x4b\xfe\x34\xfe\x1e\xfe\x08\xfe\xf2\xfd\xdd\xfd\xc8\xfd\xb3\xfd\x9f\xfd\x8b\xfd\x77\xfd\x64\xfd\x51\xfd\x3e\xfd"
|
|
192
|
+
b"\x2c\xfd\x1b\xfd\x0a\xfd\xf9\xfc\xe9\xfc\xd9\xfc\xca\xfc\xbb\xfc\xad\xfc\x9f\xfc\x92\xfc\x86\xfc\x79\xfc\x6e\xfc\x63\xfc\x58\xfc\x4e\xfc\x45\xfc\x3c\xfc\x34\xfc\x2d\xfc\x26\xfc\x1f\xfc\x19\xfc\x14\xfc\x10\xfc\x0c\xfc\x08\xfc\x05\xfc\x03\xfc\x02\xfc\x01\xfc"
|
|
193
|
+
b"\x00\xfc\x01\xfc\x02\xfc\x03\xfc\x05\xfc\x08\xfc\x0c\xfc\x10\xfc\x14\xfc\x19\xfc\x1f\xfc\x26\xfc\x2d\xfc\x34\xfc\x3c\xfc\x45\xfc\x4e\xfc\x58\xfc\x63\xfc\x6e\xfc\x79\xfc\x86\xfc\x92\xfc\x9f\xfc\xad\xfc\xbb\xfc\xca\xfc\xd9\xfc\xe9\xfc\xf9\xfc\x0a\xfd\x1b\xfd"
|
|
194
|
+
b"\x2c\xfd\x3e\xfd\x51\xfd\x64\xfd\x77\xfd\x8b\xfd\x9f\xfd\xb3\xfd\xc8\xfd\xdd\xfd\xf2\xfd\x08\xfe\x1e\xfe\x34\xfe\x4b\xfe\x62\xfe\x79\xfe\x90\xfe\xa8\xfe\xbf\xfe\xd7\xfe\xef\xfe\x08\xff\x20\xff\x39\xff\x51\xff\x6a\xff\x83\xff\x9c\xff\xb5\xff\xce\xff\xe7\xff",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
# Look up the fast integer sine (-1024..1024) for a 0..255 phase index.
|
|
199
|
+
def isin(idx):
|
|
200
|
+
return SIN256[idx & 0xFF]
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# Look up the fast integer cosine (-1024..1024) for a 0..255 phase index.
|
|
204
|
+
def icos(idx):
|
|
205
|
+
return SIN256[(idx + 64) & 0xFF]
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# Generate a random integer in [lo, hi] using only getrandbits for port safety.
|
|
209
|
+
def rng_int(lo, hi):
|
|
210
|
+
span = hi - lo + 1
|
|
211
|
+
if span <= 1:
|
|
212
|
+
return lo
|
|
213
|
+
bits = 0
|
|
214
|
+
n = span - 1
|
|
215
|
+
while n:
|
|
216
|
+
bits += 1
|
|
217
|
+
n >>= 1
|
|
218
|
+
return lo + (getrandbits(bits) % span)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# Seed the random number generator deterministically if supported.
|
|
222
|
+
def init_rng(val=42):
|
|
223
|
+
try:
|
|
224
|
+
seed(val)
|
|
225
|
+
except Exception:
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class Layout:
|
|
230
|
+
"""Scale coordinates and pixel-art metrics from 480x320 up to 800x480."""
|
|
231
|
+
|
|
232
|
+
def __init__(self, width, height):
|
|
233
|
+
self.w = width
|
|
234
|
+
self.h = height
|
|
235
|
+
self.sw = width / REF_WIDTH
|
|
236
|
+
self.sh = height / REF_HEIGHT
|
|
237
|
+
self.s = min(self.sw, self.sh)
|
|
238
|
+
self.compact = width < 600 or height < 380
|
|
239
|
+
# Choose an integer pixel-art magnification factor (2x on 480x320, 3x on 800x480).
|
|
240
|
+
self.px = 2 if self.compact else 3
|
|
241
|
+
self.tile_px = 2 if self.compact else 3
|
|
242
|
+
self.bar_h = 28 if self.compact else 36
|
|
243
|
+
self.scene_y = self.bar_h
|
|
244
|
+
self.scene_h = height - self.bar_h
|
|
245
|
+
self.pad = 6 if self.compact else 10
|
|
246
|
+
|
|
247
|
+
# Scale a horizontal coordinate from the 800-wide reference design.
|
|
248
|
+
def x(self, val):
|
|
249
|
+
return int(val * self.sw)
|
|
250
|
+
|
|
251
|
+
# Scale a vertical coordinate inside the full screen height.
|
|
252
|
+
def y(self, val):
|
|
253
|
+
return int(val * self.sh)
|
|
254
|
+
|
|
255
|
+
# Scale a vertical coordinate inside the scene area below the stage bar.
|
|
256
|
+
def sy(self, frac):
|
|
257
|
+
return self.scene_y + int(frac * self.scene_h)
|
|
258
|
+
|
|
259
|
+
# Scale a dimension uniformly using the smaller axis ratio.
|
|
260
|
+
def u(self, val):
|
|
261
|
+
return max(1, int(val * self.s))
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
# Paint a vertical RGB565 gradient into a FrameBuffer over the given rectangle.
|
|
265
|
+
def paint_gradient(fb, x, y, w, h, rgb_top, rgb_bot, step=2):
|
|
266
|
+
if w <= 0 or h <= 0:
|
|
267
|
+
return
|
|
268
|
+
denom = max(1, h - 1)
|
|
269
|
+
r0, g0, b0 = rgb_top
|
|
270
|
+
dr = rgb_bot[0] - r0
|
|
271
|
+
dg = rgb_bot[1] - g0
|
|
272
|
+
db = rgb_bot[2] - b0
|
|
273
|
+
s = max(1, step)
|
|
274
|
+
for row in range(0, h, s):
|
|
275
|
+
t = row / denom
|
|
276
|
+
c = rgb565(r0 + dr * t, g0 + dg * t, b0 + db * t)
|
|
277
|
+
bh = s if row + s <= h else h - row
|
|
278
|
+
fb.fill_rect(x, y + row, w, bh, c)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
# Draw a stylized pixel-art beveled panel with a corner highlight and border.
|
|
282
|
+
def draw_pixel_panel(fb, x, y, w, h, bg_col, border_col, hi_col=None, shadow_col=None):
|
|
283
|
+
if w < 6 or h < 6:
|
|
284
|
+
return
|
|
285
|
+
if shadow_col is not None:
|
|
286
|
+
fb.fill_rect(x + 3, y + 3, w, h, shadow_col)
|
|
287
|
+
fb.fill_rect(x + 2, y + 2, w - 4, h - 4, bg_col)
|
|
288
|
+
fb.hline(x + 2, y, w - 4, border_col)
|
|
289
|
+
fb.hline(x + 2, y + h - 1, w - 4, border_col)
|
|
290
|
+
fb.vline(x, y + 2, h - 4, border_col)
|
|
291
|
+
fb.vline(x + w - 1, y + 2, h - 4, border_col)
|
|
292
|
+
fb.pixel(x + 1, y + 1, border_col)
|
|
293
|
+
fb.pixel(x + w - 2, y + 1, border_col)
|
|
294
|
+
fb.pixel(x + 1, y + h - 2, border_col)
|
|
295
|
+
fb.pixel(x + w - 2, y + h - 2, border_col)
|
|
296
|
+
if hi_col is not None and w > 8:
|
|
297
|
+
fb.hline(x + 3, y + 1, w - 6, hi_col)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
# Draw a Bayer-inspired pixel curtain wipe across the scene during act transitions.
|
|
301
|
+
def draw_pixel_wipe(fb, x, y, w, h, progress, col_main=VOID, col_edge=CYAN):
|
|
302
|
+
# Progress runs 0.0 -> 0.5 (closing) and 0.5 -> 1.0 (opening).
|
|
303
|
+
if progress <= 0.0 or progress >= 1.0:
|
|
304
|
+
return
|
|
305
|
+
coverage = 1.0 - abs(progress * 2.0 - 1.0)
|
|
306
|
+
cell = 16
|
|
307
|
+
cols = (w + cell - 1) // cell
|
|
308
|
+
for cx in range(cols):
|
|
309
|
+
# Stagger columns slightly so the wipe sweeps left-to-right like a pixel wave.
|
|
310
|
+
local = coverage * 1.25 - (cx / max(1, cols)) * 0.25
|
|
311
|
+
if local <= 0.0:
|
|
312
|
+
continue
|
|
313
|
+
if local >= 1.0:
|
|
314
|
+
fb.fill_rect(x + cx * cell, y, min(cell, w - cx * cell), h, col_main)
|
|
315
|
+
continue
|
|
316
|
+
fill_h = int(h * local)
|
|
317
|
+
bx = x + cx * cell
|
|
318
|
+
bw = min(cell, w - cx * cell)
|
|
319
|
+
if progress < 0.5:
|
|
320
|
+
fb.fill_rect(bx, y, bw, fill_h, col_main)
|
|
321
|
+
if fill_h + 3 <= h:
|
|
322
|
+
fb.fill_rect(bx, y + fill_h, bw, 3, col_edge)
|
|
323
|
+
else:
|
|
324
|
+
top_y = y + h - fill_h
|
|
325
|
+
fb.fill_rect(bx, top_y, bw, fill_h, col_main)
|
|
326
|
+
if top_y >= y + 3:
|
|
327
|
+
fb.fill_rect(bx, top_y - 3, bw, 3, col_edge)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
# A pygraphics FrameBuffer over buf. Bit World never reads the Area a drawing call
|
|
331
|
+
# returns, so it asks for none: on MicroPython each one is a new object, and a frame
|
|
332
|
+
# of them is enough garbage to stop the picture for a collection. A pygraphics
|
|
333
|
+
# without areas= returns them anyway.
|
|
334
|
+
def gfx_frame(buf, w, h):
|
|
335
|
+
try:
|
|
336
|
+
return FrameBuffer(buf, w, h, RGB565, areas=False)
|
|
337
|
+
except TypeError:
|
|
338
|
+
return FrameBuffer(buf, w, h, RGB565)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
if framebuf is None:
|
|
342
|
+
Canvas = None
|
|
343
|
+
else:
|
|
344
|
+
|
|
345
|
+
class Canvas(framebuf.FrameBuffer):
|
|
346
|
+
"""An RGB565 frame drawn with MicroPython's framebuf, which allocates nothing per call.
|
|
347
|
+
|
|
348
|
+
A pygraphics without ``areas=False`` returns a new ``Area`` from each drawing
|
|
349
|
+
call, and a frame makes a few hundred of them: enough garbage for a collection every few seconds, which
|
|
350
|
+
stops the picture for a fifth of a second on a board with a large heap. The
|
|
351
|
+
calls framebuf lacks, and text, whose 8x8 font differs, go to a pygraphics
|
|
352
|
+
``FrameBuffer`` on the same memory, in ``gfx``.
|
|
353
|
+
"""
|
|
354
|
+
|
|
355
|
+
def __init__(self, buf, w, h):
|
|
356
|
+
super().__init__(buf, w, h, framebuf.RGB565)
|
|
357
|
+
self.gfx = gfx_frame(buf, w, h)
|
|
358
|
+
|
|
359
|
+
# Draw text in pygraphics' 8x8 font, which isn't framebuf's.
|
|
360
|
+
def text(self, s, x, y, c):
|
|
361
|
+
self.gfx.text(s, x, y, c)
|
|
362
|
+
|
|
363
|
+
# Draw text in the 8x16 font.
|
|
364
|
+
def text16(self, s, x, y, c):
|
|
365
|
+
self.gfx.text16(s, x, y, c)
|
|
366
|
+
|
|
367
|
+
# Blend color through an 8-bit alpha mask.
|
|
368
|
+
def blit_alpha(self, mask, x, y, w, h, c):
|
|
369
|
+
self.gfx.blit_alpha(mask, x, y, w, h, c)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
# Wrap w x h RGB565 pixels in buf for drawing: a Canvas where framebuf exists.
|
|
373
|
+
def make_canvas(buf, w, h):
|
|
374
|
+
if Canvas is None:
|
|
375
|
+
return gfx_frame(buf, w, h)
|
|
376
|
+
return Canvas(buf, w, h)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
# A pygraphics Draw for a frame from make_canvas.
|
|
380
|
+
def make_draw(fb):
|
|
381
|
+
return Draw(getattr(fb, "gfx", fb))
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
# n zeroed bytes for pixels. With offheap they live outside the garbage-collected
|
|
385
|
+
# heap, which reads every word of a bytearray at each collection: on an ESP32 the
|
|
386
|
+
# three 800x480 backgrounds made every collection stop the picture for 200 ms or
|
|
387
|
+
# more. Keep the returned object for as long as anything draws into it, because a
|
|
388
|
+
# memoryview of it doesn't keep it alive.
|
|
389
|
+
def pixel_bytes(n):
|
|
390
|
+
if OffHeapBuffer is None:
|
|
391
|
+
return bytearray(n)
|
|
392
|
+
return OffHeapBuffer(n)
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# Build a reusable RGB565 frame tuple (pixel_bytes, frame from make_canvas).
|
|
396
|
+
def make_fb(w, h, fill_color=None):
|
|
397
|
+
buf = pixel_bytes(w * h * 2)
|
|
398
|
+
fb = make_canvas(buf, w, h)
|
|
399
|
+
if fill_color is not None:
|
|
400
|
+
fb.fill(fill_color)
|
|
401
|
+
return buf, fb
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
class PanelState:
|
|
405
|
+
"""What one display buffer holds: which act, where its moving parts were, what it drew."""
|
|
406
|
+
|
|
407
|
+
def __init__(self):
|
|
408
|
+
self.act = -1
|
|
409
|
+
self.rects = []
|
|
410
|
+
# An act may keep its moving rectangles here instead, as x, y, w, h in an array,
|
|
411
|
+
# with how many there are, so remembering them allocates nothing.
|
|
412
|
+
self.moved = None
|
|
413
|
+
self.moved_n = 0
|
|
414
|
+
self.sig = {}
|
|
415
|
+
self.bar = None
|
|
416
|
+
|
|
417
|
+
# True, and remember it, when value differs from what this buffer last drew for key.
|
|
418
|
+
def changed(self, key, value):
|
|
419
|
+
if self.sig.get(key) == value:
|
|
420
|
+
return False
|
|
421
|
+
self.sig[key] = value
|
|
422
|
+
return True
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
# Copy all of src, a frame from make_canvas, over fb. pygraphics copies whole rows at a
|
|
426
|
+
# time, where framebuf copies pixel by pixel, fifty times slower at full screen.
|
|
427
|
+
def copy_frame(fb, src):
|
|
428
|
+
getattr(fb, "gfx", fb).blit(getattr(src, "gfx", src), 0, 0)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
# Rectangles up to this many pixels are copied by framebuf, which allocates nothing.
|
|
432
|
+
# Larger ones go to pygraphics, whose row copies are much faster; a pygraphics without
|
|
433
|
+
# areas=False also makes a new Area for each.
|
|
434
|
+
SMALL_COPY = 2048
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
# Blit sources for rectangles of the background that never move: (source, x, y) for each,
|
|
438
|
+
# clipped like restore_rects. Build them once, and restore_sources copies them each frame.
|
|
439
|
+
def rect_sources(src, rects, w, h):
|
|
440
|
+
view = memoryview(src)
|
|
441
|
+
sources = []
|
|
442
|
+
for x, y, rw, rh in rects:
|
|
443
|
+
x0 = max(0, x)
|
|
444
|
+
y0 = max(0, y)
|
|
445
|
+
x1 = min(w, x + rw)
|
|
446
|
+
y1 = min(h, y + rh)
|
|
447
|
+
if x1 > x0 and y1 > y0:
|
|
448
|
+
sources.append(((view[(y0 * w + x0) * 2 :], x1 - x0, y1 - y0, RGB565, w), x0, y0))
|
|
449
|
+
return sources
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
# Copy the rectangles rect_sources prepared back over a frame.
|
|
453
|
+
def restore_sources(fb, sources):
|
|
454
|
+
gfx = getattr(fb, "gfx", fb)
|
|
455
|
+
for source, x, y in sources:
|
|
456
|
+
if source[1] * source[2] <= SMALL_COPY:
|
|
457
|
+
fb.blit(source, x, y)
|
|
458
|
+
else:
|
|
459
|
+
gfx.blit(source, x, y)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
# framebuf takes a list as a blit source, so restore_rect fills in this one each time.
|
|
463
|
+
_source = [None, 0, 0, RGB565, 0]
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
# Copy one (x, y, w, h) rectangle of the pre-rendered background back over a frame, from
|
|
467
|
+
# view, a memoryview of the background made once, clipped to the w x h frame. It's a blit
|
|
468
|
+
# from a (buffer, width, height, format, stride) view into the background; slicing the
|
|
469
|
+
# rows in Python is far slower on a board.
|
|
470
|
+
def restore_rect(fb, view, rect, w, h):
|
|
471
|
+
x, y, rw, rh = rect
|
|
472
|
+
restore_area(fb, view, x, y, rw, rh, w, h)
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
# restore_rect for a rectangle given as numbers, which saves making a tuple for it.
|
|
476
|
+
def restore_area(fb, view, x, y, rw, rh, w, h):
|
|
477
|
+
x0 = max(0, x)
|
|
478
|
+
y0 = max(0, y)
|
|
479
|
+
x1 = min(w, x + rw)
|
|
480
|
+
y1 = min(h, y + rh)
|
|
481
|
+
if x1 <= x0 or y1 <= y0:
|
|
482
|
+
return
|
|
483
|
+
gfx = getattr(fb, "gfx", fb)
|
|
484
|
+
src = _source
|
|
485
|
+
src[0] = view[(y0 * w + x0) * 2 :]
|
|
486
|
+
src[1] = x1 - x0
|
|
487
|
+
src[2] = y1 - y0
|
|
488
|
+
src[4] = w
|
|
489
|
+
if gfx is not fb and src[1] * src[2] <= SMALL_COPY:
|
|
490
|
+
fb.blit(src, x0, y0)
|
|
491
|
+
else:
|
|
492
|
+
gfx.blit((src[0], src[1], src[2], RGB565, w), x0, y0)
|
|
493
|
+
src[0] = None # don't keep the background's view alive
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
# Copy each rectangle in rects back with restore_rect. One listed twice, or listed in
|
|
497
|
+
# skip because it was copied already, is copied once.
|
|
498
|
+
def restore_rects(fb, view, rects, w, h, skip=None):
|
|
499
|
+
for i in range(len(rects)):
|
|
500
|
+
rect = rects[i]
|
|
501
|
+
if rects.index(rect) < i or (skip is not None and rect in skip):
|
|
502
|
+
continue
|
|
503
|
+
restore_rect(fb, view, rect, w, h)
|