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.
Files changed (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/perch/huey.py ADDED
@@ -0,0 +1,481 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Huey, a chameleon on his perch, drawn from a pose and a set of colours.
5
+
6
+ He sits above the origin: x to the right, y down, the top of the perch at
7
+ y = 0, about 450 units wide and 260 tall. `draw` returns its shapes for a
8
+ `vec.Doc`. His two eyes look where they like, each on its own.
9
+ """
10
+
11
+ import math
12
+
13
+ from .vec import at, circle, ellipse, group, limb, line, path, rect, smooth
14
+
15
+ NAVY = 0x0B2A4A
16
+ LIME = 0xC4DC4C
17
+ WHITE = 0xFFFFFF
18
+
19
+ # The colours it can take: (skin, shade, light, belly, spots, deep).
20
+ # No two colours of a scheme are the same number, nor the same as a colour
21
+ # drawn whatever the scheme (the lime, white, a glow): a change of scheme
22
+ # redraws a pose by swapping each colour for its counterpart, which needs one
23
+ # to be told from another. Where two would be alike, one is a step away.
24
+ COLORS = {
25
+ "leaf": (0x6FC24B, 0x3E9440, 0xA9E36B, 0xE4F5A8, 0xFFE25A, 0x25663A),
26
+ "brand": (0x3F8FD6, 0x2767AC, 0x7DBBF0, 0xC4DC4D, 0xC5DC4C, 0x1A4A80),
27
+ "sunset": (0xF47C4C, 0xCC4A33, 0xFFB26A, 0xFFE3A6, 0x8A3F78, 0x8E2B2B),
28
+ "board": (0x239468, 0x146B4B, 0x56C492, 0xF4CD52, 0xF4CD53, 0x0C4A35),
29
+ }
30
+
31
+ _CROUCH = 22
32
+ _BARK = 0x7A5440
33
+ _BARK_DARK = 0x5B3B2E
34
+ _BARK_LIGHT = 0x9C7257
35
+
36
+
37
+ def _spiral_points(cx, cy, r0, r1, start, turns, offset0, offset1, t0, t1, steps):
38
+ points = []
39
+ for i in range(steps + 1):
40
+ t = t0 + (t1 - t0) * i / steps
41
+ a = math.radians(start) - t * turns * 2 * math.pi
42
+ # the radius shrinks faster at first, so the coils sit apart
43
+ r = r1 + (r0 - r1) * (1 - t) ** 1.25 + offset0 + (offset1 - offset0) * t
44
+ points.append((cx + math.cos(a) * r, cy + math.sin(a) * r))
45
+ return points
46
+
47
+
48
+ def _spiral(cx, cy, r0, r1, w0, w1, start, turns, fill, steps=40):
49
+ """A tapering tail wound round (cx, cy), from radius r0 in to r1."""
50
+ outer = _spiral_points(cx, cy, r0, r1, start, turns, w0 / 2, w1 / 2, 0, 1, steps)
51
+ inner = _spiral_points(cx, cy, r0, r1, start, turns, -w0 / 2, -w1 / 2, 0, 1, steps)
52
+ inner.reverse()
53
+ tip = ((outer[-1][0] + inner[0][0]) / 2, (outer[-1][1] + inner[0][1]) / 2)
54
+ d = smooth(outer) + "L" + smooth(inner).tail() + "Z"
55
+ return path(d, fill) + circle(tip[0], tip[1], w1 / 2, fill)
56
+
57
+
58
+ def _eye(doc, x, y, r, look, blink, happy, skin, shade, light, deep):
59
+ """A turret eye: a cone of skin with the eye at its tip, turned by *look*."""
60
+ out = [
61
+ circle(x, y, r, shade),
62
+ circle(x + look[0] * r * 0.06, y + look[1] * r * 0.06, r * 0.86, skin),
63
+ # the turret turns: its rings slide toward where it looks
64
+ circle(x + look[0] * r * 0.14, y + look[1] * r * 0.12, r * 0.70, light),
65
+ ]
66
+ ox, oy = x + look[0] * r * 0.20, y + look[1] * r * 0.17
67
+ open_r = r * 0.56
68
+ if happy:
69
+ out.append(circle(ox, oy, open_r, skin))
70
+ out.append(path("M%.2f %.2fQ%.2f %.2f %.2f %.2f" % (ox - open_r * 0.72, oy + open_r * 0.22, ox, oy - open_r * 0.74, ox + open_r * 0.72, oy + open_r * 0.22), None, deep, r * 0.13))
71
+ return b"".join(out)
72
+ if blink >= 0.88:
73
+ out.append(circle(ox, oy, open_r, skin))
74
+ out.append(path("M%.2f %.2fQ%.2f %.2f %.2f %.2f" % (ox - open_r * 0.8, oy, ox, oy + open_r * 0.34, ox + open_r * 0.8, oy), None, deep, r * 0.11))
75
+ return b"".join(out)
76
+ out.append(circle(ox, oy, open_r + r * 0.07, deep))
77
+ white = doc.radial([(0, WHITE), (0.8, 0xF4F7FB), (1, 0xD3DCE8)])
78
+ out.append(circle(ox, oy, open_r, white))
79
+ pr = open_r * 0.62
80
+ # a heavy lid pushes the gaze down
81
+ px, py = ox + look[0] * open_r * 0.30, oy + look[1] * open_r * 0.28 + blink * open_r * 0.42
82
+ iris = doc.radial([(0, 0x1F5E8F), (0.75, NAVY), (1, 0x061A30)], cx=0.5, cy=0.62)
83
+ out.append(circle(px, py, pr, iris))
84
+ out.append(circle(px - pr * 0.36, py - pr * 0.40, pr * 0.30, WHITE))
85
+ out.append(circle(px + pr * 0.38, py + pr * 0.36, pr * 0.13, WHITE, opacity=0.8))
86
+ if blink > 0:
87
+ # the lid: a cap of skin drawn down over the top of the eye
88
+ lr = open_r + r * 0.07
89
+ drop = -lr + 2 * lr * blink
90
+ half = math.sqrt(max(lr * lr - drop * drop, 0))
91
+ out.append(
92
+ path(
93
+ "M%.2f %.2fA%.2f %.2f 0 %d 1 %.2f %.2fQ%.2f %.2f %.2f %.2fZ" % (ox - half, oy + drop, lr, lr, 1 if drop > 0 else 0, ox + half, oy + drop, ox, oy + drop + lr * 0.16, ox - half, oy + drop),
94
+ skin,
95
+ )
96
+ )
97
+ out.append(path("M%.2f %.2fQ%.2f %.2f %.2f %.2f" % (ox - half, oy + drop, ox, oy + drop + lr * 0.16, ox + half, oy + drop), None, deep, r * 0.09))
98
+ return b"".join(out)
99
+
100
+
101
+ def _foot(x, y, skin, deep, turn=0):
102
+ # two bundles of toes that close round the perch like tongs; we see the near one
103
+ return at(
104
+ x,
105
+ y,
106
+ ellipse(-7, 3, 9, 12, skin, rot=14) + ellipse(8, 3, 9, 12, skin, rot=-14) + ellipse(0, -4, 13, 9, skin) + line(0.5, 2, 0.5, 12, deep, 2.2),
107
+ rot=turn,
108
+ )
109
+
110
+
111
+ def _hand(x, y, skin, deep, turn):
112
+ # the raised hand, his two bundles of toes spread in a wave
113
+ return at(
114
+ x,
115
+ y,
116
+ limb(0, 0, -11, -20, 0.2, 15, 11, skin) + limb(0, 0, 13, -19, -0.2, 15, 11, skin) + circle(0, 0, 10, skin) + line(0, -5, 0.5, -12, deep, 2),
117
+ rot=turn,
118
+ )
119
+
120
+
121
+ def _perch(kind):
122
+ out = []
123
+ if kind == "stem":
124
+ # a green stem, long enough to climb
125
+ out.append(limb(-360, 9, 360, 7, 0.004, 16, 12, 0x4F9A3A))
126
+ out.append(path("M-350 4Q0 6 350 2", None, 0x8CC152, 3))
127
+ for x, turn, flip in ((-250, -150, False), (-236, 150, True), (236, -40, False), (286, 36, True)):
128
+ leaf = path("M0 0C14 -22 44 -26 58 -8C40 6 14 8 0 0Z", 0x3F8F3A) + path("M0 0C14 -22 44 -26 58 -8C36 -12 16 -8 0 0Z", 0x6FC24B)
129
+ out.append(at(x, 8, leaf, rot=turn, flip=flip))
130
+ return b"".join(out)
131
+ if kind == "wire":
132
+ # a jumper wire, pulled tight between two pins
133
+ out.append(path("M-232 8Q0 16 232 6", None, 0xC8452F, 11))
134
+ out.append(path("M-200 4Q0 12 200 2", None, 0xF07A5C, 2.5))
135
+ for x, y, turn in ((-232, 8, 2), (232, 6, -2)):
136
+ out.append(at(x, y, rect(-22, -8, 44, 16, 0x2B2B33, r=3) + rect(-18, -5, 30, 3, 0x4A4A55, r=1.5), rot=turn))
137
+ out.append(rect(-270, 5.5, 20, 5, 0xD9DEE6, r=2))
138
+ out.append(rect(250, 3.5, 20, 5, 0xD9DEE6, r=2))
139
+ return b"".join(out)
140
+ out.append(limb(120, 6, 204, -36, 0.12, 9, 5, _BARK_DARK))
141
+ out.append(limb(-236, 12, 240, 5, 0.012, 19, 13, _BARK))
142
+ out.append(path("M-226 15Q0 22 236 9", None, _BARK_DARK, 4, opacity=0.8))
143
+ out.append(path("M-190 5Q-60 7 60 3", None, _BARK_LIGHT, 2.6))
144
+ out.append(path("M110 2Q160 0 214 1", None, _BARK_LIGHT, 2.2))
145
+ # a leaf or two at the tip of the side shoot
146
+ out.append(at(204, -37, path("M0 0C14 -22 44 -26 58 -8C40 6 14 8 0 0Z", 0x5E9E3E) + path("M0 0C14 -22 44 -26 58 -8C36 -12 16 -8 0 0Z", 0x8CC152) + path("M2 -1Q28 -12 54 -8", None, 0x3F7D32, 1.6), rot=-28))
147
+ out.append(at(170, -19, path("M0 0C8 -14 26 -16 34 -5C22 4 8 5 0 0Z", 0x5E9E3E) + path("M0 0C8 -14 26 -16 34 -5C20 -7 9 -5 0 0Z", 0x8CC152), rot=-96))
148
+ return b"".join(out)
149
+
150
+
151
+ _HIP = (-78, -70)
152
+ _NECK = (62, -128)
153
+
154
+
155
+ _kept_text = {}
156
+
157
+
158
+ def _kept(key, make):
159
+ """Text built once for *key* and kept: the parts of a pose that are the
160
+ same from one pose to the next cost their arithmetic only the first time."""
161
+ text = _kept_text.get(key)
162
+ if text is None:
163
+ if len(_kept_text) >= 12:
164
+ _kept_text.clear()
165
+ text = _kept_text[key] = make()
166
+ return text
167
+
168
+
169
+ def _trunk(colors, curl, tail):
170
+ """The tail, the crest and the body: everything behind the head."""
171
+ skin, shade, light, belly, spots, deep = COLORS[colors]
172
+ out = []
173
+ if tail:
174
+ # the tail, wound like a watch spring behind him
175
+ turns = 1.25 + 0.3 * curl
176
+ tx, ty = -160, -96
177
+ out.append(limb(-86, -110, tx + 43, ty - 36, 0.10, 46, 32, skin))
178
+ out.append(_spiral(tx, ty, 56, 8, 32, 8, -40, turns, skin))
179
+ out.append(path(smooth(_spiral_points(tx, ty, 56, 8, -40, turns, -10, -2, 0.04, 0.9, 36)), None, shade, 4.5))
180
+ out.append(path(smooth(_spiral_points(tx, ty, 56, 8, -40, turns, 8, 2, 0.02, 0.42, 20)), None, light, 3))
181
+
182
+ # the crest along the back: a row of soft scallops
183
+ back = ((-104, -126, 8), (-86, -144, 9), (-64, -158, 9.5), (-40, -168, 10), (-15, -174, 10), (10, -175, 10), (34, -171, 9.5))
184
+ for bx, by, r in back:
185
+ out.append(circle(bx, by, r, deep))
186
+
187
+ # the body
188
+ out.append(path(smooth([(-118, -104), (-74, -154), (-6, -172), (56, -158), (92, -116), (84, -64), (30, -42), (-42, -42), (-100, -58)], True), skin))
189
+ # shade under the back's curve, and the pale belly
190
+ out.append(path(smooth([(-116, -98), (-106, -66), (-50, -52), (30, -52), (84, -72), (84, -62), (30, -42), (-42, -42), (-102, -58)], True), shade))
191
+ out.append(path(smooth([(-92, -62), (-44, -51), (28, -50), (74, -64), (62, -50), (26, -43), (-42, -43), (-88, -54)], True), belly))
192
+ # bands down his sides, and a line of spots
193
+ for sx, sy, lean in ((-70, -146, -10), (-30, -160, -4), (12, -162, 4)):
194
+ out.append(limb(sx, sy, sx + lean, sy + 62, 0.16, 15, 5, shade))
195
+ for sx, sy, r in ((-88, -98, 5), (-50, -92, 6.5), (-9, -90, 7), (32, -94, 6), (-70, -76, 3.5), (-30, -72, 4), (12, -72, 4)):
196
+ out.append(circle(sx, sy, r, spots))
197
+ out.append(path(smooth([(-52, -160), (-10, -169), (36, -164), (58, -152), (30, -158), (-10, -162)], True), light))
198
+
199
+ return b"".join(out)
200
+
201
+
202
+ def _skull(colors):
203
+ """The head without its eyes and mouth: the helmet, its casque and the jaw."""
204
+ skin, shade, light, belly, spots, deep = COLORS[colors]
205
+ head = []
206
+ # the head: a helmet with its casque at the back
207
+ head.append(path(smooth([(52, -112), (42, -160), (58, -214), (86, -240), (118, -222), (156, -178), (184, -144), (178, -116), (128, -92), (76, -94)], True), skin))
208
+ head.append(path(smooth([(50, -124), (42, -162), (58, -214), (86, -240), (74, -206), (64, -160), (62, -122)], True), shade))
209
+ head.append(limb(90, -232, 112, -204, -0.08, 7, 2.5, light))
210
+ # the lower jaw, pale like the belly
211
+ head.append(path(smooth([(90, -116), (134, -111), (180, -128), (182, -118), (170, -104), (128, -91), (82, -95)], True), belly))
212
+ return b"".join(head)
213
+
214
+
215
+ def _upper(doc, colors, look, look_far, blink, mood, curl=1.0, nod=0, tongue=0, target=None, tail=True):
216
+ """Tail, body and head, in the units they were drawn in, before the crouch."""
217
+ skin, shade, light, belly, spots, deep = COLORS[colors]
218
+ happy = mood == "happy"
219
+ out = [_kept(("trunk", colors, curl, tail), lambda: _trunk(colors, curl, tail))]
220
+
221
+ head = []
222
+ # the far eye, half hidden behind the brow
223
+ head.append(_eye(doc, 150, -190, 28, look_far, blink, happy, skin, shade, light, deep))
224
+ head.append(_kept(("skull", colors), lambda: _skull(colors)))
225
+ if tongue > 0:
226
+ # the mouth open, and the tongue on its way to the target
227
+ gx, gy = target if target else (360, -128)
228
+ ex, ey = 176 + (gx - 176) * tongue, -122 + (gy + 122) * tongue
229
+ head.append(path("M92 -120Q138 -108 182 -132Q180 -108 152 -100Q112 -97 92 -120Z", deep))
230
+ head.append(limb(150, -112, ex, ey, 0.03, 13, 8, 0xFF8F8F))
231
+ head.append(circle(ex, ey, 13, 0xFF8F8F))
232
+ head.append(circle(ex + 3, ey - 5, 4, 0xFFC0C0))
233
+ head.append(path("M92 -120Q84 -123 84 -131", None, deep, 4))
234
+ elif happy:
235
+ # a wide open grin
236
+ head.append(path("M90 -121Q138 -104 182 -131Q176 -104 150 -99Q112 -96 90 -121Z", deep))
237
+ head.append(path("M118 -104Q140 -110 162 -104Q140 -98 118 -104Z", 0xFF8F8F))
238
+ head.append(path("M90 -121Q84 -124 84 -132", None, deep, 4))
239
+ else:
240
+ head.append(path("M181 -130Q138 -106 92 -119Q84 -122 84 -131", None, deep, 4))
241
+ if mood == "curious" and tongue <= 0:
242
+ # the tip of his tongue, tasting the air
243
+ head.append(limb(178, -127, 214, -124, 0.10, 7, 6, 0xFF8F8F))
244
+ head.append(circle(217, -124, 8.5, 0xFF8F8F))
245
+ head.append(circle(219, -127, 2.6, 0xFFC0C0))
246
+ head.append(path("M181 -130Q170 -124 160 -119", None, deep, 4))
247
+ head.append(circle(170, -148, 2.4, deep))
248
+ # the near eye
249
+ head.append(_eye(doc, 110, -164, 39, look, blink, happy, skin, shade, light, deep))
250
+ head = b"".join(head)
251
+ if nod:
252
+ head = group(head, "rotate(%.2f %d %d)" % (nod, _NECK[0], _NECK[1]))
253
+ out.append(head)
254
+ return b"".join(out)
255
+
256
+
257
+ def _gait(phase):
258
+ """A foot's place in its stride: ``(forward, lift)`` for a phase from 0 to 1."""
259
+ phase = phase % 1.0
260
+ if phase < 0.6:
261
+ # on the perch, carried back as the body moves on
262
+ return 19 * (1 - 2 * phase / 0.6), 0.0
263
+ q = (phase - 0.6) / 0.4
264
+ return -19 + 38 * q, math.sin(q * math.pi) * 18
265
+
266
+
267
+ def grip(hand=1.0):
268
+ """Where the raised hand holds something, ``(x, y, turn)``.
269
+
270
+ The point is the palm between its two bundles of toes, in the units
271
+ `draw` uses, and the turn is the hand's in degrees: a prop drawn pointing
272
+ up from its own origin, placed there and turned so, stands in the hand.
273
+ """
274
+ return 78 + 76 * hand, -8 - 40 * hand, 38
275
+
276
+
277
+ def draw(doc, look=(0.5, 0.1), look_far=None, blink=0, mood="calm", colors="leaf", hand=0, curl=1.0, perch="twig", step=None, nod=0, tongue=0, target=None):
278
+ """The chameleon's shapes, back to front.
279
+
280
+ Args:
281
+ doc: The `vec.Doc` that holds the gradients.
282
+ look: Where the near eye points, each of x and y from -1 to 1.
283
+ look_far: Where the far eye points, or None for the same way.
284
+ blink (float): 0 with the eyes open, 1 closed.
285
+ mood (str): "calm", "happy", "curious" or "sleepy".
286
+ colors (str): A name from `COLORS`.
287
+ hand (float): 0 with both hands on the perch, 1 with one raised in a wave.
288
+ curl (float): How tightly the tail is wound: 0 loose, 1 at rest, 2 tight.
289
+ perch (str): "twig", "wire", "stem", or None for no perch.
290
+ step (float): Where he is in his walk, 0 to 1 and round again, or None standing.
291
+ nod (float): The head's tilt in degrees, positive chin down.
292
+ tongue (float): 0 with the tongue in, 1 with it shot out to *target*.
293
+ target: Where the tongue strikes, ``(x, y)`` in the head's own units.
294
+ """
295
+ skin, shade, light, belly, spots, deep = COLORS[colors]
296
+ if look_far is None:
297
+ look_far = look
298
+ if mood == "sleepy":
299
+ blink = max(blink, 0.5)
300
+ # the four feet: near front, far front, near hind, far hind, each (forward, lift)
301
+ if step is None:
302
+ nf = ff = nh = fh = (0, 0)
303
+ sway, bob = 0, 0
304
+ else:
305
+ # diagonal pairs move together, and the body rocks twice a stride
306
+ nf, fh = _gait(step), _gait(step + 0.04)
307
+ ff, nh = _gait(step + 0.5), _gait(step + 0.54)
308
+ sway = 4 * math.sin(step * 4 * math.pi)
309
+ bob = 2 * math.cos(step * 4 * math.pi)
310
+ out = []
311
+ # far legs
312
+ out.append(limb(92 + sway, -58 + bob, 116 + ff[0], -8 - ff[1], -0.22, 24, 17, shade))
313
+ out.append(limb(-92 + sway, -48 + bob, -92 + fh[0], -8 - fh[1], 0.28, 26, 17, shade))
314
+ out.append(at(sway, _CROUCH + bob, _upper(doc, colors, look, look_far, blink, mood, curl, nod, tongue, target)))
315
+ # near hind leg, folded
316
+ kx, ky = -42 + nh[0] * 0.6 + sway * 0.4, -24 - nh[1] * 0.5
317
+ out.append(limb(-70 + sway, -46 + bob, kx, ky, 0.34, 34, 23, skin))
318
+ out.append(limb(kx, ky - 2, -56 + nh[0], -6 - nh[1], 0.22, 21, 17, skin))
319
+ if perch:
320
+ out.append(_perch(perch))
321
+
322
+ # feet over the perch
323
+ out.append(_foot(118 + ff[0], 2 - ff[1], shade, deep, -ff[1]))
324
+ out.append(_foot(-92 + fh[0], 4 - fh[1], shade, deep, -fh[1]))
325
+ out.append(_foot(-58 + nh[0], 4 - nh[1], skin, deep, -nh[1]))
326
+ # the near arm: on the perch, or raised in a wave
327
+ sx, sy = 60 + sway, -56 + bob
328
+ if hand > 0:
329
+ hx, hy, turn = grip(hand)
330
+ out.append(limb(sx, sy, hx, hy, -0.26 + 0.1 * hand, 28, 16, skin))
331
+ if hand > 0.5:
332
+ out.append(_hand(hx, hy, skin, deep, turn))
333
+ else:
334
+ out.append(_foot(hx, hy + 8, skin, deep))
335
+ else:
336
+ out.append(limb(sx, sy, 78 + nf[0], -10 - nf[1], -0.26, 28, 17, skin))
337
+ out.append(_foot(80 + nf[0], 3 - nf[1], skin, deep, -nf[1]))
338
+ out.append(circle(sx, sy - 2, 15, skin))
339
+ out.append(path("M%.1f %.1fq10 9 24 3" % (sx - 12, sy + 10), None, shade, 3.5))
340
+ return b"".join(out)
341
+
342
+
343
+ def _turned(point, turn, hip):
344
+ """Where a point of the body lands when the body turns about its hip to stand at *hip*."""
345
+ a = math.radians(turn)
346
+ x, y = point[0] - _HIP[0], point[1] - _HIP[1]
347
+ return hip[0] + x * math.cos(a) - y * math.sin(a), hip[1] + x * math.sin(a) + y * math.cos(a)
348
+
349
+
350
+ def _body_at(body, turn, hip):
351
+ return group(body, "translate(%.2f %.2f) rotate(%.2f) translate(%d %d)" % (hip[0], hip[1], turn, -_HIP[0], -_HIP[1]))
352
+
353
+
354
+ def draw_sit(doc, look=(0.0, 0.0), look_far=None, blink=0, mood="calm", colors="leaf", perch="twig", wave=0.0):
355
+ """Sitting up on his haunches, both hands free: how he idles on a desktop.
356
+
357
+ Args:
358
+ wave (float): 0 with the near hand held out, 1 with it lifted in a wave.
359
+ The others are as in `draw`.
360
+ """
361
+ skin, shade, light, belly, spots, deep = COLORS[colors]
362
+ if look_far is None:
363
+ look_far = look
364
+ if mood == "sleepy":
365
+ blink = max(blink, 0.5)
366
+ turn, hip = -52, (-36, -44)
367
+ out = []
368
+ # the tail, wound up on the perch behind him
369
+ tx, ty = -150, -58
370
+ out.append(limb(-62, -52, tx + 46, ty + 2, -0.12, 46, 32, skin))
371
+ out.append(_spiral(tx, ty, 46, 7, 30, 8, 0, 1.55, skin))
372
+ out.append(path(smooth(_spiral_points(tx, ty, 46, 7, 0, 1.55, -9, -2, 0.04, 0.9, 36)), None, shade, 4.5))
373
+ out.append(path(smooth(_spiral_points(tx, ty, 46, 7, 0, 1.55, 8, 2, 0.1, 0.5, 20)), None, light, 3))
374
+ # far limbs
375
+ fx, fy = _turned((84, -80), turn, hip)
376
+ out.append(limb(fx, fy, fx + 52, fy + 34, 0.22, 24, 15, shade))
377
+ out.append(_hand(fx + 52, fy + 34, shade, deep, 100))
378
+ out.append(limb(-16, -30, 44, -8, -0.2, 26, 18, shade))
379
+ out.append(_body_at(_upper(doc, colors, look, look_far, blink, mood, nod=46, tail=False), turn, hip))
380
+ # the near haunch, folded under him
381
+ out.append(ellipse(-26, -40, 38, 29, skin, rot=-24))
382
+ out.append(path("M-56 -30Q-30 -6 4 -22", None, shade, 3.5))
383
+ out.append(limb(-6, -24, 16, -8, -0.2, 22, 17, skin))
384
+ if perch:
385
+ out.append(_perch(perch))
386
+ out.append(_foot(46, 3, shade, deep))
387
+ out.append(_foot(18, 4, skin, deep))
388
+ # the near arm, held out or waving
389
+ sx, sy = _turned((60, -78), turn, hip)
390
+ hx, hy = sx + 58 + 40 * wave, sy + 30 - 22 * wave
391
+ out.append(limb(sx, sy, hx, hy, 0.26 - 0.06 * wave, 27, 16, skin))
392
+ out.append(_hand(hx, hy, skin, deep, 70 - 34 * wave))
393
+ out.append(circle(sx, sy, 14, skin))
394
+ return b"".join(out)
395
+
396
+
397
+ def draw_sleep(doc, colors="leaf", perch="twig"):
398
+ """Asleep on the perch: belly down, chin on his hand, tail wound tight."""
399
+ skin, shade, light, belly, spots, deep = COLORS[colors]
400
+ out = []
401
+ out.append(limb(96, -30, 112, -8, -0.2, 22, 17, shade))
402
+ out.append(at(0, 40, _upper(doc, colors, (0, 0), (0, 0), 1, "calm", curl=2, nod=14)))
403
+ # legs folded away: a haunch and an elbow
404
+ out.append(ellipse(-64, -22, 34, 22, skin, rot=-10))
405
+ out.append(path("M-94 -18Q-66 2 -34 -14", None, shade, 3.5))
406
+ out.append(limb(52, -34, 84, -10, -0.3, 26, 17, skin))
407
+ if perch:
408
+ out.append(_perch(perch))
409
+ out.append(_foot(116, 2, shade, deep))
410
+ out.append(_foot(-36, 4, skin, deep))
411
+ out.append(_foot(88, 3, skin, deep))
412
+ # sleep, rising off him
413
+ for zx, zy, zs, opa in ((206, -128, 1.0, 0.9), (226, -168, 1.35, 0.75), (252, -218, 1.75, 0.6)):
414
+ out.append(path("M%.1f %.1fh%.1fl%.1f %.1fh%.1f" % (zx, zy, 14 * zs, -14 * zs, 16 * zs, 14 * zs), None, LIME, 4.2 * zs ** 0.5, opacity=opa))
415
+ return b"".join(out)
416
+
417
+
418
+ def draw_hang(doc, look=(-0.2, 0.2), look_far=None, mood="happy", colors="leaf", perch="twig", wave=1.0):
419
+ """Hanging head down by his tail and hind feet, hands free.
420
+
421
+ The perch is still at y = 0; the body hangs about 330 units below it.
422
+ """
423
+ skin, shade, light, belly, spots, deep = COLORS[colors]
424
+ if look_far is None:
425
+ look_far = look
426
+ turn, hip = 82, (22, 62)
427
+ out = []
428
+ # the far hind leg, and the tail going up behind the perch
429
+ out.append(limb(hip[0] + 14, hip[1] + 6, -52, 6, 0.2, 26, 17, shade))
430
+ rx, ry = _turned((-108, -106), turn, hip)
431
+ out.append(limb(rx - 8, ry + 14, 96, -14, 0.24, 44, 26, skin))
432
+ # the far arm, dangling
433
+ fx, fy = _turned((84, -80), turn, hip)
434
+ out.append(limb(fx, fy, fx - 62, fy + 30, 0.2, 24, 15, shade))
435
+ out.append(_hand(fx - 62, fy + 30, shade, deep, -150))
436
+ out.append(_body_at(_upper(doc, colors, look, look_far, 0, mood, nod=-34, tail=False), turn, hip))
437
+ # the near hind leg, reaching up to hold on
438
+ out.append(limb(hip[0], hip[1], -18, 6, 0.24, 32, 18, skin))
439
+ if perch:
440
+ out.append(_perch(perch))
441
+ # four turns of tail wound close round the perch, thinning to a curled tip
442
+ for i in range(4):
443
+ cx = 94 + i * 15
444
+ w = 21 - i * 2.5
445
+ out.append(limb(cx - 7, -12, cx + 7, 21, 0, w + 3, w + 2, shade))
446
+ out.append(limb(cx - 8, -12, cx + 5, 21, 0, w, w - 1, skin))
447
+ out.append(limb(cx - 9, -9, cx - 5, 3, 0, 3.5, 2.5, light))
448
+ out.append(path("M150 21q10 9 17 0q5 -9 -4 -12q-7 0 -6 6", None, skin, 7))
449
+ out.append(_foot(-52, 3, shade, deep, 180))
450
+ out.append(_foot(-18, 2, skin, deep, 180))
451
+ # the near arm, thrown wide
452
+ sx, sy = _turned((60, -78), turn, hip)
453
+ hx, hy = sx - 66, sy + 6 - 34 * wave
454
+ out.append(limb(sx, sy, hx, hy, -0.24, 27, 16, skin))
455
+ out.append(_hand(hx, hy, skin, deep, -70 + 30 * wave))
456
+ out.append(circle(sx, sy, 14, skin))
457
+ return b"".join(out)
458
+
459
+
460
+ def _bug(x, y, s=1.0):
461
+ """A small beetle, the kind a chameleon and a programmer both go after."""
462
+ return at(
463
+ x,
464
+ y,
465
+ ellipse(-9, -11, 12, 6, 0xCFE8FF, opacity=0.75, rot=-30)
466
+ + ellipse(9, -11, 12, 6, 0xCFE8FF, opacity=0.75, rot=30)
467
+ + line(-6, 6, -13, 11, 0x2B2B33, 2)
468
+ + line(6, 6, 13, 11, 0x2B2B33, 2)
469
+ + line(0, 8, 0, 14, 0x2B2B33, 2)
470
+ + ellipse(0, 0, 11, 9, 0xE4513D)
471
+ + path("M-11 0A11 9 0 0 1 11 0Z", 0x2B2B33)
472
+ + circle(-4, 3.5, 2, 0x2B2B33)
473
+ + circle(4, 3.5, 2, 0x2B2B33)
474
+ + circle(-4, -4, 1.6, WHITE)
475
+ + circle(4, -4, 1.6, WHITE),
476
+ scale=s,
477
+ )
478
+
479
+
480
+ def _sparkle(x, y, r, color):
481
+ return path("M%.1f %.1fQ%.1f %.1f %.1f %.1fQ%.1f %.1f %.1f %.1fQ%.1f %.1f %.1f %.1fQ%.1f %.1f %.1f %.1fZ" % (x, y - r, x, y, x + r, y, x, y, x, y + r, x, y, x - r, y, x, y, x, y - r), color)