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
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The coast: a beach, a headland with a lighthouse and one tree, in any season.
|
|
5
|
+
|
|
6
|
+
`draw` adds the scene to a `vec.Doc`, 800 by 480 units. The season picks the
|
|
7
|
+
colours, what the tree carries and what lies on the sand; `night` turns the
|
|
8
|
+
same season to night.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
|
|
13
|
+
from . import huey_props
|
|
14
|
+
from . import huey_shift # noqa: F401 (its colour schemes)
|
|
15
|
+
from .vec import at, circle, ellipse, group, limb, line, mix, path, pts, rect, smooth
|
|
16
|
+
|
|
17
|
+
W, H = 800, 480
|
|
18
|
+
HORIZON = 252
|
|
19
|
+
|
|
20
|
+
# Per season: the sky from its top to the sun, the sea far to near, the sand,
|
|
21
|
+
# the headland, the tree's leaves, the grass.
|
|
22
|
+
SEASONS = {
|
|
23
|
+
"spring": {
|
|
24
|
+
"sky": (0x6FBDE8, 0xBFE4F2, 0xFFF1D8),
|
|
25
|
+
"sun": 0xFFF7D6,
|
|
26
|
+
"sea": (0x2F8FB3, 0x48B5C4, 0x8FDCD2),
|
|
27
|
+
"sand": (0xF6E3B4, 0xEBCF93, 0xD9B777),
|
|
28
|
+
"land": (0x8FB7A8, 0x5E9A7E),
|
|
29
|
+
"leaves": (0xFFD3E0, 0xFFA9C4, 0xE87DA3),
|
|
30
|
+
"grass": (0x8CC152, 0x5E9E3E),
|
|
31
|
+
"cloud": (0xFFFFFF, 0xE3F1F7),
|
|
32
|
+
"sun_at": (560, 120),
|
|
33
|
+
},
|
|
34
|
+
"summer": {
|
|
35
|
+
"sky": (0x1E8FD5, 0x6CC4EE, 0xD9F4FB),
|
|
36
|
+
"sun": 0xFFFBE0,
|
|
37
|
+
"sea": (0x0E6FA8, 0x1FA3C0, 0x6FDCCB),
|
|
38
|
+
"sand": (0xFBE7B2, 0xF2D08A, 0xDDB066),
|
|
39
|
+
"land": (0x6FA9A0, 0x3F8A66),
|
|
40
|
+
"leaves": (0x9BD45A, 0x5FB045, 0x2F8544),
|
|
41
|
+
"grass": (0x9CCB4A, 0x4F9A3A),
|
|
42
|
+
"cloud": (0xFFFFFF, 0xDDF0F8),
|
|
43
|
+
"sun_at": (600, 84),
|
|
44
|
+
},
|
|
45
|
+
"autumn": {
|
|
46
|
+
"sky": (0x4B3F8C, 0xD7607A, 0xFFC56B),
|
|
47
|
+
"sun": 0xFFF0B8,
|
|
48
|
+
"sea": (0x3B3A7A, 0x8B4E86, 0xF29A6B),
|
|
49
|
+
"sand": (0xF2C58E, 0xDFA56C, 0xB97F52),
|
|
50
|
+
"land": (0x6B4B7E, 0x4A335F),
|
|
51
|
+
"leaves": (0xFFC83D, 0xF58B2A, 0xC9482B),
|
|
52
|
+
"grass": (0xD9A441, 0x9A6B2F),
|
|
53
|
+
"cloud": (0xFFD9B0, 0xF79C7C),
|
|
54
|
+
"sun_at": (470, 214),
|
|
55
|
+
},
|
|
56
|
+
"winter": {
|
|
57
|
+
"sky": (0x7C9CC0, 0xBDD3E6, 0xF4F7FA),
|
|
58
|
+
"sun": 0xFFFFFF,
|
|
59
|
+
"sea": (0x4A6E8F, 0x6E97B2, 0xA9CAD8),
|
|
60
|
+
"sand": (0xFFFFFF, 0xE6F0F8, 0xC3D7E8),
|
|
61
|
+
"land": (0xC9D9E6, 0x9DB6CB),
|
|
62
|
+
"leaves": None,
|
|
63
|
+
"grass": (0xC9B98A, 0x9C8B62),
|
|
64
|
+
"cloud": (0xFFFFFF, 0xDCE7F1),
|
|
65
|
+
"sun_at": (520, 150),
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_NIGHT_SKY = (0x06122A, 0x12305C, 0x2A5A8C)
|
|
70
|
+
_BARK = 0x5B3B2E
|
|
71
|
+
_BARK_LIGHT = 0x7A5440
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _Random:
|
|
75
|
+
# the same numbers on every runtime, so the tree is the same tree
|
|
76
|
+
def __init__(self, seed):
|
|
77
|
+
self.state = seed
|
|
78
|
+
|
|
79
|
+
def next(self):
|
|
80
|
+
self.state = (self.state * 1103515245 + 12345) & 0x7FFFFFFF
|
|
81
|
+
return (self.state >> 8) / 8388608.0
|
|
82
|
+
|
|
83
|
+
def between(self, a, b):
|
|
84
|
+
return a + (b - a) * self.next()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _dim(color, night):
|
|
88
|
+
"""A daytime colour as moonlight sees it."""
|
|
89
|
+
if not night:
|
|
90
|
+
return color
|
|
91
|
+
return mix(mix(color, 0x1B3A6B, 0.55), 0x06122A, 0.25)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _wave_edge(x0, x1, y, amp, length, phase, bottom):
|
|
95
|
+
"""Path data: a strip from a wavy top edge down to *bottom*."""
|
|
96
|
+
points = []
|
|
97
|
+
x = x0
|
|
98
|
+
while x <= x1 + length / 4:
|
|
99
|
+
points.append((x, y + amp * math.sin((x + phase) * 2 * math.pi / length)))
|
|
100
|
+
x += length / 4
|
|
101
|
+
return smooth(points) + "L%d %dL%d %dZ" % (x1 + length, bottom, x0, bottom)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _sky(season, night):
|
|
105
|
+
out = []
|
|
106
|
+
top, middle, glow = _NIGHT_SKY if night else season["sky"]
|
|
107
|
+
sx, sy = season["sun_at"]
|
|
108
|
+
if night:
|
|
109
|
+
sx, sy = 590, 96
|
|
110
|
+
out.append(rect(0, 0, W, HORIZON + 4, top))
|
|
111
|
+
# rings of light around the sun: the sky's steps are drawn, not left to the display
|
|
112
|
+
radii = (560, 470, 390, 320, 255, 195, 140, 92)
|
|
113
|
+
for i, r in enumerate(radii):
|
|
114
|
+
t = (i + 1) / len(radii)
|
|
115
|
+
color = mix(top, middle, t * 2) if t < 0.5 else mix(middle, glow, t * 2 - 1)
|
|
116
|
+
out.append(circle(sx, sy, r, color))
|
|
117
|
+
if night:
|
|
118
|
+
stars = _Random(7)
|
|
119
|
+
for _ in range(70):
|
|
120
|
+
x, y = stars.between(0, W), stars.between(0, HORIZON - 30)
|
|
121
|
+
if (x - sx) ** 2 + (y - sy) ** 2 < 70 * 70:
|
|
122
|
+
continue
|
|
123
|
+
out.append(circle(x, y, stars.between(0.6, 1.9), 0xFFFFFF, opacity=stars.between(0.45, 1)))
|
|
124
|
+
# the moon, with the dark of it hiding one side
|
|
125
|
+
out.append(circle(sx, sy, 50, 0xFFFFFF, opacity=0.10))
|
|
126
|
+
out.append(circle(sx, sy, 34, 0xFFF8E1))
|
|
127
|
+
out.append(circle(sx - 9, sy - 8, 6, 0xE9DFC0))
|
|
128
|
+
out.append(circle(sx + 10, sy + 6, 9, 0xE9DFC0))
|
|
129
|
+
out.append(circle(sx + 2, sy - 16, 3.5, 0xE9DFC0))
|
|
130
|
+
else:
|
|
131
|
+
out.append(circle(sx, sy, 62, 0xFFFFFF, opacity=0.35))
|
|
132
|
+
out.append(circle(sx, sy, 40, season["sun"]))
|
|
133
|
+
return b"".join(out)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _cloud(x, y, s, colors):
|
|
137
|
+
light, shade = colors
|
|
138
|
+
out = [
|
|
139
|
+
circle(x - 34 * s, y + 3 * s, 18 * s, shade),
|
|
140
|
+
circle(x + 36 * s, y + 5 * s, 15 * s, shade),
|
|
141
|
+
circle(x + 6 * s, y - 6 * s, 26 * s, shade),
|
|
142
|
+
rect(x - 52 * s, y + 3 * s, 103 * s, 18 * s, shade, r=9 * s),
|
|
143
|
+
circle(x - 30 * s, y - 2 * s, 16 * s, light),
|
|
144
|
+
circle(x + 4 * s, y - 13 * s, 23 * s, light),
|
|
145
|
+
circle(x + 33 * s, y - 1 * s, 13 * s, light),
|
|
146
|
+
rect(x - 46 * s, y - 2 * s, 92 * s, 14 * s, light, r=7 * s),
|
|
147
|
+
]
|
|
148
|
+
return b"".join(out)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _headland(season, night, beam):
|
|
152
|
+
far, near = season["land"]
|
|
153
|
+
far, near = _dim(far, night), _dim(near, night)
|
|
154
|
+
out = []
|
|
155
|
+
out.append(path(smooth([(-20, HORIZON + 6), (40, 214), (120, 196), (190, 206), (262, 232), (330, HORIZON + 6)]) + "Z", far))
|
|
156
|
+
out.append(path(smooth([(-20, HORIZON + 8), (20, 226), (84, 212), (150, 224), (214, 244), (250, HORIZON + 8)]) + "Z", near))
|
|
157
|
+
# the lighthouse
|
|
158
|
+
x, y = 96, 212
|
|
159
|
+
if beam:
|
|
160
|
+
out.append(path("M%d %dL%d %dL%d %dZ" % (x, y - 78, 820, y - 40, 820, y + 70), 0xFFF3B0, opacity=0.16))
|
|
161
|
+
out.append(path("M%d %dL%d %dL%d %dZ" % (x, y - 78, 820, y - 10, 820, y + 42), 0xFFF3B0, opacity=0.16))
|
|
162
|
+
white, red = _dim(0xFFFDF5, night), _dim(0xE4513D, night)
|
|
163
|
+
out.append(path(pts([(x - 13, y), (x - 8, y - 66), (x + 8, y - 66), (x + 13, y)], True), white))
|
|
164
|
+
out.append(path(pts([(x - 11.6, y - 18), (x - 10.2, y - 36), (x + 10.2, y - 36), (x + 11.6, y - 18)], True), red))
|
|
165
|
+
out.append(path(pts([(x + 3, y), (x + 2, y - 66), (x + 8, y - 66), (x + 13, y)], True), 0x000000, opacity=0.12))
|
|
166
|
+
out.append(rect(x - 11, y - 70, 22, 5, _dim(0x3A3F4B, night), r=1))
|
|
167
|
+
out.append(rect(x - 7, y - 86, 14, 16, 0xFFF3B0 if beam else _dim(0xBFE4F2, night)))
|
|
168
|
+
out.append(path(pts([(x - 10, y - 86), (x, y - 98), (x + 10, y - 86)], True), red))
|
|
169
|
+
return b"".join(out)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _sea(season, night):
|
|
173
|
+
deep, mid_, shallow = (_dim(c, night) for c in season["sea"])
|
|
174
|
+
out = [rect(0, HORIZON, W, H - HORIZON, deep)]
|
|
175
|
+
bands = ((274, mix(deep, mid_, 0.5), 3, 150, 0), (300, mid_, 4, 190, 40), (330, mix(mid_, shallow, 0.5), 5, 230, 120), (362, shallow, 6, 270, 30))
|
|
176
|
+
for y, color, amp, length, phase in bands:
|
|
177
|
+
out.append(path(_wave_edge(0, W, y, amp, length, phase, H), color))
|
|
178
|
+
# the light on the water, in broken bars that widen toward the shore
|
|
179
|
+
sx = 590 if night else season["sun_at"][0]
|
|
180
|
+
glint = 0xFFF8E1 if night else season["sun"]
|
|
181
|
+
bars = _Random(11)
|
|
182
|
+
y = HORIZON + 5
|
|
183
|
+
half = 26.0
|
|
184
|
+
while y < 372:
|
|
185
|
+
for _ in range(2):
|
|
186
|
+
w = bars.between(half * 0.3, half)
|
|
187
|
+
x = sx + bars.between(-half, half) - w / 2
|
|
188
|
+
out.append(rect(x, y, w, 2.6, glint, r=1.3, opacity=bars.between(0.35, 0.8)))
|
|
189
|
+
y += 9
|
|
190
|
+
half += 5
|
|
191
|
+
return b"".join(out)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _shore(season, night):
|
|
195
|
+
light, sand, wet = (_dim(c, night) for c in season["sand"])
|
|
196
|
+
out = []
|
|
197
|
+
# foam, wet sand, dry sand: three curves a little apart
|
|
198
|
+
edge = [(-20, 392), (120, 372), (270, 380), (430, 366), (600, 372), (820, 352)]
|
|
199
|
+
out.append(path(smooth([(x, y - 12) for x, y in edge]) + "L820 480L-20 480Z", _dim(0xFFFFFF, night), opacity=0.9))
|
|
200
|
+
out.append(path(smooth([(x, y - 4) for x, y in edge]) + "L820 480L-20 480Z", wet))
|
|
201
|
+
out.append(path(smooth([(x, y + 14 + 6 * math.sin(x / 90)) for x, y in edge]) + "L820 480L-20 480Z", sand))
|
|
202
|
+
out.append(path(smooth([(-20, 452), (160, 436), (360, 452), (560, 440), (820, 458)]) + "L820 480L-20 480Z", light))
|
|
203
|
+
return b"".join(out)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _dune(season, night):
|
|
207
|
+
light, sand, wet = (_dim(c, night) for c in season["sand"])
|
|
208
|
+
dark, green = (_dim(c, night) for c in season["grass"])
|
|
209
|
+
out = []
|
|
210
|
+
out.append(path(smooth([(400, 500), (480, 420), (560, 338), (650, 288), (740, 268), (830, 262)]) + "L830 500Z", wet))
|
|
211
|
+
out.append(path(smooth([(450, 500), (520, 428), (592, 348), (676, 302), (760, 282), (830, 278)]) + "L830 500Z", sand))
|
|
212
|
+
out.append(path(smooth([(540, 500), (590, 440), (650, 380), (724, 340), (830, 320)]) + "L830 500Z", light))
|
|
213
|
+
# dune grass, in tufts
|
|
214
|
+
tufts = _Random(3)
|
|
215
|
+
for cx, cy, n in ((548, 356, 7), (598, 322, 6), (742, 290, 8), (786, 300, 6), (640, 384, 7), (720, 356, 5), (772, 410, 8)):
|
|
216
|
+
for _ in range(n):
|
|
217
|
+
lean = tufts.between(-16, 16)
|
|
218
|
+
tall = tufts.between(16, 38)
|
|
219
|
+
x = cx + tufts.between(-12, 12)
|
|
220
|
+
out.append(limb(x, cy, x + lean, cy - tall, lean / 60, 3.2, 0.8, green if tufts.next() > 0.45 else dark))
|
|
221
|
+
return b"".join(out)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _tree(season, night, x, y):
|
|
225
|
+
leaves = season["leaves"]
|
|
226
|
+
out = []
|
|
227
|
+
tips = []
|
|
228
|
+
rng = _Random(29)
|
|
229
|
+
bark, bark_light = _dim(_BARK, night), _dim(_BARK_LIGHT, night)
|
|
230
|
+
|
|
231
|
+
def branch(x0, y0, angle, length, width, depth):
|
|
232
|
+
x1 = x0 + math.cos(angle) * length
|
|
233
|
+
y1 = y0 + math.sin(angle) * length
|
|
234
|
+
out.append(limb(x0, y0, x1, y1, rng.between(-0.12, 0.12), width, width * 0.62, bark))
|
|
235
|
+
if depth == 0 or length < 9:
|
|
236
|
+
tips.append((x1, y1))
|
|
237
|
+
return
|
|
238
|
+
if depth < 3:
|
|
239
|
+
tips.append((x1, y1))
|
|
240
|
+
# the sea wind has pushed every fork a little inland
|
|
241
|
+
spread = rng.between(0.36, 0.62)
|
|
242
|
+
branch(x1, y1, angle - spread - 0.05, length * rng.between(0.68, 0.8), width * 0.62, depth - 1)
|
|
243
|
+
branch(x1, y1, angle + spread * 0.8 - 0.05, length * rng.between(0.62, 0.76), width * 0.6, depth - 1)
|
|
244
|
+
|
|
245
|
+
# the trunk leans, then forks
|
|
246
|
+
out.append(path("M%d %dQ%d %d %d %dL%d %dQ%d %d %d %dZ" % (x - 22, y + 8, x - 8, y + 2, x - 6, y - 14, x + 8, y - 14, x + 8, y + 2, x + 20, y + 8), bark))
|
|
247
|
+
out.append(limb(x - 1, y - 4, x + 8, y - 44, 0.10, 17, 13, bark))
|
|
248
|
+
out.append(limb(x - 9, y + 2, x - 2, y - 30, 0.1, 5, 3, bark_light))
|
|
249
|
+
branch(x + 8, y - 44, -math.pi / 2 - 0.42, 44, 12, 4)
|
|
250
|
+
branch(x + 8, y - 44, -math.pi / 2 + 0.50, 40, 11, 4)
|
|
251
|
+
if leaves:
|
|
252
|
+
light, mid_, dark = (_dim(c, night) for c in leaves)
|
|
253
|
+
blobs = []
|
|
254
|
+
for tx, ty in tips:
|
|
255
|
+
blobs.append((tx + rng.between(-6, 6), ty + rng.between(-6, 6), rng.between(13, 22)))
|
|
256
|
+
for bx, by, r in blobs:
|
|
257
|
+
out.append(circle(bx - 3, by + 5, r, dark))
|
|
258
|
+
for bx, by, r in blobs:
|
|
259
|
+
out.append(circle(bx, by, r * 0.86, mid_))
|
|
260
|
+
for bx, by, r in blobs:
|
|
261
|
+
if rng.next() > 0.35:
|
|
262
|
+
out.append(circle(bx + r * 0.3, by - r * 0.34, r * 0.42, light))
|
|
263
|
+
else:
|
|
264
|
+
# snow lying along the branch tips
|
|
265
|
+
for tx, ty in tips:
|
|
266
|
+
out.append(ellipse(tx, ty - 3, 7, 3, _dim(0xFFFFFF, night)))
|
|
267
|
+
return b"".join(out)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _gull(x, y, s, color):
|
|
271
|
+
return path("M%.1f %.1fQ%.1f %.1f %.1f %.1fQ%.1f %.1f %.1f %.1f" % (x - 9 * s, y - 2 * s, x - 4 * s, y - 7 * s, x, y, x + 5 * s, y - 8 * s, x + 11 * s, y - 3 * s), None, color, 1.8 * s)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _sailboat(x, y, night):
|
|
275
|
+
hull, sail = _dim(0xC8452F, night), _dim(0xFFFDF5, night)
|
|
276
|
+
return (
|
|
277
|
+
path(pts([(x - 14, y - 5), (x + 16, y - 5), (x + 11, y + 2), (x - 9, y + 2)], True), hull)
|
|
278
|
+
+ path(pts([(x + 1, y - 34), (x + 1, y - 7), (x + 15, y - 7)], True), sail)
|
|
279
|
+
+ path(pts([(x - 2, y - 28), (x - 2, y - 7), (x - 12, y - 7)], True), mix(sail, 0x8FA9C4, 0.35))
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _starfish(x, y, r, color, turn):
|
|
284
|
+
points = []
|
|
285
|
+
for i in range(10):
|
|
286
|
+
a = math.radians(turn + i * 36)
|
|
287
|
+
rr = r if i % 2 == 0 else r * 0.42
|
|
288
|
+
points.append((x + math.cos(a) * rr, y + math.sin(a) * rr * 0.62))
|
|
289
|
+
return path(smooth(points, True), color) + ellipse(x, y, r * 0.2, r * 0.12, mix(color, 0xFFFFFF, 0.4))
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _sandcastle(x, y, sand, shade):
|
|
293
|
+
out = [
|
|
294
|
+
rect(x - 30, y - 22, 60, 24, sand, r=2),
|
|
295
|
+
rect(x - 30, y - 22, 14, 24, shade, opacity=0.5),
|
|
296
|
+
rect(x - 13, y - 44, 26, 26, sand, r=2),
|
|
297
|
+
rect(x - 13, y - 44, 7, 26, shade, opacity=0.5),
|
|
298
|
+
]
|
|
299
|
+
for dx in (-30, -15, 0, 15):
|
|
300
|
+
out.append(rect(x + dx + 2, y - 28, 9, 8, sand, r=1))
|
|
301
|
+
for dx in (-13, -1, 9):
|
|
302
|
+
out.append(rect(x + dx, y - 50, 7, 8, sand, r=1))
|
|
303
|
+
out.append(path("M%d %dA6 9 0 0 1 %d %dZ" % (x - 6, y, x + 6, y), shade))
|
|
304
|
+
out.append(line(x, y - 50, x, y - 72, 0x7A5440, 1.6))
|
|
305
|
+
out.append(path(pts([(x, y - 72), (x + 15, y - 67), (x, y - 62)], True), 0xE4513D))
|
|
306
|
+
return b"".join(out)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _snowman(x, y):
|
|
310
|
+
return (
|
|
311
|
+
ellipse(x, y + 1, 26, 5, 0x6E97B2, opacity=0.35)
|
|
312
|
+
+ circle(x, y - 14, 17, 0xFFFFFF)
|
|
313
|
+
+ circle(x, y - 38, 12, 0xFFFFFF)
|
|
314
|
+
+ circle(x - 5, y - 13, 15, 0xDCE7F1, opacity=0.6)
|
|
315
|
+
+ circle(x + 2, y - 15, 15, 0xFFFFFF)
|
|
316
|
+
+ circle(x - 4, y - 41, 1.6, 0x2B2B33)
|
|
317
|
+
+ circle(x + 4, y - 41, 1.6, 0x2B2B33)
|
|
318
|
+
+ path(pts([(x, y - 38), (x + 12, y - 35), (x, y - 34)], True), 0xF58B2A)
|
|
319
|
+
+ limb(x - 11, y - 28, x + 12, y - 27, 0.2, 5, 5, 0xE4513D)
|
|
320
|
+
+ limb(x + 8, y - 27, x + 13, y - 14, 0, 5, 4, 0xE4513D)
|
|
321
|
+
+ line(x - 16, y - 20, x - 32, y - 32, 0x5B3B2E, 1.8)
|
|
322
|
+
+ line(x + 16, y - 20, x + 31, y - 34, 0x5B3B2E, 1.8)
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def _drift(season_name, night, rng):
|
|
327
|
+
"""What the air carries: petals, leaves, snow, or fireflies at night."""
|
|
328
|
+
out = []
|
|
329
|
+
if season_name == "winter":
|
|
330
|
+
for _ in range(90):
|
|
331
|
+
out.append(circle(rng.between(0, W), rng.between(0, H), rng.between(1.2, 3.4), 0xFFFFFF, opacity=rng.between(0.6, 1)))
|
|
332
|
+
elif season_name in ("spring", "autumn"):
|
|
333
|
+
colors = (0xFFA9C4, 0xFFD3E0, 0xFFFFFF) if season_name == "spring" else (0xFFC83D, 0xF58B2A, 0xC9482B)
|
|
334
|
+
for _ in range(26):
|
|
335
|
+
x, y = rng.between(380, 800), rng.between(140, 470)
|
|
336
|
+
color = _dim(colors[int(rng.between(0, 2.99))], night)
|
|
337
|
+
out.append(ellipse(x, y, rng.between(3, 5.5), rng.between(1.6, 2.6), color, rot=rng.between(0, 180)))
|
|
338
|
+
if night and season_name != "winter":
|
|
339
|
+
for _ in range(14):
|
|
340
|
+
x, y = rng.between(430, 790), rng.between(250, 450)
|
|
341
|
+
out.append(circle(x, y, 7, 0xE8FF8A, opacity=0.18))
|
|
342
|
+
out.append(circle(x, y, 3.4, 0xE8FF8A, opacity=0.35))
|
|
343
|
+
out.append(circle(x, y, 1.5, 0xFDFFE0))
|
|
344
|
+
return b"".join(out)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
# The chameleon in each season: his colour scheme, what he holds, his pose.
|
|
348
|
+
_HUEY = {
|
|
349
|
+
"spring": ("blossom", "flower", {"mood": "happy", "look": (0.6, -0.3), "look_far": (-0.5, 0.2)}),
|
|
350
|
+
"summer": ("leaf", "plane", {"mood": "calm", "look": (0.7, -0.4), "look_far": (0.2, 0.5)}),
|
|
351
|
+
"autumn": ("sunset", "sparkler", {"mood": "happy", "look": (0.8, -0.6), "look_far": (-0.6, -0.5)}),
|
|
352
|
+
"winter": ("snow", "mug", {"mood": "happy", "look": (0.3, 0.2)}),
|
|
353
|
+
"night": ("night", "lantern", {"mood": "calm", "look": (0.8, -0.2), "look_far": (0.1, -0.8)}),
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
_WOOD = 0xCFC2AC
|
|
357
|
+
_WOOD_SHADE = 0x9D8D78
|
|
358
|
+
_WOOD_LIGHT = 0xEEE5D3
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _shape(x, y, s, d):
|
|
362
|
+
"""Path data written in a drawing's own units, placed at (x, y) and scaled by *s*.
|
|
363
|
+
|
|
364
|
+
Capital letters are points measured from (x, y); small ones are steps.
|
|
365
|
+
"""
|
|
366
|
+
out, moved = [], False
|
|
367
|
+
for token in d.replace("M", " M ").replace("L", " L ").replace("Q", " Q ").replace("Z", " Z ").replace("l", " l ").replace("q", " q ").split():
|
|
368
|
+
if token in "MLQZlq":
|
|
369
|
+
out.append(token)
|
|
370
|
+
moved = token in "lq"
|
|
371
|
+
flip = 0
|
|
372
|
+
else:
|
|
373
|
+
v = float(token) * s
|
|
374
|
+
if not moved:
|
|
375
|
+
v += y if flip else x
|
|
376
|
+
out.append("%.1f" % v)
|
|
377
|
+
flip ^= 1
|
|
378
|
+
return " ".join(out)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _driftwood(x, y, s, night):
|
|
382
|
+
"""A sea-bleached bough propped on the sand, its top where the chameleon's perch is."""
|
|
383
|
+
wood, shade, light = _dim(_WOOD, night), _dim(_WOOD_SHADE, night), _dim(_WOOD_LIGHT, night)
|
|
384
|
+
stone, stone_shade, stone_light = _dim(0x9AA5AE, night), _dim(0x74808C, night), _dim(0xC3CCD3, night)
|
|
385
|
+
top = y + 8 * s
|
|
386
|
+
left, right = x - 262 * s, x + 262 * s
|
|
387
|
+
out = [
|
|
388
|
+
ellipse(x - 30 * s, y + 80 * s, 240 * s, 14 * s, 0x000000, opacity=0.16),
|
|
389
|
+
# its near end is propped on two beach stones, and its far end rests on the dune
|
|
390
|
+
path(_shape(left, top, s, "M-34 86Q-46 52 -14 30L44 18Q92 30 100 86Z"), stone),
|
|
391
|
+
path(_shape(left, top, s, "M-34 86Q-46 52 -14 30L6 26Q-8 58 14 86Z"), stone_shade),
|
|
392
|
+
path(_shape(left, top, s, "M44 18Q92 30 100 86L84 86Q78 44 36 30Z"), stone_light),
|
|
393
|
+
path(_shape(left, top, s, "M10 58l22 -8M52 66l18 6"), None, stone_shade, 2.2 * s),
|
|
394
|
+
path(_shape(left, top, s, "M96 88Q98 62 122 58Q148 60 152 88Z"), stone),
|
|
395
|
+
path(_shape(left, top, s, "M96 88Q98 62 122 58Q112 72 116 88Z"), stone_shade),
|
|
396
|
+
# the bough
|
|
397
|
+
limb(left, top + 8 * s, right + 40 * s, top - 2 * s, 0.014, 40 * s, 20 * s, wood),
|
|
398
|
+
path("M%.1f %.1fQ%.1f %.1f %.1f %.1f" % (left + 16 * s, top + 21 * s, x, top + 22 * s, right + 10 * s, top + 7 * s), None, shade, 6 * s),
|
|
399
|
+
path("M%.1f %.1fQ%.1f %.1f %.1f %.1f" % (left + 30 * s, top - 4 * s, x - 60 * s, top - 6 * s, x + 40 * s, top - 7 * s), None, light, 3.2 * s),
|
|
400
|
+
path("M%.1f %.1fq%.1f %.1f %.1f 0" % (x - 150 * s, top + 8 * s, 14 * s, -5 * s, 30 * s), None, shade, 2 * s),
|
|
401
|
+
path("M%.1f %.1fq%.1f %.1f %.1f 0" % (x + 60 * s, top + 4 * s, 12 * s, 4 * s, 26 * s), None, shade, 2 * s),
|
|
402
|
+
# a snapped side branch, and the rings of the cut end
|
|
403
|
+
limb(right - 80 * s, top - 6 * s, right - 30 * s, top - 56 * s, 0.14, 14 * s, 6 * s, wood),
|
|
404
|
+
limb(left + 90 * s, top + 16 * s, left + 120 * s, top + 44 * s, -0.1, 12 * s, 5 * s, shade),
|
|
405
|
+
ellipse(left - 2 * s, top + 8 * s, 11 * s, 19 * s, light),
|
|
406
|
+
ellipse(left - 2 * s, top + 8 * s, 6.5 * s, 12 * s, None, shade, 1.6 * s),
|
|
407
|
+
ellipse(left - 2 * s, top + 8 * s, 2 * s, 4 * s, shade),
|
|
408
|
+
]
|
|
409
|
+
return b"".join(out)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def draw(doc, season="summer", night=False, pose=None, colors=None, drift=True, who="chameleon", huey_at=(322, 404), huey_scale=0.6):
|
|
413
|
+
"""Add the coast to *doc*.
|
|
414
|
+
|
|
415
|
+
Args:
|
|
416
|
+
doc: The `vec.Doc` to draw into.
|
|
417
|
+
season (str): "spring", "summer", "autumn" or "winter".
|
|
418
|
+
night (bool): The same place after dark, the lighthouse lit.
|
|
419
|
+
pose (dict): Arguments for `huey.draw`, over the season's own.
|
|
420
|
+
colors (str): The chameleon's scheme, or None for the season's own.
|
|
421
|
+
drift (bool): Draw what the air carries: petals, leaves, snow, fireflies.
|
|
422
|
+
who (str): "chameleon", on a driftwood bough, "stage" for the bough alone,
|
|
423
|
+
or None for the place without either.
|
|
424
|
+
huey_at: Where the chameleon's perch is.
|
|
425
|
+
huey_scale (float): The chameleon's size.
|
|
426
|
+
"""
|
|
427
|
+
s = SEASONS[season]
|
|
428
|
+
staged = who in ("chameleon", "stage")
|
|
429
|
+
rng = _Random(101)
|
|
430
|
+
add = doc.add
|
|
431
|
+
add(_sky(s, night))
|
|
432
|
+
cloud = tuple(_dim(c, night) for c in s["cloud"])
|
|
433
|
+
if not night:
|
|
434
|
+
add(_cloud(170, 86, 1.0, cloud), _cloud(400, 54, 0.62, cloud), _cloud(716, 168, 0.8, cloud))
|
|
435
|
+
else:
|
|
436
|
+
add(group(_cloud(210, 120, 0.9, cloud), opacity=0.5))
|
|
437
|
+
add(_sea(s, night))
|
|
438
|
+
add(_headland(s, night, night))
|
|
439
|
+
ink = _dim(0x2B3A4B, night)
|
|
440
|
+
if season == "summer" and not night:
|
|
441
|
+
add(_sailboat(396, HORIZON + 4, night))
|
|
442
|
+
if not night:
|
|
443
|
+
add(_gull(300, 130, 1.0, ink), _gull(332, 116, 0.7, ink), _gull(268, 150, 0.6, ink))
|
|
444
|
+
add(_shore(s, night))
|
|
445
|
+
add(_dune(s, night))
|
|
446
|
+
add(_tree(s, night, 676, 306))
|
|
447
|
+
light, sand, wet = (_dim(c, night) for c in s["sand"])
|
|
448
|
+
# what lies on the sand
|
|
449
|
+
pebble = 30 if staged else 96
|
|
450
|
+
add(ellipse(pebble, 440, 26, 8, wet), ellipse(pebble - 4, 437, 24, 8, _dim(0x9AA7B4, night)), ellipse(pebble, 434, 9, 3, _dim(0xC3CCD6, night)))
|
|
451
|
+
add(ellipse(470, 462, 9, 3.4, wet), ellipse(52, 468, 6, 2.4, wet), ellipse(246, 470, 5, 2, wet))
|
|
452
|
+
star_x, star_y = (232, 470) if staged else (180, 456)
|
|
453
|
+
if season == "summer":
|
|
454
|
+
add(_sandcastle(118 if staged else 430, 456 if staged else 450, sand, wet))
|
|
455
|
+
add(_starfish(star_x, star_y, 15, _dim(0xF58B2A, night), 20))
|
|
456
|
+
elif season == "spring":
|
|
457
|
+
add(_starfish(star_x, star_y, 15, _dim(0xF27A9B, night), 20))
|
|
458
|
+
for fx, fy, color in ((610, 330, 0xFFFFFF), (628, 352, 0xFFE066), (700, 318, 0xFF8FB1), (756, 332, 0xFFFFFF), (668, 380, 0xFFE066), (736, 392, 0xFF8FB1)):
|
|
459
|
+
add(line(fx, fy, fx + 1, fy - 12, _dim(0x5E9E3E, night), 1.6))
|
|
460
|
+
for i in range(5):
|
|
461
|
+
a = i * 1.2566
|
|
462
|
+
add(circle(fx + 1 + math.cos(a) * 3.6, fy - 13 + math.sin(a) * 3.6, 2.6, _dim(color, night)))
|
|
463
|
+
add(circle(fx + 1, fy - 13, 2, _dim(0xF5A623, night)))
|
|
464
|
+
elif season == "autumn":
|
|
465
|
+
add(_starfish(star_x, star_y, 15, _dim(0xC9482B, night), 20))
|
|
466
|
+
for _ in range(16):
|
|
467
|
+
add(ellipse(rng.between(520, 790), rng.between(330, 470), 5.5, 2.6, _dim((0xFFC83D, 0xF58B2A, 0xC9482B)[int(rng.between(0, 2.99))], night), rot=rng.between(0, 180)))
|
|
468
|
+
else:
|
|
469
|
+
add(_snowman(112 if staged else 500, 458 if staged else 452))
|
|
470
|
+
if who in ("chameleon", "stage"):
|
|
471
|
+
add(_driftwood(huey_at[0], huey_at[1], huey_scale, night))
|
|
472
|
+
if who == "chameleon":
|
|
473
|
+
scheme, prop, default = _HUEY["night" if night else season]
|
|
474
|
+
options = dict(default)
|
|
475
|
+
options.update(pose or {})
|
|
476
|
+
body = huey_props.hold(doc, prop, perch=None, colors=colors or scheme, **options)
|
|
477
|
+
add(at(huey_at[0], huey_at[1], body, scale=huey_scale))
|
|
478
|
+
if drift:
|
|
479
|
+
add(_drift(season, night, rng))
|