agentcut 0.0.0-stage → 0.1.1

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 (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -2
  3. package/dist/bridge.d.ts +45 -0
  4. package/dist/bridge.js +691 -0
  5. package/dist/bridge.js.map +1 -0
  6. package/dist/config.d.ts +13 -0
  7. package/dist/config.js +50 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +35 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/log.d.ts +1 -0
  13. package/dist/log.js +14 -0
  14. package/dist/log.js.map +1 -0
  15. package/dist/studio/agents/claude.d.ts +7 -0
  16. package/dist/studio/agents/claude.js +155 -0
  17. package/dist/studio/agents/claude.js.map +1 -0
  18. package/dist/studio/agents/codex.d.ts +4 -0
  19. package/dist/studio/agents/codex.js +169 -0
  20. package/dist/studio/agents/codex.js.map +1 -0
  21. package/dist/studio/agents/index.d.ts +8 -0
  22. package/dist/studio/agents/index.js +50 -0
  23. package/dist/studio/agents/index.js.map +1 -0
  24. package/dist/studio/agents/types.d.ts +131 -0
  25. package/dist/studio/agents/types.js +11 -0
  26. package/dist/studio/agents/types.js.map +1 -0
  27. package/dist/studio/bundler.d.ts +29 -0
  28. package/dist/studio/bundler.js +136 -0
  29. package/dist/studio/bundler.js.map +1 -0
  30. package/dist/studio/chat.d.ts +147 -0
  31. package/dist/studio/chat.js +681 -0
  32. package/dist/studio/chat.js.map +1 -0
  33. package/dist/studio/cli.d.ts +2 -0
  34. package/dist/studio/cli.js +194 -0
  35. package/dist/studio/cli.js.map +1 -0
  36. package/dist/studio/components.d.ts +4 -0
  37. package/dist/studio/components.js +36 -0
  38. package/dist/studio/components.js.map +1 -0
  39. package/dist/studio/host.d.ts +105 -0
  40. package/dist/studio/host.js +634 -0
  41. package/dist/studio/host.js.map +1 -0
  42. package/dist/studio/http.d.ts +21 -0
  43. package/dist/studio/http.js +240 -0
  44. package/dist/studio/http.js.map +1 -0
  45. package/dist/studio/music.d.ts +35 -0
  46. package/dist/studio/music.js +130 -0
  47. package/dist/studio/music.js.map +1 -0
  48. package/dist/studio/proc.d.ts +11 -0
  49. package/dist/studio/proc.js +69 -0
  50. package/dist/studio/proc.js.map +1 -0
  51. package/dist/studio/projects.d.ts +84 -0
  52. package/dist/studio/projects.js +369 -0
  53. package/dist/studio/projects.js.map +1 -0
  54. package/dist/studio/render.d.ts +24 -0
  55. package/dist/studio/render.js +197 -0
  56. package/dist/studio/render.js.map +1 -0
  57. package/dist/studio/reveal.d.ts +7 -0
  58. package/dist/studio/reveal.js +49 -0
  59. package/dist/studio/reveal.js.map +1 -0
  60. package/dist/studio/schema.d.ts +4152 -0
  61. package/dist/studio/schema.js +358 -0
  62. package/dist/studio/schema.js.map +1 -0
  63. package/dist/studio/tools.d.ts +2 -0
  64. package/dist/studio/tools.js +165 -0
  65. package/dist/studio/tools.js.map +1 -0
  66. package/dist/studio/voice.d.ts +150 -0
  67. package/dist/studio/voice.js +434 -0
  68. package/dist/studio/voice.js.map +1 -0
  69. package/dist/studio/workspace.d.ts +31 -0
  70. package/dist/studio/workspace.js +187 -0
  71. package/dist/studio/workspace.js.map +1 -0
  72. package/package.json +50 -4
  73. package/template/AGENTS.md +13 -0
  74. package/template/components/CATALOG.md +1306 -0
  75. package/template/components/README.md +61 -0
  76. package/template/components/STYLES.md +246 -0
  77. package/template/components/arcade-title/ArcadeTitle.tsx +860 -0
  78. package/template/components/arcade-title/meta.json +28 -0
  79. package/template/components/aurora/Aurora.tsx +63 -0
  80. package/template/components/aurora/meta.json +28 -0
  81. package/template/components/bar-wipe-title/BarWipeTitle.tsx +94 -0
  82. package/template/components/bar-wipe-title/meta.json +29 -0
  83. package/template/components/before-after/BeforeAfter.tsx +89 -0
  84. package/template/components/before-after/meta.json +233 -0
  85. package/template/components/bento-grid/BentoGrid.tsx +202 -0
  86. package/template/components/bento-grid/meta.json +25 -0
  87. package/template/components/blur-in-title/BlurInTitle.tsx +121 -0
  88. package/template/components/blur-in-title/meta.json +32 -0
  89. package/template/components/catalog.json +8730 -0
  90. package/template/components/catalog.ts +103 -0
  91. package/template/components/chat-thread/ChatThread.tsx +128 -0
  92. package/template/components/chat-thread/meta.json +24 -0
  93. package/template/components/checklist/Checklist.tsx +129 -0
  94. package/template/components/checklist/meta.json +25 -0
  95. package/template/components/confetti/Confetti.tsx +109 -0
  96. package/template/components/confetti/meta.json +28 -0
  97. package/template/components/countdown/Countdown.tsx +166 -0
  98. package/template/components/countdown/meta.json +28 -0
  99. package/template/components/cut-and-paste/CutAndPaste.tsx +654 -0
  100. package/template/components/cut-and-paste/meta.json +29 -0
  101. package/template/components/decode-text/DecodeText.tsx +97 -0
  102. package/template/components/decode-text/meta.json +29 -0
  103. package/template/components/editorial-quote/EditorialQuote.tsx +122 -0
  104. package/template/components/editorial-quote/meta.json +28 -0
  105. package/template/components/glitch-title/GlitchTitle.tsx +171 -0
  106. package/template/components/glitch-title/meta.json +32 -0
  107. package/template/components/halftone-wave/HalftoneWave.tsx +106 -0
  108. package/template/components/halftone-wave/meta.json +28 -0
  109. package/template/components/highlighter/Highlighter.tsx +142 -0
  110. package/template/components/highlighter/meta.json +28 -0
  111. package/template/components/hook-card/HookCard.tsx +552 -0
  112. package/template/components/hook-card/meta.json +304 -0
  113. package/template/components/index.ts +149 -0
  114. package/template/components/iris-wipe/IrisWipe.tsx +76 -0
  115. package/template/components/iris-wipe/meta.json +24 -0
  116. package/template/components/kinetic-poster/KineticPoster.tsx +437 -0
  117. package/template/components/kinetic-poster/meta.json +31 -0
  118. package/template/components/kinetic-punch/KineticPunch.tsx +80 -0
  119. package/template/components/kinetic-punch/meta.json +30 -0
  120. package/template/components/lava-lamp/LavaLamp.tsx +92 -0
  121. package/template/components/lava-lamp/meta.json +28 -0
  122. package/template/components/letter-cascade/LetterCascade.tsx +102 -0
  123. package/template/components/letter-cascade/meta.json +29 -0
  124. package/template/components/lib.ts +179 -0
  125. package/template/components/light-leak/LightLeakTransition.tsx +43 -0
  126. package/template/components/light-leak/meta.json +74 -0
  127. package/template/components/line-diagram/LineDiagram.tsx +205 -0
  128. package/template/components/line-diagram/meta.json +217 -0
  129. package/template/components/list-card/ListCard.tsx +104 -0
  130. package/template/components/list-card/meta.json +232 -0
  131. package/template/components/logo-sting/LogoSting.tsx +129 -0
  132. package/template/components/logo-sting/meta.json +29 -0
  133. package/template/components/looks.tsx +1447 -0
  134. package/template/components/lower-third/LowerThird.tsx +100 -0
  135. package/template/components/lower-third/meta.json +24 -0
  136. package/template/components/marquee/Marquee.tsx +100 -0
  137. package/template/components/marquee/meta.json +30 -0
  138. package/template/components/notification/Notification.tsx +115 -0
  139. package/template/components/notification/meta.json +27 -0
  140. package/template/components/outline-fill/OutlineFill.tsx +106 -0
  141. package/template/components/outline-fill/meta.json +28 -0
  142. package/template/components/panel-sweep/PanelSweep.tsx +86 -0
  143. package/template/components/panel-sweep/meta.json +25 -0
  144. package/template/components/prompt-box/PromptBox.tsx +131 -0
  145. package/template/components/prompt-box/meta.json +24 -0
  146. package/template/components/props.ts +73 -0
  147. package/template/components/quote-card/QuoteCard.tsx +71 -0
  148. package/template/components/quote-card/meta.json +216 -0
  149. package/template/components/shape-shift/ShapeShift.tsx +420 -0
  150. package/template/components/shape-shift/meta.json +31 -0
  151. package/template/components/slide-zoom-message/SlideZoomMessage.tsx +179 -0
  152. package/template/components/slide-zoom-message/meta.json +199 -0
  153. package/template/components/social-post/SocialPost.tsx +185 -0
  154. package/template/components/social-post/meta.json +30 -0
  155. package/template/components/split-flap/SplitFlap.tsx +191 -0
  156. package/template/components/split-flap/meta.json +29 -0
  157. package/template/components/spotlight-grid/SpotlightGrid.tsx +84 -0
  158. package/template/components/spotlight-grid/meta.json +25 -0
  159. package/template/components/stat-counter/StatCounter.tsx +117 -0
  160. package/template/components/stat-counter/meta.json +27 -0
  161. package/template/components/sticker-badge/StickerBadge.tsx +46 -0
  162. package/template/components/sticker-badge/meta.json +220 -0
  163. package/template/components/sticker-slam/StickerSlam.tsx +941 -0
  164. package/template/components/sticker-slam/meta.json +34 -0
  165. package/template/components/style-layer.tsx +233 -0
  166. package/template/components/styles.json +762 -0
  167. package/template/components/styles.ts +113 -0
  168. package/template/components/target-lock/TargetLock.tsx +662 -0
  169. package/template/components/target-lock/meta.json +32 -0
  170. package/template/components/text-reveal/TextReveal.tsx +99 -0
  171. package/template/components/text-reveal/meta.json +28 -0
  172. package/template/components/tile-wipe/TileWipe.tsx +75 -0
  173. package/template/components/tile-wipe/meta.json +24 -0
  174. package/template/components/type-zoom/TypeZoom.tsx +103 -0
  175. package/template/components/type-zoom/meta.json +27 -0
  176. package/template/components/types.ts +66 -0
  177. package/template/components/typewriter/Typewriter.tsx +112 -0
  178. package/template/components/typewriter/meta.json +29 -0
  179. package/template/components/word-pop/WordPop.tsx +59 -0
  180. package/template/components/word-pop/meta.json +237 -0
  181. package/template/components/word-stack/WordStack.tsx +122 -0
  182. package/template/components/word-stack/meta.json +27 -0
  183. package/template/components/word-swap/WordSwap.tsx +127 -0
  184. package/template/components/word-swap/meta.json +30 -0
  185. package/template/presets/charcoal-sketch/PROMPT.md +48 -0
  186. package/template/presets/charcoal-sketch/assets/paper/grain-0.png +0 -0
  187. package/template/presets/charcoal-sketch/assets/paper/grain-1.png +0 -0
  188. package/template/presets/charcoal-sketch/assets/paper/grain-2.png +0 -0
  189. package/template/presets/charcoal-sketch/assets/paper/sketch-paper.jpg +0 -0
  190. package/template/presets/charcoal-sketch/assets/paper/smudge.png +0 -0
  191. package/template/presets/charcoal-sketch/poster.jpg +0 -0
  192. package/template/presets/charcoal-sketch/preset.json +17 -0
  193. package/template/presets/charcoal-sketch/preview.mp4 +0 -0
  194. package/template/presets/charcoal-sketch/scenes/Grain.tsx +23 -0
  195. package/template/presets/charcoal-sketch/scenes/Paper.tsx +17 -0
  196. package/template/presets/charcoal-sketch/scenes/examples/Agents.tsx +100 -0
  197. package/template/presets/charcoal-sketch/scenes/examples/Approvals.tsx +110 -0
  198. package/template/presets/charcoal-sketch/scenes/examples/Blog.tsx +105 -0
  199. package/template/presets/charcoal-sketch/scenes/examples/EndCard.tsx +41 -0
  200. package/template/presets/charcoal-sketch/scenes/examples/Hook.tsx +130 -0
  201. package/template/presets/charcoal-sketch/scenes/examples/Ideas.tsx +92 -0
  202. package/template/presets/charcoal-sketch/scenes/examples/Posting.tsx +128 -0
  203. package/template/presets/charcoal-sketch/scenes/lib/painfix.tsx +119 -0
  204. package/template/presets/charcoal-sketch/scenes/lib/sketch.tsx +291 -0
  205. package/template/presets/charcoal-sketch/scripts/build_layers.example.py +193 -0
  206. package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -0
  207. package/template/presets/charcoal-sketch/scripts/make_textures.py +93 -0
  208. package/template/presets/punk-cut-paper/PROMPT.md +37 -0
  209. package/template/presets/punk-cut-paper/assets/paper/desk-cream.jpg +0 -0
  210. package/template/presets/punk-cut-paper/assets/paper/grain-overlay.png +0 -0
  211. package/template/presets/punk-cut-paper/assets/paper/halftone-black.png +0 -0
  212. package/template/presets/punk-cut-paper/assets/paper/halftone-red.png +0 -0
  213. package/template/presets/punk-cut-paper/assets/paper/halftone-yellow.png +0 -0
  214. package/template/presets/punk-cut-paper/assets/paper/kraft.jpg +0 -0
  215. package/template/presets/punk-cut-paper/assets/paper/newsprint.jpg +0 -0
  216. package/template/presets/punk-cut-paper/assets/paper/paper-cream.jpg +0 -0
  217. package/template/presets/punk-cut-paper/assets/paper/paper-white.jpg +0 -0
  218. package/template/presets/punk-cut-paper/assets/paper/tape.png +0 -0
  219. package/template/presets/punk-cut-paper/build_layers.example.py +150 -0
  220. package/template/presets/punk-cut-paper/poster.jpg +0 -0
  221. package/template/presets/punk-cut-paper/preset.json +15 -0
  222. package/template/presets/punk-cut-paper/preview.mp4 +0 -0
  223. package/template/presets/punk-cut-paper/scenes/Backdrop.tsx +76 -0
  224. package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -0
  225. package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -0
  226. package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -0
  227. package/template/presets/punk-cut-paper/scenes/Xerox.tsx +31 -0
  228. package/template/presets/punk-cut-paper/scenes/lib/punk.tsx +208 -0
  229. package/template/runtime/composition.tsx +920 -0
  230. package/template/runtime/helpers.tsx +228 -0
  231. package/template/runtime/index.tsx +22 -0
  232. package/template/runtime/types.ts +248 -0
  233. package/template/skill/SKILL.md +149 -0
  234. package/template/skill/references/browser-export.md +61 -0
  235. package/template/skill/references/components.md +38 -0
  236. package/template/skill/references/craft.md +53 -0
  237. package/template/skill/references/cursor.md +91 -0
  238. package/template/skill/references/footage.md +73 -0
  239. package/template/skill/references/format.md +140 -0
  240. package/template/skill/references/presets.md +56 -0
  241. package/template/skill/references/sound.md +128 -0
  242. package/template/starter/.studio/chat.json +1 -0
  243. package/template/starter/assets/.keep +0 -0
  244. package/template/starter/layers.json +46 -0
  245. package/template/starter/notes.md +4 -0
  246. package/template/starter/project.json +13 -0
  247. package/template/starter/renders/.keep +0 -0
  248. package/template/starter/scenes/Title.tsx +38 -0
@@ -0,0 +1,860 @@
1
+ import { useId } from "react";
2
+ import { AbsoluteFill, useCurrentFrame } from "remotion";
3
+ import { exitOut, glowStyle } from "../lib";
4
+ import type { MotionBaseProps } from "../types";
5
+
6
+ type Props = MotionBaseProps & {
7
+ title: string;
8
+ subtitle: string;
9
+ scene: string;
10
+ palette: string;
11
+ sprite: string;
12
+ resolution: number;
13
+ spriteFps: number;
14
+ speed: number;
15
+ crt: boolean;
16
+ seed: number;
17
+ };
18
+
19
+ type Palette = {
20
+ /** Day sky, top to horizon. */
21
+ sky: string[];
22
+ /** Night / space sky, top to horizon. */
23
+ night: string[];
24
+ sun: string;
25
+ /** Synthwave sun: horizontal cuts through its lower half. */
26
+ sunStripes: boolean;
27
+ cloud: string;
28
+ far: string;
29
+ farShade: string;
30
+ mid: string;
31
+ midShade: string;
32
+ grass: string;
33
+ ground: string;
34
+ groundDark: string;
35
+ cityFar: string;
36
+ cityNear: string;
37
+ road: string;
38
+ window: string;
39
+ text: string;
40
+ textAlt: string;
41
+ outline: string;
42
+ star: string;
43
+ main: string;
44
+ skin: string;
45
+ dark: string;
46
+ accent: string;
47
+ planet: string;
48
+ planetShade: string;
49
+ surface: string;
50
+ surfaceDark: string;
51
+ };
52
+
53
+ const GB = ["#0f380f", "#306230", "#8bac0f", "#9bbc0f"];
54
+
55
+ const PALETTES: Record<string, Palette> = {
56
+ pico8: {
57
+ sky: ["#1d2b53", "#29adff", "#29adff", "#ffccaa"],
58
+ night: ["#000000", "#1d2b53", "#1d2b53", "#7e2553"],
59
+ sun: "#ffec27",
60
+ sunStripes: false,
61
+ cloud: "#fff1e8",
62
+ far: "#83769c",
63
+ farShade: "#5f574f",
64
+ mid: "#008751",
65
+ midShade: "#1d2b53",
66
+ grass: "#00e436",
67
+ ground: "#ab5236",
68
+ groundDark: "#5f574f",
69
+ cityFar: "#7e2553",
70
+ cityNear: "#000000",
71
+ road: "#5f574f",
72
+ window: "#ffa300",
73
+ text: "#fff1e8",
74
+ textAlt: "#ffec27",
75
+ outline: "#000000",
76
+ star: "#fff1e8",
77
+ main: "#ff004d",
78
+ skin: "#ffccaa",
79
+ dark: "#1d2b53",
80
+ accent: "#29adff",
81
+ planet: "#ff77a8",
82
+ planetShade: "#7e2553",
83
+ surface: "#83769c",
84
+ surfaceDark: "#5f574f",
85
+ },
86
+ nes: {
87
+ sky: ["#0058f8", "#0078f8", "#3cbcfc", "#a4e4fc"],
88
+ night: ["#000000", "#00005c", "#0000bc", "#4428bc"],
89
+ sun: "#f8b800",
90
+ sunStripes: false,
91
+ cloud: "#fcfcfc",
92
+ far: "#9878f8",
93
+ farShade: "#6844fc",
94
+ mid: "#00a800",
95
+ midShade: "#005800",
96
+ grass: "#b8f8b8",
97
+ ground: "#ac7c00",
98
+ groundDark: "#503000",
99
+ cityFar: "#6844fc",
100
+ cityNear: "#000000",
101
+ road: "#7c7c7c",
102
+ window: "#f8b800",
103
+ text: "#fcfcfc",
104
+ textAlt: "#f8b800",
105
+ outline: "#000000",
106
+ star: "#fcfcfc",
107
+ main: "#e40058",
108
+ skin: "#fca044",
109
+ dark: "#000000",
110
+ accent: "#3cbcfc",
111
+ planet: "#e45c10",
112
+ planetShade: "#a81000",
113
+ surface: "#bcbcbc",
114
+ surfaceDark: "#7c7c7c",
115
+ },
116
+ gameboy: {
117
+ sky: [GB[3], GB[3], GB[3], GB[2]],
118
+ night: [GB[0], GB[0], GB[1], GB[1]],
119
+ sun: GB[2],
120
+ sunStripes: false,
121
+ cloud: GB[2],
122
+ far: GB[2],
123
+ farShade: GB[1],
124
+ mid: GB[1],
125
+ midShade: GB[0],
126
+ grass: GB[2],
127
+ ground: GB[1],
128
+ groundDark: GB[0],
129
+ cityFar: GB[1],
130
+ cityNear: GB[0],
131
+ road: GB[1],
132
+ window: GB[3],
133
+ text: GB[3],
134
+ textAlt: GB[2],
135
+ outline: GB[0],
136
+ star: GB[3],
137
+ main: GB[0],
138
+ skin: GB[2],
139
+ dark: GB[0],
140
+ accent: GB[3],
141
+ planet: GB[2],
142
+ planetShade: GB[1],
143
+ surface: GB[1],
144
+ surfaceDark: GB[0],
145
+ },
146
+ sunset: {
147
+ sky: ["#2b0f54", "#ab1f65", "#ff4f69", "#ff8142"],
148
+ night: ["#0d0221", "#0d0221", "#2b0f54", "#53115e"],
149
+ sun: "#ffda45",
150
+ sunStripes: true,
151
+ cloud: "#ff8142",
152
+ far: "#53115e",
153
+ farShade: "#2b0f54",
154
+ mid: "#2b0f54",
155
+ midShade: "#1a0b3b",
156
+ grass: "#ff4f69",
157
+ ground: "#1a0b3b",
158
+ groundDark: "#0d0221",
159
+ cityFar: "#53115e",
160
+ cityNear: "#1a0b3b",
161
+ road: "#1a0b3b",
162
+ window: "#49e7ec",
163
+ text: "#fff3d6",
164
+ textAlt: "#49e7ec",
165
+ outline: "#0d0221",
166
+ star: "#fff3d6",
167
+ main: "#49e7ec",
168
+ skin: "#fff3d6",
169
+ dark: "#0d0221",
170
+ accent: "#ff4f69",
171
+ planet: "#ff4f69",
172
+ planetShade: "#53115e",
173
+ surface: "#53115e",
174
+ surfaceDark: "#2b0f54",
175
+ },
176
+ };
177
+
178
+ // A 5×7 bitmap font: each glyph is 7 rows, 5 bits per row (bit 4 is the left column).
179
+ const FONT: Record<string, number[]> = {
180
+ A: [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11],
181
+ B: [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e],
182
+ C: [0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e],
183
+ D: [0x1c, 0x12, 0x11, 0x11, 0x11, 0x12, 0x1c],
184
+ E: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f],
185
+ F: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10],
186
+ G: [0x0e, 0x11, 0x10, 0x17, 0x11, 0x11, 0x0f],
187
+ H: [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11],
188
+ I: [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e],
189
+ J: [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c],
190
+ K: [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11],
191
+ L: [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f],
192
+ M: [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11],
193
+ N: [0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11],
194
+ O: [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e],
195
+ P: [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10],
196
+ Q: [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d],
197
+ R: [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11],
198
+ S: [0x0f, 0x10, 0x10, 0x0e, 0x01, 0x01, 0x1e],
199
+ T: [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04],
200
+ U: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e],
201
+ V: [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04],
202
+ W: [0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0a],
203
+ X: [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11],
204
+ Y: [0x11, 0x11, 0x11, 0x0a, 0x04, 0x04, 0x04],
205
+ Z: [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f],
206
+ "0": [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e],
207
+ "1": [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e],
208
+ "2": [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f],
209
+ "3": [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e],
210
+ "4": [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02],
211
+ "5": [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e],
212
+ "6": [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e],
213
+ "7": [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08],
214
+ "8": [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e],
215
+ "9": [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c],
216
+ " ": [0, 0, 0, 0, 0, 0, 0],
217
+ ".": [0, 0, 0, 0, 0, 0x0c, 0x0c],
218
+ ",": [0, 0, 0, 0, 0x0c, 0x04, 0x08],
219
+ "!": [0x04, 0x04, 0x04, 0x04, 0x04, 0, 0x04],
220
+ "?": [0x0e, 0x11, 0x01, 0x02, 0x04, 0, 0x04],
221
+ "-": [0, 0, 0, 0x1f, 0, 0, 0],
222
+ ":": [0, 0x0c, 0x0c, 0, 0x0c, 0x0c, 0],
223
+ "'": [0x04, 0x04, 0x08, 0, 0, 0, 0],
224
+ "&": [0x0c, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0d],
225
+ "/": [0, 0x01, 0x02, 0x04, 0x08, 0x10, 0],
226
+ "+": [0, 0x04, 0x04, 0x1f, 0x04, 0x04, 0],
227
+ "#": [0x0a, 0x0a, 0x1f, 0x0a, 0x1f, 0x0a, 0x0a],
228
+ "(": [0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02],
229
+ ")": [0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08],
230
+ "*": [0, 0x04, 0x15, 0x0e, 0x15, 0x04, 0],
231
+ $: [0x04, 0x0f, 0x14, 0x0e, 0x05, 0x1e, 0x04],
232
+ "%": [0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03],
233
+ "@": [0x0e, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0f],
234
+ ">": [0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08],
235
+ "<": [0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02],
236
+ "=": [0, 0, 0x1f, 0, 0x1f, 0, 0],
237
+ _: [0, 0, 0, 0, 0, 0, 0x1f],
238
+ };
239
+
240
+ // Sprites: "." transparent, a main, s skin, d dark, w text, y text alt, e accent.
241
+ const RUNNER_HEAD = ["...aaaa..", "..aaaaaaa", "..ssssds.", "..sssss.."];
242
+ const RUNNER_ARMS = [
243
+ ["..aaaaa..", ".saaaaa.s", "..aaaaa.."],
244
+ ["..aaaaa..", "..saaaas.", "..aaaaa.."],
245
+ ];
246
+ const RUNNER_LEGS = [
247
+ ["..dd.dd..", ".dd...dd.", ".d.....d.", "dd.....dd"],
248
+ ["..ddddd..", "..dd.dd..", ".dd...d..", ".d....dd."],
249
+ ["...ddd...", "...ddd...", "...dd....", "...ddd..."],
250
+ ["..dd.dd..", ".dd...dd.", ".d.....d.", "dd.....dd"],
251
+ ["..ddddd..", "..dd.dd..", "..d...dd.", ".dd....d."],
252
+ ["...ddd...", "...ddd...", "....dd...", "...ddd..."],
253
+ ];
254
+ const RUNNER_BOB = [0, 0, -1, 0, 0, -1];
255
+ const SHIP = [
256
+ "...aa.......",
257
+ "..aaaa......",
258
+ "aaaaaaaaww..",
259
+ "aeaaaaaawwa.",
260
+ "aaaaaaaaaaa.",
261
+ "..aaaa......",
262
+ "...aa.......",
263
+ ];
264
+
265
+ const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];
266
+ const threshold = (x: number, y: number) => (BAYER[(y & 3) * 4 + (x & 3)] + 0.5) / 16;
267
+ const mod = (a: number, n: number) => ((a % n) + n) % n;
268
+ const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
269
+
270
+ /** Seeded integer hash → [0, 1): the same on the server and every client. */
271
+ function hash(seed: number, a: number, b = 0, c = 0) {
272
+ let h =
273
+ Math.imul(a | 0, 374761393) ^
274
+ Math.imul(b | 0, 668265263) ^
275
+ Math.imul(c | 0, 1274126177) ^
276
+ Math.imul((seed | 0) + 101, 1597334677);
277
+ h = Math.imul(h ^ (h >>> 13), 1274126177);
278
+ h ^= h >>> 16;
279
+ return (h >>> 0) / 4294967296;
280
+ }
281
+
282
+ /** A low-res frame buffer of palette ids, drawn out as one SVG path per color. */
283
+ class Canvas {
284
+ readonly w: number;
285
+ readonly h: number;
286
+ readonly px: Int16Array;
287
+ private readonly colors: string[] = [];
288
+ private readonly ids = new Map<string, number>();
289
+
290
+ constructor(w: number, h: number) {
291
+ this.w = w;
292
+ this.h = h;
293
+ this.px = new Int16Array(w * h).fill(-1);
294
+ }
295
+
296
+ id(color: string) {
297
+ let i = this.ids.get(color);
298
+ if (i === undefined) {
299
+ i = this.colors.length;
300
+ this.colors.push(color);
301
+ this.ids.set(color, i);
302
+ }
303
+ return i;
304
+ }
305
+
306
+ set(x: number, y: number, id: number) {
307
+ if (x < 0 || y < 0 || x >= this.w || y >= this.h) return;
308
+ this.px[y * this.w + x] = id;
309
+ }
310
+
311
+ get(x: number, y: number) {
312
+ if (x < 0 || y < 0 || x >= this.w || y >= this.h) return -1;
313
+ return this.px[y * this.w + x];
314
+ }
315
+
316
+ rect(x: number, y: number, w: number, h: number, id: number) {
317
+ for (let yy = y; yy < y + h; yy++) for (let xx = x; xx < x + w; xx++) this.set(xx, yy, id);
318
+ }
319
+
320
+ disc(cx: number, cy: number, r: number, id: number, maxY = Infinity) {
321
+ const rr = r * r + r * 0.8;
322
+ for (let dy = -r; dy <= r; dy++) {
323
+ if (cy + dy > maxY) continue;
324
+ for (let dx = -r; dx <= r; dx++) if (dx * dx + dy * dy <= rr) this.set(cx + dx, cy + dy, id);
325
+ }
326
+ }
327
+
328
+ /** Horizontal runs of one color merged into rectangles, one path per color. */
329
+ paths() {
330
+ const d: string[][] = this.colors.map(() => []);
331
+ for (let y = 0; y < this.h; y++) {
332
+ let x = 0;
333
+ while (x < this.w) {
334
+ const id = this.px[y * this.w + x];
335
+ let end = x + 1;
336
+ while (end < this.w && this.px[y * this.w + end] === id) end++;
337
+ if (id >= 0) d[id].push(`M${x} ${y}h${end - x}v1h-${end - x}z`);
338
+ x = end;
339
+ }
340
+ }
341
+ return this.colors.map((color, i) => ({ color, d: d[i].join("") })).filter((p) => p.d);
342
+ }
343
+ }
344
+
345
+ type Ctx = {
346
+ cv: Canvas;
347
+ pal: Palette;
348
+ vw: number;
349
+ vh: number;
350
+ gY: number;
351
+ step: number;
352
+ seed: number;
353
+ /** Parallax offset in whole pixels for a layer moving at `f` × the scroll speed. */
354
+ o: (f: number) => number;
355
+ };
356
+
357
+ /** A vertical gradient through the colors, solid in each band then Bayer-dithered into the next. */
358
+ function skyFill({ cv, vw }: Ctx, colors: string[], top: number, bottom: number) {
359
+ const ids = colors.map((c) => cv.id(c));
360
+ const n = ids.length;
361
+ for (let y = top; y < bottom; y++) {
362
+ const v = ((y - top) / Math.max(1, bottom - top - 1)) * (n - 1);
363
+ const i = Math.min(n - 2, Math.floor(v));
364
+ const f = clamp01((v - i - 0.5) / 0.5);
365
+ for (let x = 0; x < vw; x++) cv.set(x, y, f > threshold(x, y) ? ids[i + 1] : ids[i]);
366
+ }
367
+ }
368
+
369
+ function paintHills(ctx: Ctx, vertical: boolean) {
370
+ const { cv, pal, vw, vh, gY, seed, o } = ctx;
371
+ skyFill(ctx, pal.sky, 0, gY);
372
+
373
+ // Sun, sitting behind the far mountains.
374
+ const sun = cv.id(pal.sun);
375
+ const sr = Math.max(5, Math.round(Math.min(vw, vh) * 0.13));
376
+ const sx = Math.round(vw * (vertical ? 0.7 : 0.74));
377
+ const sy = Math.round(vh * (vertical ? 0.55 : 0.5));
378
+ for (let dy = -sr; dy <= sr; dy++) {
379
+ if (pal.sunStripes && dy > 0 && (dy % 4 === 0 || (dy % 4 === 1 && dy > sr * 0.5))) continue;
380
+ for (let dx = -sr; dx <= sr; dx++) if (dx * dx + dy * dy <= sr * sr + sr * 0.8) cv.set(sx + dx, sy + dy, sun);
381
+ }
382
+
383
+ // Clouds drifting slowly.
384
+ const cloud = cv.id(pal.cloud);
385
+ for (let i = 0; i < 4; i++) {
386
+ const cw = 10 + Math.floor(hash(seed, i, 1) * 10);
387
+ const base = Math.floor(hash(seed, i, 2) * (vw + 40));
388
+ const y = Math.floor(vh * (0.07 + hash(seed, i, 3) * 0.26));
389
+ const x = mod(base - o(0.12 + i * 0.04), vw + 40) - 20;
390
+ cv.rect(x, y + 3, cw, 2, cloud);
391
+ cv.disc(x + 3, y + 3, 2, cloud, y + 4);
392
+ cv.disc(x + Math.floor(cw * 0.45), y + 2, 3, cloud, y + 4);
393
+ cv.disc(x + cw - 4, y + 3, 2, cloud, y + 4);
394
+ }
395
+
396
+ // Far mountains: sharp peaks, lit on the left, with snow on the tall ones.
397
+ const far = cv.id(pal.far);
398
+ const farShade = cv.id(pal.farShade);
399
+ const P = Math.max(24, Math.round(vh * 0.38));
400
+ const of = o(0.25);
401
+ for (let x = 0; x < vw; x++) {
402
+ const wx = x + of;
403
+ const k0 = Math.floor(wx / P);
404
+ let top = Infinity;
405
+ let peakX = 0;
406
+ let peakTop = 0;
407
+ let snowy = false;
408
+ for (let k = k0 - 1; k <= k0 + 1; k++) {
409
+ const cx = k * P + Math.floor(hash(seed, k, 5) * P * 0.6);
410
+ const pt = Math.floor(vh * (0.34 + hash(seed, k, 6) * 0.18));
411
+ const y = pt + Math.abs(wx - cx);
412
+ if (y < top) {
413
+ top = y;
414
+ peakX = cx;
415
+ peakTop = pt;
416
+ snowy = pt < vh * 0.42;
417
+ }
418
+ }
419
+ for (let y = Math.max(0, top); y < gY; y++) {
420
+ const snow = snowy && y < peakTop + 3 + (wx % 2);
421
+ cv.set(x, y, snow ? cloud : wx < peakX ? far : farShade);
422
+ }
423
+ }
424
+
425
+ // Mid hills: rolling, dithered darker toward their base, with a few trees.
426
+ const mid = cv.id(pal.mid);
427
+ const midShade = cv.id(pal.midShade);
428
+ const grass = cv.id(pal.grass);
429
+ const om = o(0.5);
430
+ const s1 = hash(seed, 1, 40) * 6.28;
431
+ const s2 = hash(seed, 2, 40) * 6.28;
432
+ const hillTop = (wx: number) =>
433
+ Math.round(vh * 0.64 + 3 * Math.sin(wx * 0.045 + s1) + 2 * Math.sin(wx * 0.11 + s2));
434
+ for (let x = 0; x < vw; x++) {
435
+ const wx = x + om;
436
+ const top = hillTop(wx);
437
+ for (let y = top; y < gY; y++) {
438
+ const depth = y - top;
439
+ const c =
440
+ depth === 0 ? grass : depth < 6 ? mid : depth < 10 ? ((depth - 6) / 4 > threshold(x, y) ? midShade : mid) : midShade;
441
+ cv.set(x, y, c);
442
+ }
443
+ }
444
+ const T = 23;
445
+ for (let k = Math.floor(om / T) - 1; k <= Math.floor((om + vw) / T) + 1; k++) {
446
+ if (hash(seed, k, 41) < 0.45) continue;
447
+ const wx = k * T + Math.floor(hash(seed, k, 42) * 12);
448
+ const x = wx - om;
449
+ const top = hillTop(wx);
450
+ cv.rect(x, top - 2, 1, 2, midShade);
451
+ cv.disc(x, top - 4, 2, midShade);
452
+ cv.set(x - 1, top - 5, mid);
453
+ }
454
+
455
+ // Near ground: grass edge with tufts, dirt with speckles.
456
+ const ground = cv.id(pal.ground);
457
+ const groundDark = cv.id(pal.groundDark);
458
+ const on = o(1);
459
+ for (let x = 0; x < vw; x++) {
460
+ const wx = x + on;
461
+ if (hash(seed, wx, 8) < 0.14) cv.set(x, gY - 1, grass);
462
+ for (let y = gY; y < vh; y++) {
463
+ const dpt = y - gY;
464
+ let c = ground;
465
+ if (dpt === 0) c = grass;
466
+ else if (dpt === 1) c = hash(seed, wx, 7) < 0.5 ? grass : ground;
467
+ else if (dpt === 2) c = hash(seed, wx, 9) < 0.4 ? groundDark : ground;
468
+ else if (hash(seed, wx, y) < 0.07) c = groundDark;
469
+ cv.set(x, y, c);
470
+ }
471
+ }
472
+ }
473
+
474
+ function paintCity(ctx: Ctx) {
475
+ const { cv, pal, vw, vh, gY, step, seed, o } = ctx;
476
+ skyFill(ctx, pal.night, 0, gY);
477
+
478
+ // Twinkling stars and a crescent moon.
479
+ const star = cv.id(pal.star);
480
+ const nStars = Math.floor((vw * vh) / 110);
481
+ for (let i = 0; i < nStars; i++) {
482
+ const x = Math.floor(hash(seed, i, 10) * vw);
483
+ const y = Math.floor(hash(seed, i, 11) * gY * 0.6);
484
+ const tw = hash(seed, i, Math.floor(step / 3) + 100);
485
+ if (tw < 0.25) continue;
486
+ cv.set(x, y, star);
487
+ if (hash(seed, i, 12) > 0.92 && tw > 0.6) {
488
+ cv.set(x - 1, y, star);
489
+ cv.set(x + 1, y, star);
490
+ cv.set(x, y - 1, star);
491
+ cv.set(x, y + 1, star);
492
+ }
493
+ }
494
+ const mr = Math.max(3, Math.round(Math.min(vw, vh) * 0.075));
495
+ const mx = Math.round(vw * 0.8);
496
+ const my = Math.round(vh * 0.16);
497
+ for (let dy = -mr; dy <= mr; dy++)
498
+ for (let dx = -mr; dx <= mr; dx++) {
499
+ const inA = dx * dx + dy * dy <= mr * mr + mr * 0.8;
500
+ const bx = dx + Math.round(mr * 0.5);
501
+ const by = dy + Math.round(mr * 0.25);
502
+ if (inA && bx * bx + by * by > mr * mr) cv.set(mx + dx, my + dy, star);
503
+ }
504
+
505
+ // Far skyline with flickering windows and antenna lights.
506
+ const cityFar = cv.id(pal.cityFar);
507
+ const win = cv.id(pal.window);
508
+ const accent = cv.id(pal.accent);
509
+ const of = o(0.25);
510
+ for (let x = 0; x < vw; x++) {
511
+ const wx = x + of;
512
+ const k = Math.floor(wx / 10);
513
+ const local = mod(wx, 10);
514
+ const bw = 6 + Math.floor(hash(seed, k, 20) * 4);
515
+ if (local >= bw) continue;
516
+ const top = gY - Math.floor(vh * (0.22 + hash(seed, k, 21) * 0.26));
517
+ for (let y = top; y < gY; y++) {
518
+ const lit =
519
+ local >= 1 && local < bw - 1 && local % 2 === 1 && (y - top) % 3 === 1 && y > top + 1 &&
520
+ hash(seed, k * 31 + local, y, Math.floor(step / 25)) < 0.22;
521
+ cv.set(x, y, lit ? win : cityFar);
522
+ }
523
+ if (hash(seed, k, 22) > 0.65 && local === Math.floor(bw / 2)) {
524
+ for (let y = top - 4; y < top; y++) cv.set(x, y, cityFar);
525
+ if (Math.floor(step / 5) % 2 === 0) cv.set(x, top - 5, accent);
526
+ }
527
+ }
528
+
529
+ // Near buildings: a lighter roof edge and a grid of lit windows.
530
+ const cityNear = cv.id(pal.cityNear);
531
+ const om = o(0.5);
532
+ for (let x = 0; x < vw; x++) {
533
+ const wx = x + om;
534
+ const k = Math.floor(wx / 18);
535
+ const local = mod(wx, 18);
536
+ const bw = 11 + Math.floor(hash(seed, k, 23) * 6);
537
+ if (local >= bw) continue;
538
+ const top = gY - Math.floor(vh * (0.12 + hash(seed, k, 24) * 0.22));
539
+ for (let y = top; y < gY; y++) {
540
+ let c = y === top ? cityFar : cityNear;
541
+ if (local >= 2 && local < bw - 2 && (local - 2) % 3 < 2 && y > top + 2 && y < gY - 2 && (y - top - 3) % 4 < 2) {
542
+ const lit = hash(seed, k * 7 + Math.floor((local - 2) / 3), Math.floor((y - top - 3) / 4), 31 + Math.floor(step / 40));
543
+ if (lit < 0.45) c = win;
544
+ }
545
+ cv.set(x, y, c);
546
+ }
547
+ }
548
+
549
+ // Street: a curb line, the road and moving lane dashes.
550
+ const road = cv.id(pal.road);
551
+ const on = o(1);
552
+ const lane = gY + Math.max(3, Math.floor((vh - gY) / 2));
553
+ for (let x = 0; x < vw; x++) {
554
+ const wx = x + on;
555
+ for (let y = gY; y < vh; y++) {
556
+ let c = y === gY ? cityFar : road;
557
+ if (y === lane && mod(wx, 14) < 6) c = win;
558
+ cv.set(x, y, c);
559
+ }
560
+ }
561
+ }
562
+
563
+ function paintSpace(ctx: Ctx) {
564
+ const { cv, pal, vw, vh, gY, step, seed } = ctx;
565
+ skyFill(ctx, [pal.night[0], pal.night[0], pal.night[1], pal.night[2]], 0, gY);
566
+
567
+ // Three layers of stars scrolling at different speeds.
568
+ const layers = [
569
+ { color: cv.id(pal.far), sp: 0.15, n: (vw * vh) / 70 },
570
+ { color: cv.id(pal.star), sp: 0.4, n: (vw * vh) / 140 },
571
+ { color: cv.id(pal.textAlt), sp: 0.9, n: (vw * vh) / 400 },
572
+ ];
573
+ layers.forEach((layer, l) => {
574
+ const off = ctx.o(layer.sp);
575
+ for (let i = 0; i < Math.floor(layer.n); i++) {
576
+ const x = mod(Math.floor(hash(seed, i, 50 + l) * vw * 3) - off, vw);
577
+ const y = Math.floor(hash(seed, i, 60 + l) * gY);
578
+ if (l === 1 && hash(seed, i, Math.floor(step / 4) + 200) < 0.2) continue;
579
+ cv.set(x, y, layer.color);
580
+ if (l === 2) cv.set(x + 1, y, layer.color);
581
+ }
582
+ });
583
+
584
+ // A dithered planet with a tilted ring.
585
+ const planet = cv.id(pal.planet);
586
+ const planetShade = cv.id(pal.planetShade);
587
+ const ring = cv.id(pal.textAlt);
588
+ const r = Math.max(6, Math.round(Math.min(vw, vh) * 0.17));
589
+ const cx = Math.round(vw * 0.74);
590
+ const cy = Math.round(vh * 0.3);
591
+ const inPlanet = (x: number, y: number) => (x - cx) ** 2 + (y - cy) ** 2 <= r * r + r * 0.8;
592
+ for (let dy = -r; dy <= r; dy++)
593
+ for (let dx = -r; dx <= r; dx++) {
594
+ if (!inPlanet(cx + dx, cy + dy)) continue;
595
+ const shade = clamp01((((dx / r) * 0.8 + (dy / r) * 0.5) + 0.1) / 0.6);
596
+ cv.set(cx + dx, cy + dy, shade > threshold(cx + dx, cy + dy) ? planetShade : planet);
597
+ }
598
+ const rx = Math.round(r * 1.9);
599
+ const ry = Math.max(2, Math.round(r * 0.42));
600
+ for (let dx = -rx; dx <= rx; dx++) {
601
+ const e = Math.round(ry * Math.sqrt(Math.max(0, 1 - (dx / rx) ** 2)));
602
+ const tilt = Math.round(dx * 0.22);
603
+ const x = cx + dx;
604
+ const back = cy - e + tilt;
605
+ const front = cy + e + tilt;
606
+ if (!inPlanet(x, back)) cv.set(x, back, ring);
607
+ cv.set(x, front, ring);
608
+ }
609
+
610
+ // Cratered surface.
611
+ const surface = cv.id(pal.surface);
612
+ const surfaceDark = cv.id(pal.surfaceDark);
613
+ const edge = cv.id(pal.cloud);
614
+ const on = ctx.o(1);
615
+ for (let x = 0; x < vw; x++) {
616
+ const wx = x + on;
617
+ const top = gY + Math.round(1.5 * Math.sin(wx * 0.09) + Math.sin(wx * 0.23 + 1));
618
+ for (let y = top; y < vh; y++) cv.set(x, y, y === top ? edge : surface);
619
+ const k = Math.floor(wx / 22);
620
+ const ccx = k * 22 + 4 + Math.floor(hash(seed, k, 70) * 10);
621
+ const cw = 5 + Math.floor(hash(seed, k, 71) * 5);
622
+ const ccy = gY + 4 + Math.floor(hash(seed, k, 72) * Math.max(1, vh - gY - 8));
623
+ if (Math.abs(wx - ccx) < cw / 2) {
624
+ cv.set(x, ccy, surfaceDark);
625
+ if (Math.abs(wx - ccx) < cw / 2 - 1) cv.set(x, ccy + 1, surfaceDark);
626
+ }
627
+ }
628
+ }
629
+
630
+ function drawSprite(cv: Canvas, rows: string[], x: number, y: number, map: Record<string, number>) {
631
+ rows.forEach((row, ry) => {
632
+ for (let rx = 0; rx < row.length; rx++) {
633
+ const id = map[row[rx]];
634
+ if (id !== undefined) cv.set(x + rx, y + ry, id);
635
+ }
636
+ });
637
+ }
638
+
639
+ function drawCoin(cv: Canvas, pal: Palette, x: number, y: number, f: number) {
640
+ const w = Math.max(1, Math.round(8 * Math.abs(Math.cos((f * Math.PI) / 4))));
641
+ const fillId = cv.id(pal.textAlt);
642
+ const edge = cv.id(pal.outline);
643
+ const shine = cv.id(pal.text);
644
+ for (let r = 0; r < 8; r++) {
645
+ const half = Math.max(0.5, (w / 2) * Math.sqrt(Math.max(0, 1 - ((r - 3.5) / 4) ** 2)));
646
+ const left = Math.round(x + 4 - half);
647
+ const right = Math.round(x + 4 + half) - 1;
648
+ for (let xx = left; xx <= right; xx++) {
649
+ const isEdge = xx === left || xx === right || r === 0 || r === 7;
650
+ cv.set(xx, y + r, isEdge ? edge : w > 3 && xx === left + 1 && r > 1 && r < 6 ? shine : fillId);
651
+ }
652
+ }
653
+ }
654
+
655
+ /** Greedy word wrap of `text` into lines of at most `max` characters (long words are cut). */
656
+ function wrap(text: string, max: number) {
657
+ const lines: string[] = [];
658
+ let line = "";
659
+ for (const word of text.split(/\s+/).filter(Boolean)) {
660
+ let wd = word;
661
+ while (wd.length > max) {
662
+ if (line) lines.push(line);
663
+ lines.push(wd.slice(0, max));
664
+ wd = wd.slice(max);
665
+ line = "";
666
+ }
667
+ if (!line) line = wd;
668
+ else if (line.length + 1 + wd.length <= max) line += ` ${wd}`;
669
+ else {
670
+ lines.push(line);
671
+ line = wd;
672
+ }
673
+ }
674
+ if (line) lines.push(line);
675
+ return lines;
676
+ }
677
+
678
+ /** Draws text into the mask (palette ids), 5×7 glyphs at an integer scale. Top rows `top`, bottom rows `bottom`. */
679
+ function drawText(mask: Int16Array, w: number, h: number, text: string, x0: number, y0: number, s: number, top: number, bottom: number) {
680
+ for (let i = 0; i < text.length; i++) {
681
+ const glyph = FONT[text[i]] ?? FONT["?"];
682
+ for (let r = 0; r < 7; r++)
683
+ for (let c = 0; c < 5; c++) {
684
+ if (!(glyph[r] & (1 << (4 - c)))) continue;
685
+ for (let yy = 0; yy < s; yy++)
686
+ for (let xx = 0; xx < s; xx++) {
687
+ const px = x0 + (i * 6 + c) * s + xx;
688
+ const py = y0 + r * s + yy;
689
+ if (px >= 0 && py >= 0 && px < w && py < h) mask[py * w + px] = r < 4 ? top : bottom;
690
+ }
691
+ }
692
+ }
693
+ }
694
+
695
+ /**
696
+ * A retro game title screen on a low-res pixel canvas: Bayer-dithered sky, parallax layers scrolling in
697
+ * whole pixels, a stepped sprite animation, a bitmap-font title that drops in with a bounce and a
698
+ * blinking "press start", with optional CRT scanlines. Fades in and out with a dithered dissolve.
699
+ */
700
+ export function ArcadeTitle(props: Props) {
701
+ const frame = useCurrentFrame();
702
+ const scanId = `px${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
703
+ const { width, height, fps, durationInFrames: d } = props;
704
+ const pal = PALETTES[props.palette] ?? PALETTES.pico8;
705
+ const res = Math.max(40, Math.round(props.resolution));
706
+ const scale = Math.min(width, height) / res;
707
+ const vw = Math.ceil(width / scale);
708
+ const vh = Math.ceil(height / scale);
709
+ const vertical = height > width;
710
+ const step = Math.floor((frame * props.spriteFps) / fps);
711
+ const seed = Math.round(props.seed);
712
+ const gY = Math.floor(vh * (vertical ? 0.8 : 0.79));
713
+ const cv = new Canvas(vw, vh);
714
+ const ctx: Ctx = { cv, pal, vw, vh, gY, step, seed, o: (f) => Math.floor(step * props.speed * f) };
715
+
716
+ if (props.scene === "city") paintCity(ctx);
717
+ else if (props.scene === "space") paintSpace(ctx);
718
+ else paintHills(ctx, vertical);
719
+
720
+ // The sprite.
721
+ const map: Record<string, number> = {
722
+ a: cv.id(pal.main),
723
+ s: cv.id(pal.skin),
724
+ d: cv.id(pal.dark),
725
+ w: cv.id(pal.text),
726
+ y: cv.id(pal.textAlt),
727
+ e: cv.id(pal.accent),
728
+ };
729
+ const sprite = props.sprite === "auto" ? (props.scene === "space" ? "ship" : "runner") : props.sprite;
730
+ if (sprite === "runner") {
731
+ const f = step % 6;
732
+ const rows = [...RUNNER_HEAD, ...RUNNER_ARMS[f < 3 ? 0 : 1], ...RUNNER_LEGS[f]];
733
+ const x = Math.min(Math.floor(vw * 0.2), -10 + step * 3);
734
+ drawSprite(cv, rows, x, gY - rows.length + RUNNER_BOB[f], map);
735
+ } else if (sprite === "ship") {
736
+ const x = Math.min(Math.floor(vw * 0.2), -14 + step * 3);
737
+ const y = Math.floor(vh * (props.scene === "space" ? 0.62 : 0.6)) + Math.round(2 * Math.sin(step * 0.5));
738
+ const flick = 2 + (step % 3);
739
+ for (let i = 1; i <= flick; i++) cv.set(x - i, y + 3, i <= 2 ? map.y : map.e);
740
+ for (let i = 1; i <= flick - 2; i++) {
741
+ cv.set(x - i, y + 2, map.y);
742
+ cv.set(x - i, y + 4, map.y);
743
+ }
744
+ drawSprite(cv, SHIP, x, y, map);
745
+ } else if (sprite === "coins") {
746
+ const on = ctx.o(1);
747
+ const gap = 16;
748
+ const y = (props.scene === "space" ? Math.floor(vh * 0.6) : gY - 14) + (Math.floor(step / 3) % 2);
749
+ for (let k = Math.floor(on / gap); k <= Math.floor((on + vw) / gap) + 1; k++) {
750
+ if (hash(seed, k, 80) < 0.3) continue;
751
+ drawCoin(cv, pal, k * gap - on, y, step + k * 2);
752
+ }
753
+ }
754
+
755
+ // The title and the blinking subtitle, outlined so they read on any scene.
756
+ const title = props.title.toUpperCase().trim();
757
+ const subtitle = props.subtitle.toUpperCase().trim();
758
+ const mask = new Int16Array(vw * vh).fill(-1);
759
+ const textId = cv.id(pal.text);
760
+ const textAlt = cv.id(pal.textAlt);
761
+ const outline = cv.id(pal.outline);
762
+ let titleBottom = Math.round(vh * 0.28);
763
+ let landed = 4;
764
+ if (title) {
765
+ let s = 1;
766
+ let lines = [title];
767
+ for (let tryS = 5; tryS >= 1; tryS--) {
768
+ const max = Math.floor((vw * 0.9 + tryS) / (6 * tryS));
769
+ const words = title.split(/\s+/);
770
+ if (max < 1 || words.some((w) => w.length > max)) continue;
771
+ const wrapped = wrap(title, max);
772
+ if (wrapped.length * 9 * tryS <= vh * (vertical ? 0.36 : 0.42) && wrapped.length <= 3) {
773
+ s = tryS;
774
+ lines = wrapped;
775
+ break;
776
+ }
777
+ if (tryS === 1) lines = wrapped;
778
+ }
779
+ const lineH = 9 * s;
780
+ const ty = Math.round(vh * (vertical ? 0.2 : 0.17));
781
+ const bounce = [-2, -3, -2, 0, -1, 0];
782
+ lines.forEach((line, li) => {
783
+ const start = 3 + li * 2;
784
+ const t = step - start;
785
+ if (t < 0) return;
786
+ const drop = ty + (li + 1) * lineH + 4;
787
+ const off = t <= 5 ? -Math.round(drop * (1 - (t / 5) ** 2)) : t - 6 < bounce.length ? bounce[t - 6] * s : 0;
788
+ const lw = (line.length * 6 - 1) * s;
789
+ drawText(mask, vw, vh, line, Math.round((vw - lw) / 2), ty + li * lineH + off, s, textId, textAlt);
790
+ });
791
+ titleBottom = ty + lines.length * lineH - 2 * s;
792
+ landed = 3 + (lines.length - 1) * 2 + 12;
793
+ }
794
+ if (subtitle) {
795
+ const start = landed + 2;
796
+ if (step >= start && (step - start) % 8 < 5) {
797
+ const ss = vw >= 220 ? 2 : 1;
798
+ const lw = (subtitle.length * 6 - 1) * ss;
799
+ const sy = title ? titleBottom + Math.max(6, Math.round(vh * 0.06)) : Math.round(vh * 0.4);
800
+ drawText(mask, vw, vh, subtitle, Math.round((vw - lw) / 2), sy, ss, textId, textId);
801
+ }
802
+ }
803
+ const OUTLINE = [[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1], [0, 2], [1, 2]];
804
+ for (let y = 0; y < vh; y++)
805
+ for (let x = 0; x < vw; x++) {
806
+ if (mask[y * vw + x] < 0) continue;
807
+ for (const [dx, dy] of OUTLINE) {
808
+ const nx = x + dx;
809
+ const ny = y + dy;
810
+ if (nx >= 0 && ny >= 0 && nx < vw && ny < vh && mask[ny * vw + nx] < 0) cv.set(nx, ny, outline);
811
+ }
812
+ }
813
+ for (let i = 0; i < mask.length; i++) if (mask[i] >= 0) cv.px[i] = mask[i];
814
+
815
+ // Dithered dissolve from black at the start and to black at the end.
816
+ const black = outline;
817
+ const fadeIn = clamp01(step / 4);
818
+ const fadeOut = exitOut(frame, d, 12);
819
+ const shown = Math.min(fadeIn, fadeOut);
820
+ if (shown < 1)
821
+ for (let y = 0; y < vh; y++) for (let x = 0; x < vw; x++) if (threshold(x, y) >= shown) cv.set(x, y, black);
822
+
823
+ const paths = cv.paths();
824
+ const pxSize = Math.max(width / vw, height / vh);
825
+ const offY = (height - vh * pxSize) / 2;
826
+ const round = (v: number) => Math.round(v * 100) / 100;
827
+
828
+ return (
829
+ <AbsoluteFill style={{ background: pal.outline }}>
830
+ <svg
831
+ width={width}
832
+ height={height}
833
+ viewBox={`0 0 ${vw} ${vh}`}
834
+ preserveAspectRatio="xMidYMid slice"
835
+ shapeRendering="crispEdges"
836
+ style={{ position: "absolute", inset: 0 }}
837
+ >
838
+ {paths.map((p) => (
839
+ <path key={p.color} d={p.d} fill={p.color} />
840
+ ))}
841
+ </svg>
842
+ {props.crt ? (
843
+ <>
844
+ <svg width={width} height={height} style={{ position: "absolute", inset: 0 }}>
845
+ <defs>
846
+ <pattern id={scanId} width={8} height={round(pxSize)} y={round(offY)} patternUnits="userSpaceOnUse">
847
+ <rect y={round(pxSize * 0.62)} width={8} height={round(pxSize * 0.38)} fill="#000000" fillOpacity={0.28} />
848
+ </pattern>
849
+ </defs>
850
+ <rect width={width} height={height} fill={`url(#${scanId})`} />
851
+ </svg>
852
+ <div style={glowStyle(width / 2, height / 2, width * 1.1, height * 1.1, pal.accent, 0.08)} />
853
+ <AbsoluteFill
854
+ style={{ background: "radial-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.5) 100%)" }}
855
+ />
856
+ </>
857
+ ) : null}
858
+ </AbsoluteFill>
859
+ );
860
+ }