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/chess/art.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Chess's pictures: turned Staunton pieces and wooden or stone boards,
|
|
5
|
+
drawn by svgio once per square size and kept as LVGL images.
|
|
6
|
+
|
|
7
|
+
Each piece is an SVG on a 100-unit square, lit from the upper left: a
|
|
8
|
+
gradient across it for the turned wood or polished stone, a soft sheen on
|
|
9
|
+
its rounded parts, a darker line round it and a shadow under its foot. A
|
|
10
|
+
`Theme` names the board's two woods (or marbles) and the pieces' two
|
|
11
|
+
materials. `Pictures` draws a theme's board and its twelve pieces at one
|
|
12
|
+
square size, the first time they're asked for, so a move never parses an
|
|
13
|
+
SVG.
|
|
14
|
+
|
|
15
|
+
The shapes keep to what every svgio draws the same way: paths, circles,
|
|
16
|
+
ellipses, rectangles, and linear and radial gradients with their stops'
|
|
17
|
+
opacity.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import lvgl as lv
|
|
21
|
+
import svgio
|
|
22
|
+
|
|
23
|
+
from .engine import BISHOP, KING, KNIGHT, PAWN, QUEEN, ROOK
|
|
24
|
+
|
|
25
|
+
_HEAD = '<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="%s">'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Theme:
|
|
29
|
+
"""A board and a set of pieces.
|
|
30
|
+
|
|
31
|
+
``squares`` is ``(light, dark)``, each a dict with ``base`` and ``grain``
|
|
32
|
+
colours and ``kind`` (``"wood"`` or ``"marble"``). ``pieces`` is
|
|
33
|
+
``(white, black)``, each a dict of the material's ``edge`` (its shaded
|
|
34
|
+
side), ``body``, ``shine`` and ``line`` colours.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, name, squares, pieces, frame, mark):
|
|
38
|
+
self.name = name
|
|
39
|
+
self.squares = squares
|
|
40
|
+
self.pieces = pieces
|
|
41
|
+
self.frame = frame
|
|
42
|
+
self.mark = mark # the colour of a selected square and the last move
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_BOXWOOD = {"edge": "#9A6A35", "body": "#E9C88E", "shine": "#FFF3D6", "line": "#5C3B17"}
|
|
46
|
+
_EBONY = {"edge": "#0D0806", "body": "#3A2A22", "shine": "#9C8576", "line": "#000000"}
|
|
47
|
+
_ROSE = {"edge": "#2A0D07", "body": "#6B2A1A", "shine": "#D08B6E", "line": "#1A0603"}
|
|
48
|
+
_ALABASTER = {"edge": "#A9A39A", "body": "#F1EEE8", "shine": "#FFFFFF", "line": "#6E6860"}
|
|
49
|
+
_ONYX = {"edge": "#050608", "body": "#2C3036", "shine": "#A6B0BC", "line": "#000000"}
|
|
50
|
+
|
|
51
|
+
THEMES = (
|
|
52
|
+
Theme("Walnut",
|
|
53
|
+
({"kind": "wood", "base": "#E3C48F", "grain": "#B88A52"},
|
|
54
|
+
{"kind": "wood", "base": "#7A4B2A", "grain": "#4A2A14"}),
|
|
55
|
+
(_BOXWOOD, _EBONY), 0x3B2414, 0x6FD3FF),
|
|
56
|
+
Theme("Rosewood",
|
|
57
|
+
({"kind": "wood", "base": "#EFD9B4", "grain": "#C9A97A"},
|
|
58
|
+
{"kind": "wood", "base": "#8E3B2A", "grain": "#5A1F14"}),
|
|
59
|
+
(_BOXWOOD, _ROSE), 0x3A1610, 0xFFD166),
|
|
60
|
+
Theme("Marble",
|
|
61
|
+
({"kind": "marble", "base": "#ECE9E2", "grain": "#9C978C"},
|
|
62
|
+
{"kind": "marble", "base": "#4E6B62", "grain": "#22342E"}),
|
|
63
|
+
(_ALABASTER, _ONYX), 0x26302C, 0xFF9F1C),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# The parts every piece stands on: a foot with two rings, as a lathe turns it.
|
|
67
|
+
_FOOT = ('<ellipse cx="50" cy="93" rx="36" ry="5" fill="#000" fill-opacity="0.35"/>'
|
|
68
|
+
'<path d="M17 92 C17 86 20 83 26 82 L74 82 C80 83 83 86 83 92 Z" {f}/>'
|
|
69
|
+
'<path d="M24 82 C24 78 27 76 31 75.5 L69 75.5 C73 76 76 78 76 82 Z" {f}/>')
|
|
70
|
+
|
|
71
|
+
# Each body sits on the foot. The knight's is its own: a horse's head
|
|
72
|
+
# looking left, with a mane down its neck.
|
|
73
|
+
_BODIES = {
|
|
74
|
+
PAWN: ('<path d="M35 76 C38 68 42 60 43 54 L57 54 C58 60 62 68 65 76 Z" {f}/>'
|
|
75
|
+
'<ellipse cx="50" cy="53" rx="15" ry="4.2" {f}/>'
|
|
76
|
+
'<circle cx="50" cy="37.5" r="13.5" {f}/>'
|
|
77
|
+
'<circle cx="45" cy="32" r="6.5" {s}/>'),
|
|
78
|
+
ROOK: ('<path d="M31 76 C33 66 34 54 34 43 L66 43 C66 54 67 66 69 76 Z" {f}/>'
|
|
79
|
+
'<path d="M29 44 L71 44 L69 39 L31 39 Z" {f}/>'
|
|
80
|
+
'<path d="M28 39 L28 19 L37 19 L37 26 L45.5 26 L45.5 19 L54.5 19 L54.5 26 L63 26 L63 19 L72 19 L72 39 Z" {f}/>'
|
|
81
|
+
'<path d="M36 70 L64 70" {l}/>'
|
|
82
|
+
'<path d="M33 31 C37 30 39 30 41 31" {l}/>'),
|
|
83
|
+
BISHOP: ('<path d="M33 76 C38 70 43 64 44 58 L56 58 C57 64 62 70 67 76 Z" {f}/>'
|
|
84
|
+
'<ellipse cx="50" cy="57" rx="15" ry="4" {f}/>'
|
|
85
|
+
'<ellipse cx="50" cy="52" rx="11" ry="3" {f}/>'
|
|
86
|
+
'<path d="M50 14 C59 22 64 32 63 40 C62 47 57 50 50 50 C43 50 38 47 37 40 C36 32 41 22 50 14 Z" {f}/>'
|
|
87
|
+
'<path d="M55 25 L47 37" {l}/>'
|
|
88
|
+
'<circle cx="50" cy="12" r="4.5" {f}/>'
|
|
89
|
+
'<ellipse cx="44" cy="31" rx="4" ry="8" {s}/>'),
|
|
90
|
+
QUEEN: ('<path d="M31 76 C37 68 42 58 43 48 L57 48 C58 58 63 68 69 76 Z" {f}/>'
|
|
91
|
+
'<ellipse cx="50" cy="48" rx="17" ry="4.5" {f}/>'
|
|
92
|
+
'<path d="M34 44 L28 21 L38 32 L44 17 L50 31 L56 17 L62 32 L72 21 L66 44 Z" {f}/>'
|
|
93
|
+
'<circle cx="28" cy="20" r="3.6" {f}/><circle cx="44" cy="15.5" r="3.6" {f}/>'
|
|
94
|
+
'<circle cx="56" cy="15.5" r="3.6" {f}/><circle cx="72" cy="20" r="3.6" {f}/>'
|
|
95
|
+
'<circle cx="50" cy="24" r="4.5" {f}/>'
|
|
96
|
+
'<path d="M36 41 L64 41" {l}/>'
|
|
97
|
+
'<ellipse cx="42" cy="62" rx="3" ry="9" {s}/>'),
|
|
98
|
+
KING: ('<path d="M31 76 C37 68 42 58 43 48 L57 48 C58 58 63 68 69 76 Z" {f}/>'
|
|
99
|
+
'<ellipse cx="50" cy="48" rx="17" ry="4.5" {f}/>'
|
|
100
|
+
'<path d="M35 44 C33 36 34 29 39 26 L61 26 C66 29 67 36 65 44 Z" {f}/>'
|
|
101
|
+
'<path d="M40 27 C42 21 46 19 50 19 C54 19 58 21 60 27 Z" {f}/>'
|
|
102
|
+
'<path d="M47 20 L47 13.5 L42 13.5 L42 8.5 L47 8.5 L47 3.5 L53 3.5 L53 8.5 L58 8.5 L58 13.5 L53 13.5 L53 20 Z" {f}/>'
|
|
103
|
+
'<path d="M36 40 L64 40" {l}/>'
|
|
104
|
+
'<ellipse cx="42" cy="62" rx="3" ry="9" {s}/><ellipse cx="42" cy="33" rx="3" ry="5" {s}/>'),
|
|
105
|
+
KNIGHT: ('<path d="M30 76 C31 68 36 62 40 58 C34 58 28 60 24 57 C20 54 19 49 22 45 '
|
|
106
|
+
'C26 39 31 33 35 27 C37 22 40 19 42 16 L44 8 L49 15 C52 14 55 14 57 15 L60 9 L62 18 '
|
|
107
|
+
'C70 24 74 34 74 46 C74 58 70 68 70 76 Z" {f}/>'
|
|
108
|
+
'<path d="M62 18 C69 27 72 38 71 50 C70 60 67 68 67 75" fill="none" stroke="{line}" stroke-width="1.6" stroke-opacity="0.55"/>'
|
|
109
|
+
'<path d="M64 24 L67 23 M66 31 L70 30 M68 38 L72 38 M68 46 L72 47 M68 54 L71 56" stroke="{line}" stroke-width="1.4" stroke-opacity="0.5" fill="none"/>'
|
|
110
|
+
'<ellipse cx="43" cy="28" rx="2.6" ry="2" fill="{line}"/>'
|
|
111
|
+
'<path d="M25 50 C26 48 28 47 29 48" fill="none" stroke="{line}" stroke-width="1.6"/>'
|
|
112
|
+
'<path d="M40 58 C44 52 46 46 46 40" fill="none" stroke="{line}" stroke-width="1.2" stroke-opacity="0.45"/>'
|
|
113
|
+
'<path d="M32 33 C36 27 40 22 44 18" fill="none" stroke="{shine}" stroke-width="3" stroke-opacity="0.45" stroke-linecap="round"/>'),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_NAMES = {PAWN: "pawn", ROOK: "rook", KNIGHT: "knight", BISHOP: "bishop", QUEEN: "queen", KING: "king"}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def piece_svg(kind, material):
|
|
120
|
+
"""One piece's SVG text: *kind* is the engine's piece number (no
|
|
121
|
+
colour), *material* one of a `Theme`'s ``pieces``."""
|
|
122
|
+
m = material
|
|
123
|
+
defs = ('<defs>'
|
|
124
|
+
'<linearGradient id="g" gradientUnits="userSpaceOnUse" x1="16" y1="0" x2="84" y2="0">'
|
|
125
|
+
'<stop offset="0" stop-color="{edge}"/><stop offset="0.3" stop-color="{shine}"/>'
|
|
126
|
+
'<stop offset="0.52" stop-color="{body}"/><stop offset="1" stop-color="{edge}"/>'
|
|
127
|
+
'</linearGradient>'
|
|
128
|
+
'<radialGradient id="s" gradientUnits="objectBoundingBox" cx="0.5" cy="0.5" r="0.5">'
|
|
129
|
+
'<stop offset="0" stop-color="#fff" stop-opacity="0.75"/><stop offset="1" stop-color="#fff" stop-opacity="0"/>'
|
|
130
|
+
'</radialGradient></defs>')
|
|
131
|
+
fill = 'fill="url(#g)" stroke="{line}" stroke-width="1.5" stroke-linejoin="round"'
|
|
132
|
+
sheen = 'fill="url(#s)"'
|
|
133
|
+
line = 'fill="none" stroke="{line}" stroke-width="1.2" stroke-opacity="0.6"'
|
|
134
|
+
body = (_FOOT + _BODIES[kind]).replace("{f}", fill).replace("{s}", sheen).replace("{l}", line)
|
|
135
|
+
text = defs + body
|
|
136
|
+
for key in ("edge", "body", "shine", "line"):
|
|
137
|
+
text = text.replace("{" + key + "}", m[key])
|
|
138
|
+
return text
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _rng(seed):
|
|
142
|
+
"""A tiny deterministic random source, so a theme's grain is the same every time."""
|
|
143
|
+
state = [seed & 0x7FFFFFFF or 1]
|
|
144
|
+
|
|
145
|
+
def next_float():
|
|
146
|
+
state[0] = (state[0] * 1103515245 + 12345) & 0x7FFFFFFF
|
|
147
|
+
return state[0] / 0x7FFFFFFF
|
|
148
|
+
|
|
149
|
+
return next_float
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def board_svg(theme, square):
|
|
153
|
+
"""The board's SVG text at *square* pixels a square, eight squares a side."""
|
|
154
|
+
size = square * 8
|
|
155
|
+
rnd = _rng(len(theme.name) * 7919 + square)
|
|
156
|
+
out = [_HEAD % (size, size, "0 0 %d %d" % (size, size))]
|
|
157
|
+
out.append("<defs>")
|
|
158
|
+
for n, wood in enumerate(theme.squares):
|
|
159
|
+
out.append('<linearGradient id="w%d" x1="0" y1="0" x2="1" y2="1">'
|
|
160
|
+
'<stop offset="0" stop-color="%s"/><stop offset="1" stop-color="%s"/></linearGradient>'
|
|
161
|
+
% (n, wood["base"], _shade(wood["base"], 0.86)))
|
|
162
|
+
out.append("</defs>")
|
|
163
|
+
s = square
|
|
164
|
+
for row in range(8):
|
|
165
|
+
for col in range(8):
|
|
166
|
+
dark = (row + col) % 2
|
|
167
|
+
wood = theme.squares[dark]
|
|
168
|
+
x = col * s
|
|
169
|
+
y = row * s
|
|
170
|
+
out.append('<rect x="%d" y="%d" width="%d" height="%d" fill="url(#w%d)"/>' % (x, y, s, s, dark))
|
|
171
|
+
if wood["kind"] == "wood":
|
|
172
|
+
out.append(_grain(x, y, s, wood["grain"], bool(dark), rnd))
|
|
173
|
+
else:
|
|
174
|
+
out.append(_veins(x, y, s, wood["grain"], rnd))
|
|
175
|
+
# A thin bevel round the whole board.
|
|
176
|
+
out.append('<rect x="0.5" y="0.5" width="%d" height="%d" fill="none" stroke="#000" stroke-opacity="0.45"/>' % (size - 1, size - 1))
|
|
177
|
+
out.append("</svg>")
|
|
178
|
+
return "".join(out)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _grain(x, y, s, colour, across, rnd):
|
|
182
|
+
"""A square's wood grain: fine wavy lines, along it or across it, so
|
|
183
|
+
neighbouring squares look cut from different boards."""
|
|
184
|
+
lines = 7 + int(rnd() * 4)
|
|
185
|
+
width = max(0.5, s / 60)
|
|
186
|
+
parts = []
|
|
187
|
+
for k in range(lines):
|
|
188
|
+
at = (k + 0.3 + rnd() * 0.5) * s / lines
|
|
189
|
+
amp = (rnd() - 0.5) * s * 0.12
|
|
190
|
+
drift = (rnd() - 0.5) * s * 0.06
|
|
191
|
+
if across:
|
|
192
|
+
a, b = x + at, x + at + drift
|
|
193
|
+
mid = x + at + amp
|
|
194
|
+
d = "M%.1f %d Q%.1f %.1f %.1f %d" % (a, y, mid, y + s / 2, b, y + s)
|
|
195
|
+
else:
|
|
196
|
+
a, b = y + at, y + at + drift
|
|
197
|
+
mid = y + at + amp
|
|
198
|
+
d = "M%d %.1f Q%.1f %.1f %d %.1f" % (x, a, x + s / 2, mid, x + s, b)
|
|
199
|
+
opacity = 0.12 + rnd() * 0.25
|
|
200
|
+
w = width * (0.6 + rnd() * 1.4)
|
|
201
|
+
parts.append('<path d="%s" fill="none" stroke="%s" stroke-width="%.2f" stroke-opacity="%.2f"/>' % (d, colour, w, opacity))
|
|
202
|
+
return "".join(parts)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _veins(x, y, s, colour, rnd):
|
|
206
|
+
"""A square of marble: a cloud of soft mottling and one or two fine
|
|
207
|
+
veins running across it at a slant, as cut stone shows them."""
|
|
208
|
+
parts = []
|
|
209
|
+
for _ in range(3):
|
|
210
|
+
parts.append('<circle cx="%.1f" cy="%.1f" r="%.1f" fill="%s" fill-opacity="%.2f"/>'
|
|
211
|
+
% (x + rnd() * s, y + rnd() * s, s * (0.12 + rnd() * 0.18), colour, 0.05 + rnd() * 0.06))
|
|
212
|
+
for _ in range(1 + int(rnd() * 2)):
|
|
213
|
+
x0 = x + rnd() * s * 0.6
|
|
214
|
+
x1 = x0 + s * (0.2 + rnd() * 0.4)
|
|
215
|
+
bend = (rnd() - 0.5) * s * 0.25
|
|
216
|
+
d = "M%.1f %d C%.1f %.1f %.1f %.1f %.1f %d" % (
|
|
217
|
+
x0, y, x0 + (x1 - x0) * 0.33 + bend, y + s * 0.33, x0 + (x1 - x0) * 0.66 - bend, y + s * 0.66, min(x1, x + s), y + s)
|
|
218
|
+
parts.append('<path d="%s" fill="none" stroke="%s" stroke-width="%.2f" stroke-opacity="%.2f"/>'
|
|
219
|
+
% (d, colour, max(0.5, s / 70) * (0.6 + rnd()), 0.25 + rnd() * 0.3))
|
|
220
|
+
return "".join(parts)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _shade(hex_colour, k):
|
|
224
|
+
v = int(hex_colour[1:], 16)
|
|
225
|
+
r = min(255, int(((v >> 16) & 255) * k))
|
|
226
|
+
g = min(255, int(((v >> 8) & 255) * k))
|
|
227
|
+
b = min(255, int((v & 255) * k))
|
|
228
|
+
return "#%02X%02X%02X" % (r, g, b)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def glow_svg():
|
|
232
|
+
"""The red glow under a king in check, on a 100-unit square."""
|
|
233
|
+
return ('<defs><radialGradient id="r" cx="50" cy="50" r="50" gradientUnits="userSpaceOnUse">'
|
|
234
|
+
'<stop offset="0" stop-color="#FF2A1A" stop-opacity="0.95"/>'
|
|
235
|
+
'<stop offset="0.55" stop-color="#FF3B1F" stop-opacity="0.55"/>'
|
|
236
|
+
'<stop offset="1" stop-color="#FF3B1F" stop-opacity="0"/></radialGradient></defs>'
|
|
237
|
+
'<circle cx="50" cy="50" r="50" fill="url(#r)"/>')
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
#: The working memory a decoder gets while it draws a theme: room for the
|
|
241
|
+
#: board's thousands of small blocks, as Backline's art takes.
|
|
242
|
+
DECODER_MEMORY = 96 * 1024
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _decoder():
|
|
246
|
+
try:
|
|
247
|
+
return svgio.SvgDecoder(memory=DECODER_MEMORY)
|
|
248
|
+
except TypeError:
|
|
249
|
+
return svgio.SvgDecoder()
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _image(decoder, text, px, alpha=True):
|
|
253
|
+
"""Draw SVG *text* at *px* pixels wide; return ``(dsc, data)``."""
|
|
254
|
+
if isinstance(text, str):
|
|
255
|
+
text = text.encode()
|
|
256
|
+
w, h = decoder.open(text, width=px)
|
|
257
|
+
n = w * h
|
|
258
|
+
data = bytearray(n * (3 if alpha else 2))
|
|
259
|
+
if alpha:
|
|
260
|
+
view = memoryview(data)
|
|
261
|
+
decoder.decode(view[: n * 2], view[n * 2:])
|
|
262
|
+
else:
|
|
263
|
+
decoder.decode(data)
|
|
264
|
+
dsc = lv.image_dsc_t()
|
|
265
|
+
dsc.header.magic = lv.IMAGE_HEADER_MAGIC
|
|
266
|
+
dsc.header.cf = lv.COLOR_FORMAT.RGB565A8 if alpha else lv.COLOR_FORMAT.RGB565
|
|
267
|
+
dsc.header.w = w
|
|
268
|
+
dsc.header.h = h
|
|
269
|
+
dsc.header.stride = w * 2
|
|
270
|
+
dsc.data_size = len(data)
|
|
271
|
+
dsc.data = data
|
|
272
|
+
return dsc, data
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class Pictures:
|
|
276
|
+
"""A theme's board and pieces at one square size, drawn as asked for.
|
|
277
|
+
|
|
278
|
+
``board()`` is the whole board's image source; ``piece(code)`` a
|
|
279
|
+
piece's, by the engine's number with the colour in its low bit;
|
|
280
|
+
``glow()`` the check glow's. Each is drawn once and kept until
|
|
281
|
+
`forget`.
|
|
282
|
+
"""
|
|
283
|
+
|
|
284
|
+
def __init__(self, theme, square):
|
|
285
|
+
self.theme = theme
|
|
286
|
+
self.square = square
|
|
287
|
+
self._kept = {}
|
|
288
|
+
|
|
289
|
+
def _get(self, key, make):
|
|
290
|
+
hit = self._kept.get(key)
|
|
291
|
+
if hit is None:
|
|
292
|
+
decoder = _decoder()
|
|
293
|
+
try:
|
|
294
|
+
hit = make(decoder)
|
|
295
|
+
finally:
|
|
296
|
+
close = getattr(decoder, "close", None)
|
|
297
|
+
if close is not None:
|
|
298
|
+
close()
|
|
299
|
+
self._kept[key] = hit
|
|
300
|
+
return hit[0]
|
|
301
|
+
|
|
302
|
+
def board(self):
|
|
303
|
+
return self._get("board", lambda d: _image(d, board_svg(self.theme, self.square), self.square * 8, alpha=False))
|
|
304
|
+
|
|
305
|
+
def piece(self, code):
|
|
306
|
+
def make(d):
|
|
307
|
+
text = _HEAD % (self.square, self.square, "0 0 100 100") + piece_svg(code & 14, self.theme.pieces[code & 1]) + "</svg>"
|
|
308
|
+
return _image(d, text, self.square)
|
|
309
|
+
|
|
310
|
+
return self._get(code, make)
|
|
311
|
+
|
|
312
|
+
def glow(self):
|
|
313
|
+
px = self.square * 3 // 2
|
|
314
|
+
return self._get("glow", lambda d: _image(d, _HEAD % (px, px, "0 0 100 100") + glow_svg() + "</svg>", px))
|
|
315
|
+
|
|
316
|
+
def forget(self):
|
|
317
|
+
"""Let every picture go."""
|
|
318
|
+
self._kept.clear()
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def piece_name(code):
|
|
322
|
+
"""``"white knight"`` for the engine's number."""
|
|
323
|
+
return ("black " if code & 1 else "white ") + _NAMES[code & 14]
|