@zyro-sec/ui 1.0.1 → 1.0.3

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 (631) hide show
  1. package/AGENTS.md +29 -29
  2. package/LICENSE +21 -21
  3. package/bunfig.toml +2 -2
  4. package/package.json +76 -2
  5. package/perf/motion.bench.ts +14 -14
  6. package/perf/motion.ts +16 -16
  7. package/script/build-oc2-v2-overrides.ts +38 -38
  8. package/script/colors.txt +288 -288
  9. package/script/generate-spinner.ts +121 -121
  10. package/script/pack.ts +5 -5
  11. package/script/tailwind.ts +24 -24
  12. package/src/actions/button/button.css +346 -346
  13. package/src/actions/button/button.stories.tsx +158 -158
  14. package/src/actions/button/button.tsx +56 -56
  15. package/src/actions/icon-button/icon-button.css +128 -128
  16. package/src/actions/icon-button/icon-button.stories.tsx +122 -122
  17. package/src/actions/icon-button/icon-button.tsx +46 -46
  18. package/src/actions/split-button/split-button.css +99 -99
  19. package/src/actions/split-button/split-button.stories.tsx +59 -59
  20. package/src/actions/split-button/split-button.tsx +51 -51
  21. package/src/actions/submit.css +81 -81
  22. package/src/assets/favicon/favicon-v3.svg +6 -6
  23. package/src/assets/favicon/favicon.svg +6 -6
  24. package/src/assets/favicon/site.webmanifest +24 -24
  25. package/src/assets/icons/app/android-studio.svg +369 -369
  26. package/src/assets/icons/app/antigravity.svg +97 -97
  27. package/src/assets/icons/app/cursor.svg +16 -16
  28. package/src/assets/icons/app/file-explorer.svg +20 -20
  29. package/src/assets/icons/app/ghostty.svg +13 -13
  30. package/src/assets/icons/app/iterm2.svg +13 -13
  31. package/src/assets/icons/app/powershell.svg +14 -14
  32. package/src/assets/icons/app/sublimetext.svg +17 -17
  33. package/src/assets/icons/app/vscode.svg +39 -39
  34. package/src/assets/icons/app/windows-terminal.svg +6 -6
  35. package/src/assets/icons/app/zed-dark.svg +15 -15
  36. package/src/assets/icons/app/zed.svg +15 -15
  37. package/src/assets/icons/file-types/auto_light.svg +12 -12
  38. package/src/assets/icons/file-types/cursor.svg +1 -1
  39. package/src/assets/icons/file-types/cursor_light.svg +1 -1
  40. package/src/assets/icons/file-types/drone_light.svg +4 -4
  41. package/src/assets/icons/file-types/folder-admin-open.svg +6 -6
  42. package/src/assets/icons/file-types/folder-admin.svg +6 -6
  43. package/src/assets/icons/file-types/folder-circleci-open.svg +7 -7
  44. package/src/assets/icons/file-types/folder-circleci.svg +7 -7
  45. package/src/assets/icons/file-types/folder-flow-open.svg +6 -6
  46. package/src/assets/icons/file-types/folder-flow.svg +6 -6
  47. package/src/assets/icons/file-types/folder-gh-workflows-open.svg +6 -6
  48. package/src/assets/icons/file-types/folder-gh-workflows.svg +6 -6
  49. package/src/assets/icons/file-types/folder-github-open.svg +6 -6
  50. package/src/assets/icons/file-types/folder-github.svg +6 -6
  51. package/src/assets/icons/file-types/folder-intellij-open.svg +39 -39
  52. package/src/assets/icons/file-types/folder-intellij.svg +39 -39
  53. package/src/assets/icons/file-types/folder-macos-open.svg +6 -6
  54. package/src/assets/icons/file-types/folder-macos.svg +6 -6
  55. package/src/assets/icons/file-types/folder-next-open.svg +6 -6
  56. package/src/assets/icons/file-types/folder-next.svg +6 -6
  57. package/src/assets/icons/file-types/folder-nuxt-open.svg +6 -6
  58. package/src/assets/icons/file-types/folder-nuxt.svg +6 -6
  59. package/src/assets/icons/file-types/folder-open.svg +5 -5
  60. package/src/assets/icons/file-types/folder-scripts-open.svg +6 -6
  61. package/src/assets/icons/file-types/folder-scripts.svg +6 -6
  62. package/src/assets/icons/file-types/folder-target-open.svg +10 -10
  63. package/src/assets/icons/file-types/folder-target.svg +10 -10
  64. package/src/assets/icons/file-types/folder-turborepo-open.svg +15 -15
  65. package/src/assets/icons/file-types/folder-turborepo.svg +15 -15
  66. package/src/assets/icons/file-types/folder-vercel-open.svg +5 -5
  67. package/src/assets/icons/file-types/folder-vercel.svg +5 -5
  68. package/src/assets/icons/file-types/folder.svg +5 -5
  69. package/src/assets/icons/file-types/go_gopher.svg +35 -35
  70. package/src/assets/icons/file-types/nano-staged_light.svg +4 -4
  71. package/src/assets/icons/file-types/opa.svg +9 -9
  72. package/src/assets/icons/file-types/quarto.svg +5 -5
  73. package/src/assets/icons/file-types/rome.svg +6 -6
  74. package/src/assets/icons/file-types/stitches_light.svg +10 -10
  75. package/src/assets/icons/file-types/stylelint_light.svg +13 -13
  76. package/src/assets/icons/file-types/unocss.svg +5 -5
  77. package/src/assets/icons/file-types/vlang.svg +6 -6
  78. package/src/assets/icons/provider/302ai.svg +6 -6
  79. package/src/assets/icons/provider/abacus.svg +14 -14
  80. package/src/assets/icons/provider/aihubmix.svg +3 -3
  81. package/src/assets/icons/provider/alibaba-cn.svg +3 -3
  82. package/src/assets/icons/provider/alibaba-coding-plan-cn.svg +3 -3
  83. package/src/assets/icons/provider/alibaba-coding-plan.svg +3 -3
  84. package/src/assets/icons/provider/alibaba.svg +3 -3
  85. package/src/assets/icons/provider/amazon-bedrock.svg +3 -3
  86. package/src/assets/icons/provider/anthropic.svg +2 -2
  87. package/src/assets/icons/provider/azure-cognitive-services.svg +24 -24
  88. package/src/assets/icons/provider/azure.svg +3 -3
  89. package/src/assets/icons/provider/bailing.svg +3 -3
  90. package/src/assets/icons/provider/baseten.svg +3 -3
  91. package/src/assets/icons/provider/berget.svg +2 -2
  92. package/src/assets/icons/provider/cerebras.svg +4 -4
  93. package/src/assets/icons/provider/chutes.svg +24 -24
  94. package/src/assets/icons/provider/clarifai.svg +24 -24
  95. package/src/assets/icons/provider/claude-agent.svg +3 -3
  96. package/src/assets/icons/provider/cloudferro-sherlock.svg +4 -4
  97. package/src/assets/icons/provider/cloudflare-ai-gateway.svg +4 -4
  98. package/src/assets/icons/provider/cloudflare-workers-ai.svg +4 -4
  99. package/src/assets/icons/provider/cohere.svg +5 -5
  100. package/src/assets/icons/provider/cortecs.svg +24 -24
  101. package/src/assets/icons/provider/deepinfra.svg +4 -4
  102. package/src/assets/icons/provider/deepseek.svg +3 -3
  103. package/src/assets/icons/provider/digitalocean.svg +6 -6
  104. package/src/assets/icons/provider/dinference.svg +1 -1
  105. package/src/assets/icons/provider/drun.svg +8 -8
  106. package/src/assets/icons/provider/evroc.svg +2 -2
  107. package/src/assets/icons/provider/fastrouter.svg +3 -3
  108. package/src/assets/icons/provider/fireworks-ai.svg +3 -3
  109. package/src/assets/icons/provider/firmware.svg +18 -18
  110. package/src/assets/icons/provider/friendli.svg +3 -3
  111. package/src/assets/icons/provider/github-copilot.svg +3 -3
  112. package/src/assets/icons/provider/github-models.svg +3 -3
  113. package/src/assets/icons/provider/gitlab.svg +3 -3
  114. package/src/assets/icons/provider/google-vertex-anthropic.svg +24 -24
  115. package/src/assets/icons/provider/google-vertex.svg +10 -10
  116. package/src/assets/icons/provider/google.svg +3 -3
  117. package/src/assets/icons/provider/groq.svg +3 -3
  118. package/src/assets/icons/provider/helicone.svg +6 -6
  119. package/src/assets/icons/provider/huggingface.svg +3 -3
  120. package/src/assets/icons/provider/iflowcn.svg +3 -3
  121. package/src/assets/icons/provider/inception.svg +4 -4
  122. package/src/assets/icons/provider/inference.svg +3 -3
  123. package/src/assets/icons/provider/io-net.svg +5 -5
  124. package/src/assets/icons/provider/jiekou.svg +4 -4
  125. package/src/assets/icons/provider/kilo.svg +4 -4
  126. package/src/assets/icons/provider/kimi-for-coding.svg +3 -3
  127. package/src/assets/icons/provider/kuae-cloud-coding-plan.svg +3 -3
  128. package/src/assets/icons/provider/llama.svg +3 -3
  129. package/src/assets/icons/provider/lmstudio.svg +24 -24
  130. package/src/assets/icons/provider/lucidquery.svg +3 -3
  131. package/src/assets/icons/provider/meganova.svg +3 -3
  132. package/src/assets/icons/provider/meituan.svg +6 -6
  133. package/src/assets/icons/provider/meta.svg +3 -3
  134. package/src/assets/icons/provider/minimax-cn-coding-plan.svg +24 -24
  135. package/src/assets/icons/provider/minimax-cn.svg +3 -3
  136. package/src/assets/icons/provider/minimax-coding-plan.svg +24 -24
  137. package/src/assets/icons/provider/minimax.svg +3 -3
  138. package/src/assets/icons/provider/mistral.svg +3 -3
  139. package/src/assets/icons/provider/moark.svg +3 -3
  140. package/src/assets/icons/provider/modelscope.svg +5 -5
  141. package/src/assets/icons/provider/moonshotai-cn.svg +3 -3
  142. package/src/assets/icons/provider/moonshotai.svg +3 -3
  143. package/src/assets/icons/provider/morph.svg +24 -24
  144. package/src/assets/icons/provider/nano-gpt.svg +2 -2
  145. package/src/assets/icons/provider/nebius.svg +4 -4
  146. package/src/assets/icons/provider/nova.svg +3 -3
  147. package/src/assets/icons/provider/novita-ai.svg +10 -10
  148. package/src/assets/icons/provider/nvidia.svg +3 -3
  149. package/src/assets/icons/provider/ollama-cloud.svg +7 -7
  150. package/src/assets/icons/provider/openai.svg +3 -3
  151. package/src/assets/icons/provider/opencode-go.svg +3 -3
  152. package/src/assets/icons/provider/opencode.svg +3 -3
  153. package/src/assets/icons/provider/openrouter.svg +3 -3
  154. package/src/assets/icons/provider/ovhcloud.svg +3 -3
  155. package/src/assets/icons/provider/perplexity-agent.svg +3 -3
  156. package/src/assets/icons/provider/perplexity.svg +3 -3
  157. package/src/assets/icons/provider/poe.svg +7 -7
  158. package/src/assets/icons/provider/privatemode-ai.svg +4 -4
  159. package/src/assets/icons/provider/qihang-ai.svg +8 -8
  160. package/src/assets/icons/provider/qiniu-ai.svg +7 -7
  161. package/src/assets/icons/provider/reflection.svg +3 -3
  162. package/src/assets/icons/provider/requesty.svg +24 -24
  163. package/src/assets/icons/provider/sap-ai-core.svg +24 -24
  164. package/src/assets/icons/provider/scaleway.svg +5 -5
  165. package/src/assets/icons/provider/siliconflow-cn.svg +3 -3
  166. package/src/assets/icons/provider/siliconflow.svg +3 -3
  167. package/src/assets/icons/provider/stackit.svg +4 -4
  168. package/src/assets/icons/provider/stepfun.svg +16 -16
  169. package/src/assets/icons/provider/submodel.svg +3 -3
  170. package/src/assets/icons/provider/synthetic.svg +24 -24
  171. package/src/assets/icons/provider/tencent-coding-plan.svg +5 -5
  172. package/src/assets/icons/provider/tencent.svg +3 -3
  173. package/src/assets/icons/provider/thinkingmachines.svg +3 -3
  174. package/src/assets/icons/provider/togetherai.svg +4 -4
  175. package/src/assets/icons/provider/upstage.svg +24 -24
  176. package/src/assets/icons/provider/v0.svg +3 -3
  177. package/src/assets/icons/provider/venice.svg +4 -4
  178. package/src/assets/icons/provider/vercel.svg +3 -3
  179. package/src/assets/icons/provider/vivgrid.svg +4 -4
  180. package/src/assets/icons/provider/vultr.svg +6 -6
  181. package/src/assets/icons/provider/wandb.svg +24 -24
  182. package/src/assets/icons/provider/xai.svg +3 -3
  183. package/src/assets/icons/provider/xiaomi.svg +3 -3
  184. package/src/assets/icons/provider/zai-coding-plan.svg +3 -3
  185. package/src/assets/icons/provider/zai.svg +3 -3
  186. package/src/assets/icons/provider/zenmux.svg +4 -4
  187. package/src/assets/icons/provider/zhipuai-coding-plan.svg +3 -3
  188. package/src/assets/icons/provider/zhipuai.svg +3 -3
  189. package/src/components/animated-number-machine.ts +214 -214
  190. package/src/components/animated-number.css +110 -110
  191. package/src/components/animated-number.stories.tsx +35 -35
  192. package/src/components/animated-number.tsx +202 -202
  193. package/src/components/app-icon.css +5 -5
  194. package/src/components/app-icon.stories.tsx +73 -73
  195. package/src/components/app-icon.tsx +89 -89
  196. package/src/components/app-icons/sprite.svg +114 -114
  197. package/src/components/app-icons/types.ts +22 -22
  198. package/src/components/card.css +94 -94
  199. package/src/components/card.stories.tsx +101 -101
  200. package/src/components/card.tsx +145 -145
  201. package/src/components/collapsible.css +139 -139
  202. package/src/components/collapsible.stories.tsx +76 -76
  203. package/src/components/collapsible.tsx +62 -62
  204. package/src/components/context-menu.css +134 -134
  205. package/src/components/context-menu.stories.tsx +150 -150
  206. package/src/components/context-menu.tsx +342 -342
  207. package/src/components/diagram-preview.css +95 -95
  208. package/src/components/diagram-preview.stories.tsx +62 -62
  209. package/src/components/diagram-preview.tsx +332 -332
  210. package/src/components/dock-surface.css +30 -30
  211. package/src/components/dock-surface.stories.tsx +26 -26
  212. package/src/components/dock-surface.tsx +40 -40
  213. package/src/components/document-surface.css +37 -37
  214. package/src/components/document-surface.stories.tsx +42 -42
  215. package/src/components/document-surface.tsx +6 -6
  216. package/src/components/error-details.css +41 -41
  217. package/src/components/error-details.stories.tsx +72 -72
  218. package/src/components/error-details.tsx +13 -13
  219. package/src/components/favicon.stories.tsx +49 -49
  220. package/src/components/favicon.tsx +13 -13
  221. package/src/components/file-icon-machine.ts +78 -78
  222. package/src/components/file-icon.css +6 -6
  223. package/src/components/file-icon.stories.tsx +93 -93
  224. package/src/components/file-icon.tsx +186 -186
  225. package/src/components/file-icons/choose-icon-name.ts +574 -574
  226. package/src/components/file-icons/sprite.svg +11707 -11707
  227. package/src/components/file-icons/types.ts +1095 -1095
  228. package/src/components/font.stories.tsx +48 -48
  229. package/src/components/font.tsx +1 -1
  230. package/src/components/hover-card.css +61 -61
  231. package/src/components/hover-card.stories.tsx +79 -79
  232. package/src/components/hover-card.tsx +32 -32
  233. package/src/components/image-flight-machine.ts +247 -247
  234. package/src/components/image-flight.ts +161 -161
  235. package/src/components/image-preview.css +202 -202
  236. package/src/components/image-preview.stories.tsx +392 -392
  237. package/src/components/image-preview.tsx +908 -908
  238. package/src/components/image-zoom-machine.ts +191 -191
  239. package/src/components/image-zoom.ts +124 -124
  240. package/src/components/list.css +331 -331
  241. package/src/components/list.stories.tsx +221 -221
  242. package/src/components/list.tsx +322 -322
  243. package/src/components/logo.css +4 -4
  244. package/src/components/logo.stories.tsx +62 -62
  245. package/src/components/logo.tsx +62 -62
  246. package/src/components/menu-scroll.css +70 -70
  247. package/src/components/menu-scroll.stories.tsx +73 -73
  248. package/src/components/menu-scroll.tsx +202 -202
  249. package/src/components/motion-spring.tsx +65 -65
  250. package/src/components/popover-machine.ts +198 -198
  251. package/src/components/popover.css +66 -66
  252. package/src/components/popover.stories.tsx +84 -84
  253. package/src/components/popover.tsx +234 -234
  254. package/src/components/preview-controls.css +28 -28
  255. package/src/components/preview-controls.stories.tsx +40 -40
  256. package/src/components/preview-controls.tsx +53 -53
  257. package/src/components/progress.css +63 -63
  258. package/src/components/progress.stories.tsx +69 -69
  259. package/src/components/progress.tsx +39 -39
  260. package/src/components/provider-icon.css +5 -5
  261. package/src/components/provider-icon.stories.tsx +75 -75
  262. package/src/components/provider-icon.tsx +31 -31
  263. package/src/components/provider-icons/sprite.svg +1131 -1131
  264. package/src/components/provider-icons/types.ts +111 -111
  265. package/src/components/resize-handle-machine.ts +174 -174
  266. package/src/components/resize-handle.css +81 -81
  267. package/src/components/resize-handle.stories.tsx +81 -81
  268. package/src/components/resize-handle.tsx +164 -164
  269. package/src/components/rolling-number.css +24 -24
  270. package/src/components/rolling-number.stories.tsx +23 -23
  271. package/src/components/rolling-number.tsx +135 -135
  272. package/src/components/scroll-view-machine.ts +244 -244
  273. package/src/components/scroll-view.css +99 -99
  274. package/src/components/scroll-view.stories.tsx +68 -68
  275. package/src/components/scroll-view.tsx +653 -653
  276. package/src/components/spinner-frames.css +6 -6
  277. package/src/components/spinner-radar.ts +150 -150
  278. package/src/components/spinner.css +38 -38
  279. package/src/components/spinner.stories.tsx +40 -40
  280. package/src/components/spinner.tsx +43 -43
  281. package/src/components/sticky-accordion-header.css +11 -11
  282. package/src/components/sticky-accordion-header.stories.tsx +64 -64
  283. package/src/components/sticky-accordion-header.tsx +18 -18
  284. package/src/components/text-field-machine.ts +102 -102
  285. package/src/components/text-field.css +134 -134
  286. package/src/components/text-field.stories.tsx +132 -132
  287. package/src/components/text-field.tsx +196 -196
  288. package/src/components/text-reveal-machine.ts +184 -184
  289. package/src/components/text-reveal.css +150 -150
  290. package/src/components/text-reveal.stories.tsx +363 -363
  291. package/src/components/text-reveal.tsx +165 -165
  292. package/src/components/text-strikethrough.css +27 -27
  293. package/src/components/text-strikethrough.stories.tsx +296 -296
  294. package/src/components/text-strikethrough.tsx +92 -92
  295. package/src/components/thinking-heading.stories.tsx +900 -900
  296. package/src/components/truncated-text.css +25 -25
  297. package/src/components/truncated-text.stories.tsx +37 -37
  298. package/src/components/truncated-text.tsx +30 -30
  299. package/src/components/typewriter-machine.ts +134 -134
  300. package/src/components/typewriter.css +14 -14
  301. package/src/components/typewriter.stories.tsx +51 -51
  302. package/src/components/typewriter.tsx +70 -70
  303. package/src/context/dialog-machine.ts +281 -281
  304. package/src/context/dialog.tsx +376 -376
  305. package/src/context/file.tsx +11 -11
  306. package/src/context/focus-rescue.tsx +230 -230
  307. package/src/context/helper.tsx +43 -43
  308. package/src/context/highlight-theme.tsx +66 -66
  309. package/src/context/i18n.tsx +144 -144
  310. package/src/context/index.ts +7 -7
  311. package/src/context/marked-base.tsx +67 -67
  312. package/src/context/marked-parser.tsx +154 -154
  313. package/src/context/overlay-focus.tsx +90 -90
  314. package/src/custom-elements.d.ts +17 -17
  315. package/src/data-display/accordion/accordion.css +130 -130
  316. package/src/data-display/accordion/accordion.stories.tsx +76 -76
  317. package/src/data-display/accordion/accordion.tsx +106 -106
  318. package/src/data-display/avatar/avatar.css +70 -70
  319. package/src/data-display/avatar/avatar.stories.tsx +48 -48
  320. package/src/data-display/avatar/avatar.tsx +63 -63
  321. package/src/data-display/badge/badge.css +63 -63
  322. package/src/data-display/badge/badge.stories.tsx +75 -75
  323. package/src/data-display/badge/badge.tsx +26 -26
  324. package/src/data-display/diff-changes/diff-changes.css +47 -47
  325. package/src/data-display/diff-changes/diff-changes.stories.tsx +63 -63
  326. package/src/data-display/diff-changes/diff-changes.tsx +43 -43
  327. package/src/data-display/keybind/keybind.css +84 -84
  328. package/src/data-display/keybind/keybind.stories.tsx +77 -77
  329. package/src/data-display/keybind/keybind.tsx +31 -31
  330. package/src/data-display/line-comment/line-comment.css +341 -341
  331. package/src/data-display/line-comment/line-comment.stories.tsx +288 -288
  332. package/src/data-display/line-comment/line-comment.tsx +554 -554
  333. package/src/data-display/line-comment/machine.ts +400 -400
  334. package/src/data-display/line-comment/quote-check.svg +3 -3
  335. package/src/data-display/project-avatar/animation-machine.ts +182 -182
  336. package/src/data-display/project-avatar/animation.ts +133 -133
  337. package/src/data-display/project-avatar/generated.ts +225 -225
  338. package/src/data-display/project-avatar/procedural-craft.ts +1079 -1079
  339. package/src/data-display/project-avatar/procedural-kit.ts +244 -244
  340. package/src/data-display/project-avatar/procedural-machine.ts +924 -924
  341. package/src/data-display/project-avatar/procedural-world.ts +1542 -1542
  342. package/src/data-display/project-avatar/procedural.ts +1563 -1563
  343. package/src/data-display/project-avatar/project-avatar.css +189 -189
  344. package/src/data-display/project-avatar/project-avatar.stories.tsx +102 -102
  345. package/src/data-display/project-avatar/project-avatar.tsx +246 -246
  346. package/src/data-display/project-avatar/project-icon-styles.stories.tsx +772 -772
  347. package/src/feedback/activity-ring/activity-ring.css +5 -5
  348. package/src/feedback/activity-ring/activity-ring.stories.tsx +20 -20
  349. package/src/feedback/activity-ring/activity-ring.tsx +15 -15
  350. package/src/feedback/loader/loader.css +32 -32
  351. package/src/feedback/loader/loader.stories.tsx +44 -44
  352. package/src/feedback/loader/loader.tsx +34 -34
  353. package/src/feedback/progress-circle/progress-circle.css +28 -28
  354. package/src/feedback/progress-circle/progress-circle.stories.tsx +56 -56
  355. package/src/feedback/progress-circle/progress-circle.tsx +64 -64
  356. package/src/feedback/toast/description.ts +10 -10
  357. package/src/feedback/toast/machine.ts +115 -115
  358. package/src/feedback/toast/toast.css +234 -234
  359. package/src/feedback/toast/toast.stories.tsx +186 -186
  360. package/src/feedback/toast/toast.tsx +317 -317
  361. package/src/forms/checkbox/checkbox-compact.css +170 -170
  362. package/src/forms/checkbox/checkbox.css +125 -125
  363. package/src/forms/checkbox/checkbox.stories.tsx +104 -104
  364. package/src/forms/checkbox/checkbox.tsx +119 -119
  365. package/src/forms/field/field.css +94 -94
  366. package/src/forms/field/field.stories.tsx +129 -129
  367. package/src/forms/field/field.tsx +271 -271
  368. package/src/forms/inline-input/inline-input.css +16 -16
  369. package/src/forms/inline-input/inline-input.stories.tsx +37 -37
  370. package/src/forms/inline-input/inline-input.tsx +26 -26
  371. package/src/forms/radio/radio.css +218 -218
  372. package/src/forms/radio/radio.stories.tsx +145 -145
  373. package/src/forms/radio/radio.tsx +95 -95
  374. package/src/forms/redirect-paste/redirect-paste.stories.tsx +101 -101
  375. package/src/forms/redirect-paste/redirect-paste.tsx +92 -92
  376. package/src/forms/search-list/navigation.ts +54 -54
  377. package/src/forms/search-list/search-list.css +249 -249
  378. package/src/forms/search-list/search-list.stories.tsx +108 -108
  379. package/src/forms/search-list/search-list.tsx +463 -463
  380. package/src/forms/select/machine.ts +81 -81
  381. package/src/forms/select/select.css +312 -312
  382. package/src/forms/select/select.stories.tsx +208 -208
  383. package/src/forms/select/select.tsx +281 -281
  384. package/src/forms/switch/switch.css +281 -281
  385. package/src/forms/switch/switch.stories.tsx +97 -97
  386. package/src/forms/switch/switch.tsx +35 -35
  387. package/src/forms/text-input/text-input.css +229 -229
  388. package/src/forms/text-input/text-input.stories.tsx +220 -220
  389. package/src/forms/text-input/text-input.tsx +115 -115
  390. package/src/forms/textarea/textarea.css +103 -103
  391. package/src/forms/textarea/textarea.stories.tsx +137 -137
  392. package/src/forms/textarea/textarea.tsx +33 -33
  393. package/src/forms/typeahead/controller.ts +59 -59
  394. package/src/forms/typeahead/machine.ts +253 -253
  395. package/src/forms/typeahead/typeahead.stories.tsx +113 -113
  396. package/src/forms/typeahead/typeahead.tsx +239 -239
  397. package/src/hooks/auto-scroll-machine.ts +261 -261
  398. package/src/hooks/create-auto-scroll.tsx +196 -196
  399. package/src/hooks/index.ts +5 -5
  400. package/src/hooks/list-machine.ts +359 -359
  401. package/src/hooks/spin-phase.ts +116 -116
  402. package/src/hooks/use-filtered-list.tsx +132 -132
  403. package/src/i18n/am.ts +384 -384
  404. package/src/i18n/ar.ts +547 -547
  405. package/src/i18n/az.ts +386 -386
  406. package/src/i18n/bg.ts +386 -386
  407. package/src/i18n/bn.ts +393 -393
  408. package/src/i18n/br.ts +444 -444
  409. package/src/i18n/bs.ts +445 -445
  410. package/src/i18n/ca.ts +423 -423
  411. package/src/i18n/cs.ts +457 -457
  412. package/src/i18n/da.ts +407 -407
  413. package/src/i18n/de.ts +414 -414
  414. package/src/i18n/dv.ts +395 -395
  415. package/src/i18n/dz.ts +393 -393
  416. package/src/i18n/el.ts +388 -388
  417. package/src/i18n/en.ts +433 -433
  418. package/src/i18n/es.ts +443 -443
  419. package/src/i18n/et.ts +386 -386
  420. package/src/i18n/fa.ts +388 -388
  421. package/src/i18n/fi.ts +388 -388
  422. package/src/i18n/fo.ts +388 -388
  423. package/src/i18n/fr.ts +447 -447
  424. package/src/i18n/he.ts +422 -422
  425. package/src/i18n/hi.ts +392 -392
  426. package/src/i18n/hr.ts +422 -422
  427. package/src/i18n/hu.ts +388 -388
  428. package/src/i18n/hy.ts +389 -389
  429. package/src/i18n/id.ts +411 -411
  430. package/src/i18n/is.ts +388 -388
  431. package/src/i18n/it.ts +425 -425
  432. package/src/i18n/ja.ts +406 -406
  433. package/src/i18n/ka.ts +388 -388
  434. package/src/i18n/km.ts +389 -389
  435. package/src/i18n/ko.ts +408 -408
  436. package/src/i18n/lo.ts +387 -387
  437. package/src/i18n/lt.ts +457 -457
  438. package/src/i18n/lv.ts +421 -421
  439. package/src/i18n/mk.ts +387 -387
  440. package/src/i18n/mn.ts +386 -386
  441. package/src/i18n/ms.ts +389 -389
  442. package/src/i18n/my.ts +389 -389
  443. package/src/i18n/ne.ts +393 -393
  444. package/src/i18n/nl.ts +388 -388
  445. package/src/i18n/no.ts +413 -413
  446. package/src/i18n/pa.ts +394 -394
  447. package/src/i18n/pl.ts +476 -476
  448. package/src/i18n/ro.ts +423 -423
  449. package/src/i18n/ru.ts +475 -475
  450. package/src/i18n/si.ts +390 -390
  451. package/src/i18n/sk.ts +457 -457
  452. package/src/i18n/sl.ts +457 -457
  453. package/src/i18n/sq.ts +387 -387
  454. package/src/i18n/sr.ts +422 -422
  455. package/src/i18n/sv.ts +388 -388
  456. package/src/i18n/tg.ts +390 -390
  457. package/src/i18n/th.ts +407 -407
  458. package/src/i18n/tk.ts +386 -386
  459. package/src/i18n/tr.ts +412 -412
  460. package/src/i18n/uk.ts +480 -480
  461. package/src/i18n/ur.ts +394 -394
  462. package/src/i18n/uz.ts +390 -390
  463. package/src/i18n/vi.ts +387 -387
  464. package/src/i18n/zh.ts +408 -408
  465. package/src/i18n/zht.ts +408 -408
  466. package/src/icons/catalog.ts +638 -638
  467. package/src/icons/icon/icon.css +3 -3
  468. package/src/icons/icon/icon.stories.tsx +131 -131
  469. package/src/icons/icon/icon.tsx +106 -106
  470. package/src/icons/registry.ts +217 -217
  471. package/src/layout/divider/divider.css +11 -11
  472. package/src/layout/divider/divider.stories.tsx +38 -38
  473. package/src/layout/divider/divider.tsx +21 -21
  474. package/src/motion/README.md +113 -113
  475. package/src/motion/index.ts +13 -13
  476. package/src/motion/loop.ts +139 -139
  477. package/src/motion/reduced.ts +66 -66
  478. package/src/motion/slider.ts +45 -45
  479. package/src/motion/solid.ts +309 -309
  480. package/src/motion/spring.ts +125 -125
  481. package/src/motion/velocity.ts +46 -46
  482. package/src/motion/waapi.ts +89 -89
  483. package/src/motion-tuning-features.ts +161 -161
  484. package/src/motion-tuning-fields.ts +42 -42
  485. package/src/motion-tuning.ts +323 -323
  486. package/src/navigation/menu/machine.ts +109 -109
  487. package/src/navigation/menu/menu.css +313 -313
  488. package/src/navigation/menu/menu.stories.tsx +328 -328
  489. package/src/navigation/menu/menu.tsx +600 -600
  490. package/src/navigation/menu/submenu-machine.ts +67 -67
  491. package/src/navigation/segmented-control/machine.ts +72 -72
  492. package/src/navigation/segmented-control/segmented-control.css +113 -113
  493. package/src/navigation/segmented-control/segmented-control.stories.tsx +115 -115
  494. package/src/navigation/segmented-control/segmented-control.tsx +396 -396
  495. package/src/navigation/tab-state-indicator.stories.tsx +24 -24
  496. package/src/navigation/tab-state-indicator.tsx +38 -38
  497. package/src/navigation/tabs/tabs-current.css +244 -244
  498. package/src/navigation/tabs/tabs.css +676 -676
  499. package/src/navigation/tabs/tabs.stories.tsx +193 -193
  500. package/src/navigation/tabs/tabs.tsx +212 -212
  501. package/src/overlays/dialog/dialog.css +194 -194
  502. package/src/overlays/dialog/dialog.stories.tsx +365 -365
  503. package/src/overlays/dialog/dialog.tsx +192 -192
  504. package/src/overlays/mcp-sign-in/machine.ts +343 -343
  505. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -159
  506. package/src/overlays/tooltip/machine.ts +312 -312
  507. package/src/overlays/tooltip/tooltip.css +102 -102
  508. package/src/overlays/tooltip/tooltip.stories.tsx +155 -155
  509. package/src/overlays/tooltip/tooltip.tsx +290 -290
  510. package/src/storybook/fixtures.ts +51 -51
  511. package/src/storybook/scaffold.tsx +65 -65
  512. package/src/styles/animations.css +13 -13
  513. package/src/styles/base.css +441 -441
  514. package/src/styles/blue-tokens.stories.tsx +215 -215
  515. package/src/styles/colors.css +772 -772
  516. package/src/styles/file-tree.css +285 -285
  517. package/src/styles/index.css +42 -42
  518. package/src/styles/scrollbar.css +79 -79
  519. package/src/styles/tailwind/colors.css +288 -288
  520. package/src/styles/tailwind/index.css +113 -113
  521. package/src/styles/tailwind/utilities.css +17 -17
  522. package/src/styles/theme.css +640 -640
  523. package/src/styles/tokens/colors.css +172 -172
  524. package/src/styles/tokens/index.css +2 -2
  525. package/src/styles/tokens/theme.css +522 -522
  526. package/src/styles/utilities.css +93 -93
  527. package/src/theme/color.ts +290 -290
  528. package/src/theme/context.tsx +361 -361
  529. package/src/theme/desktop-theme.schema.json +168 -168
  530. package/src/theme/index.ts +35 -35
  531. package/src/theme/machine.ts +508 -508
  532. package/src/theme/resolve.ts +561 -561
  533. package/src/theme/themes/amoled.json +49 -49
  534. package/src/theme/themes/aura.json +51 -51
  535. package/src/theme/themes/ayu.json +51 -51
  536. package/src/theme/themes/carbonfox.json +53 -53
  537. package/src/theme/themes/catppuccin-frappe.json +65 -65
  538. package/src/theme/themes/catppuccin-macchiato.json +65 -65
  539. package/src/theme/themes/catppuccin.json +45 -45
  540. package/src/theme/themes/cobalt2.json +87 -87
  541. package/src/theme/themes/cursor.json +91 -91
  542. package/src/theme/themes/dracula.json +49 -49
  543. package/src/theme/themes/everforest.json +89 -89
  544. package/src/theme/themes/flexoki.json +86 -86
  545. package/src/theme/themes/github.json +85 -85
  546. package/src/theme/themes/gruvbox.json +45 -45
  547. package/src/theme/themes/kanagawa.json +89 -89
  548. package/src/theme/themes/lucent-orng.json +87 -87
  549. package/src/theme/themes/material.json +87 -87
  550. package/src/theme/themes/matrix.json +113 -113
  551. package/src/theme/themes/mercury.json +86 -86
  552. package/src/theme/themes/monokai.json +49 -49
  553. package/src/theme/themes/nightowl.json +46 -46
  554. package/src/theme/themes/nord.json +46 -46
  555. package/src/theme/themes/oc-2.json +509 -509
  556. package/src/theme/themes/one-dark.json +89 -89
  557. package/src/theme/themes/onedarkpro.json +45 -45
  558. package/src/theme/themes/orng.json +87 -87
  559. package/src/theme/themes/osaka-jade.json +88 -88
  560. package/src/theme/themes/palenight.json +85 -85
  561. package/src/theme/themes/rosepine.json +85 -85
  562. package/src/theme/themes/shadesofpurple.json +51 -51
  563. package/src/theme/themes/solarized.json +49 -49
  564. package/src/theme/themes/synthwave84.json +87 -87
  565. package/src/theme/themes/tokyonight.json +47 -47
  566. package/src/theme/themes/vercel.json +90 -90
  567. package/src/theme/themes/vesper.json +51 -51
  568. package/src/theme/themes/zenburn.json +87 -87
  569. package/src/theme/types.ts +75 -75
  570. package/src/theme/v2/avatar.ts +48 -48
  571. package/src/theme/v2/default-primitives.ts +114 -114
  572. package/src/theme/v2/foreground.ts +69 -69
  573. package/src/theme/v2/mapping.ts +180 -180
  574. package/src/theme/v2/resolve.ts +163 -163
  575. package/src/typography/slash/slash.css +14 -14
  576. package/src/typography/slash/slash.stories.tsx +26 -26
  577. package/src/typography/slash/slash.tsx +16 -16
  578. package/src/typography/text-shimmer/machine.ts +90 -90
  579. package/src/typography/text-shimmer/text-shimmer.css +152 -152
  580. package/src/typography/text-shimmer/text-shimmer.stories.tsx +64 -64
  581. package/src/typography/text-shimmer/text-shimmer.tsx +81 -81
  582. package/src/typography/wordmark/wordmark.stories.tsx +19 -19
  583. package/src/typography/wordmark/wordmark.tsx +73 -73
  584. package/test/solid-jsx.ts +20 -20
  585. package/tsconfig.build.json +14 -14
  586. package/tsconfig.json +23 -23
  587. package/vite.config.ts +61 -61
  588. package/src/components/animated-number-machine.test.ts +0 -140
  589. package/src/components/file-icon-machine.test.ts +0 -52
  590. package/src/components/image-flight-machine.test.ts +0 -184
  591. package/src/components/image-flight.test.ts +0 -173
  592. package/src/components/image-zoom-machine.test.ts +0 -154
  593. package/src/components/image-zoom.test.ts +0 -96
  594. package/src/components/popover-machine.test.ts +0 -150
  595. package/src/components/resize-handle-machine.test.ts +0 -164
  596. package/src/components/scroll-view-machine.test.ts +0 -141
  597. package/src/components/scroll-view.test.ts +0 -114
  598. package/src/components/spinner-radar.test.ts +0 -61
  599. package/src/components/text-field-machine.test.ts +0 -99
  600. package/src/components/text-reveal-machine.test.ts +0 -157
  601. package/src/components/typewriter-machine.test.ts +0 -177
  602. package/src/context/dialog-machine.test.ts +0 -295
  603. package/src/context/i18n.test.ts +0 -89
  604. package/src/context/marked-base.test.ts +0 -75
  605. package/src/context/marked-parser.test.ts +0 -167
  606. package/src/context/marked-regression.test.ts +0 -12
  607. package/src/data-display/line-comment/machine.test.ts +0 -385
  608. package/src/data-display/project-avatar/animation-machine.test.ts +0 -134
  609. package/src/data-display/project-avatar/generated.test.ts +0 -50
  610. package/src/data-display/project-avatar/procedural.test.ts +0 -16
  611. package/src/data-display/project-avatar/project-avatar.test.ts +0 -21
  612. package/src/feedback/toast/description.test.ts +0 -20
  613. package/src/feedback/toast/machine.test.ts +0 -106
  614. package/src/forms/search-list/navigation.test.ts +0 -40
  615. package/src/forms/select/machine.test.ts +0 -105
  616. package/src/forms/typeahead/machine.test.ts +0 -143
  617. package/src/hooks/auto-scroll-machine.test.ts +0 -212
  618. package/src/hooks/list-machine.test.ts +0 -263
  619. package/src/hooks/spin-phase.test.ts +0 -32
  620. package/src/hooks/use-filtered-list.test.ts +0 -41
  621. package/src/motion/core.test.ts +0 -328
  622. package/src/motion-tuning-features.test.ts +0 -129
  623. package/src/motion-tuning.test.ts +0 -68
  624. package/src/navigation/menu/machine.test.ts +0 -85
  625. package/src/navigation/menu/submenu-machine.test.ts +0 -71
  626. package/src/navigation/segmented-control/segmented-control.test.ts +0 -123
  627. package/src/overlays/mcp-sign-in/machine.test.ts +0 -215
  628. package/src/overlays/tooltip/machine.test.ts +0 -214
  629. package/src/theme/machine.test.ts +0 -498
  630. package/src/theme/v2/resolve.test.ts +0 -120
  631. package/src/typography/text-shimmer/machine.test.ts +0 -117
@@ -1,1563 +1,1563 @@
1
- // Experimental generators for the default project avatar, compared side by side in the components lab. Each keeps the
2
- // mesh's contract (see generated.ts): the values that define an icon are resolved once from a key, so a stored icon
3
- // never changes, and drawing is a CPU pass on a 2D canvas clipped to the same rounded tile. Most styles paint a small
4
- // grid of pixels that is scaled up nearest-neighbour, with limited palettes and ordered dithering. Only the components
5
- // lab imports this module.
6
-
7
- import { cyrb53, drawProjectIcon, generateProjectIcon, mulberry32, tileMask, valueNoise, type GeneratedProjectIcon } from "./generated"
8
- import { CRAFT } from "./procedural-craft"
9
- import {
10
- clamp01,
11
- colors,
12
- css,
13
- dither,
14
- ease,
15
- int,
16
- legible,
17
- luma,
18
- mix,
19
- normalize,
20
- ones,
21
- palette,
22
- pick,
23
- Pixels,
24
- prefixed,
25
- ramped,
26
- retry,
27
- seed,
28
- shade,
29
- shuffle,
30
- smoothstep,
31
- stars,
32
- threshold,
33
- tint,
34
- type Definition,
35
- } from "./procedural-kit"
36
- import { MACHINE } from "./procedural-machine"
37
- import { WORLD } from "./procedural-world"
38
-
39
- export type ProjectIconStyle = {
40
- readonly id: string
41
- readonly name: string
42
- readonly label: string
43
- /** The gallery group the style belongs to. */
44
- readonly family: string
45
- /** Whether the style has a hover animation. */
46
- readonly animated: boolean
47
- readonly generate: (key: string) => GeneratedProjectIcon
48
- /** Draws the icon `seconds` into its hover animation (0 is the static frame) into a square `px` × `px` context. */
49
- readonly draw: (ctx: CanvasRenderingContext2D, px: number, icon: GeneratedProjectIcon, seconds: number) => void
50
- }
51
-
52
- // Curated colors for scenes James's paper-and-ink palettes do not cover.
53
- const SPACE = [0x0e1027, 0x111827, 0x1a1033, 0x071a26, 0x14121f]
54
-
55
- const LEAVES = [0x4c956c, 0x2a9d8f, 0x606c38, 0x81b29a, 0x419d78, 0x3f7d3a]
56
-
57
- const SOILS = [0x6b4423, 0x5c3d2e, 0x3d2b1f, 0x7a5230]
58
-
59
- const PHOSPHORS = [0x39ff7a, 0xffb43a, 0x6fe3ff, 0xd6e4ff, 0xff6fb5]
60
-
61
- // Sky top, sky bottom, sun, far ridge, near ridge.
62
- const SCENES = [
63
- [0x2b1b4a, 0xf28c5a, 0xffe08a, 0x7a3d6b, 0x3a1f3d],
64
- [0x5fb4e8, 0xd9f1ff, 0xfff3b0, 0x6aa56a, 0x2f6b4f],
65
- [0x0b1030, 0x2a3a7a, 0xf0f0d0, 0x1f2a55, 0x0a0f24],
66
- [0xf2a65a, 0xfbe7c2, 0xfff8e0, 0xc4703f, 0x7a3e28],
67
- [0x8fc7e6, 0xeaf6fb, 0xffffff, 0x9fb8c8, 0x5c7488],
68
- [0xe89aa8, 0xfde2c8, 0xfff1d6, 0x6d8f71, 0x33503c],
69
- ]
70
-
71
- // Sky top, sky bottom, sun top, sun bottom, ground, grid lines.
72
- const SYNTH = [
73
- [0x1b0b3b, 0xe8467c, 0xffd166, 0xff5f7e, 0x13072e, 0xff4fd8],
74
- [0x0b132b, 0x5b4b8a, 0xfff07a, 0xff8c42, 0x0a0f1f, 0x3ad6ff],
75
- [0x2d1e4f, 0xff9a62, 0xfff3b0, 0xff6b6b, 0x24133b, 0xffb0d9],
76
- [0x08263b, 0x1f8a9e, 0xf9f871, 0xf2a65a, 0x061a26, 0x7af5d1],
77
- ]
78
-
79
- // Classic 8 × 8 one-bit fills, one byte per row.
80
- const PATTERNS = [
81
- [0xff, 0x80, 0x80, 0x80, 0xff, 0x08, 0x08, 0x08],
82
- [0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33],
83
- [0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0],
84
- [0x80, 0x80, 0x41, 0x3e, 0x08, 0x08, 0x14, 0xe3],
85
- [0x00, 0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x00],
86
- [0x81, 0x42, 0x24, 0x18, 0x81, 0x42, 0x24, 0x18],
87
- [0x00, 0x18, 0x18, 0x7e, 0x7e, 0x18, 0x18, 0x00],
88
- [0xff, 0x88, 0x88, 0x88, 0xff, 0x88, 0x88, 0x88],
89
- [0x18, 0x3c, 0x7e, 0xff, 0x7e, 0x3c, 0x18, 0x00],
90
- [0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc, 0x99],
91
- ]
92
-
93
- // 3 × 3 runes, top row in the high bits.
94
- const GLYPHS = [
95
- 0b010111010, 0b101010101, 0b111101111, 0b100100111, 0b111010010, 0b111000111, 0b101101101, 0b100010001, 0b110011001,
96
- 0b101101111, 0b111100111, 0b010101010, 0b011010110, 0b111001001,
97
- ]
98
-
99
- // The seven tetrominoes as cells, and their colors: the guideline set, a handheld's greys, an 8-bit set and pastels.
100
- const TETROMINOES = [
101
- [
102
- [0, 0],
103
- [1, 0],
104
- [2, 0],
105
- [3, 0],
106
- ],
107
- [
108
- [0, 0],
109
- [1, 0],
110
- [0, 1],
111
- [1, 1],
112
- ],
113
- [
114
- [0, 0],
115
- [1, 0],
116
- [2, 0],
117
- [1, 1],
118
- ],
119
- [
120
- [1, 0],
121
- [2, 0],
122
- [0, 1],
123
- [1, 1],
124
- ],
125
- [
126
- [0, 0],
127
- [1, 0],
128
- [1, 1],
129
- [2, 1],
130
- ],
131
- [
132
- [0, 0],
133
- [0, 1],
134
- [1, 1],
135
- [2, 1],
136
- ],
137
- [
138
- [2, 0],
139
- [0, 1],
140
- [1, 1],
141
- [2, 1],
142
- ],
143
- ]
144
-
145
- const TETROMINO_COLORS = [
146
- [0x2ad4e6, 0xf2d230, 0xa64ce0, 0x46d04a, 0xe8413c, 0x3a64e8, 0xf0902a],
147
- [0x9bbc0f, 0x8bac0f, 0x306230, 0x8bac0f, 0x306230, 0x9bbc0f, 0x306230],
148
- [0x3cbcfc, 0xf8b800, 0xd800cc, 0x58d854, 0xf83800, 0x0058f8, 0xfca044],
149
- [0x9ad8e8, 0xf6e3a1, 0xc9b1e8, 0xb5e3b0, 0xf2a7a7, 0xa7b8f2, 0xf5c09a],
150
- ]
151
-
152
- const RULES = [18, 22, 30, 60, 86, 90, 102, 110, 126, 150, 182]
153
-
154
- // An isometric cube eight pixels wide: top, left and right faces.
155
- const CUBE = ["...TT...", ".TTTTTT.", "LTTTTTTR", "LLLTTRRR", "LLLLRRRR", "LLLLRRRR", ".LLLRRR.", "...LR..."]
156
-
157
- const DEFINITIONS: Definition[] = [
158
- {
159
- id: "pixel-mesh",
160
- name: "Pixel mesh",
161
- family: "Gradients",
162
- label: "James's mesh waves on a 16 grid, dithered to its four inks",
163
- animated: true,
164
- resolve: (random) => {
165
- const position = random("mesh")
166
-
167
- return { grid: 16, seedX: position() * 40, seedY: position() * 40, ...palette(random("palette")) }
168
- },
169
- paint: (pixels, p, t) => {
170
- const inks = colors(p).slice(1)
171
-
172
- pixels.each((x, y) => {
173
- const u = (x + 0.5) / pixels.n
174
- const v = 1 - (y + 0.5) / pixels.n
175
- const mx = u * 3.6 + p.seedX
176
- const my = (v - u * 0.02) * 2.4 + p.seedY
177
-
178
- return [0, 1, 2].reduce((color, i) => {
179
- const sx = mx * (0.35 + 0.12 * i) + t * 0.2 * (i + 1)
180
- const sy = my * 0.6 + i * 3.7
181
- const k = smoothstep(0.35, 0.75, 0.65 * valueNoise(sx, sy) + 0.35 * valueNoise(sx * 2.1 + 7, sy * 2.1 + 7))
182
-
183
- return k > threshold(x, y) ? inks[i + 1] : color
184
- }, inks[0])
185
- })
186
- },
187
- },
188
- {
189
- id: "dither",
190
- name: "Dither ramp",
191
- family: "Pixel and dither",
192
- label: "A three-step gradient through a 4×4 Bayer matrix",
193
- animated: true,
194
- resolve: (random) => {
195
- const r = random("dither")
196
- const all = colors(palette(random("palette")))
197
- const ramp = ramped(shuffle(r, all).slice(0, 3))
198
-
199
- return {
200
- grid: 16,
201
- mode: r() < 0.6 ? 0 : 1,
202
- angle: r() * Math.PI * 2,
203
- cx: 0.15 + r() * 0.7,
204
- cy: 0.15 + r() * 0.7,
205
- ...prefixed("r", ramp),
206
- }
207
- },
208
- paint: (pixels, p, t) => {
209
- const ramp = colors(p, "r", 3)
210
- const angle = p.angle + t * 0.9
211
- const cx = p.cx + Math.sin(t * 1.3) * 0.2
212
- const cy = p.cy + Math.sin(t * 1.1) * 0.2
213
-
214
- pixels.each((x, y) => {
215
- const u = (x + 0.5) / pixels.n
216
- const v = (y + 0.5) / pixels.n
217
-
218
- const value =
219
- p.mode === 0
220
- ? ((u - 0.5) * Math.cos(angle) + (v - 0.5) * Math.sin(angle)) * 1.1 + 0.5
221
- : Math.hypot(u - cx, v - cy)
222
-
223
- return ramp[dither(value, 3, x, y)]
224
- })
225
- },
226
- },
227
- {
228
- id: "plasma",
229
- name: "Plasma",
230
- family: "Pixel and dither",
231
- label: "Demoscene sine plasma posterised to a five-step ramp",
232
- animated: true,
233
- resolve: (random) => {
234
- const r = random("plasma")
235
-
236
- return {
237
- grid: 16,
238
- a: 0.5 + r() * 0.7,
239
- b: 0.5 + r() * 0.7,
240
- c: 0.3 + r() * 0.5,
241
- d: 0.6 + r() * 0.8,
242
- p1: r() * 6.28,
243
- p2: r() * 6.28,
244
- p3: r() * 6.28,
245
- cx: r(),
246
- cy: r(),
247
- ...prefixed("r", ramped(colors(palette(random("palette"))))),
248
- }
249
- },
250
- paint: (pixels, p, t) => {
251
- const ramp = colors(p, "r", 5)
252
-
253
- pixels.each((x, y) => {
254
- const X = ((x + 0.5) / pixels.n) * 6.28
255
- const Y = ((y + 0.5) / pixels.n) * 6.28
256
-
257
- const value =
258
- (Math.sin(X * p.a + p.p1 + t * 1.6) +
259
- Math.sin(Y * p.b + p.p2 - t * 1.1) +
260
- Math.sin((X + Y) * p.c + p.p3 + t * 0.8) +
261
- Math.sin(Math.hypot(X - p.cx * 6.28, Y - p.cy * 6.28) * p.d - t * 2)) /
262
- 4
263
-
264
- return ramp[Math.min(4, Math.floor(clamp01(value * 0.6 + 0.5) * 5))]
265
- })
266
- },
267
- },
268
- {
269
- id: "contour",
270
- name: "Contours",
271
- family: "Pixel and dither",
272
- label: "Topographic bands of value noise with darker iso-lines",
273
- animated: true,
274
- resolve: (random) => {
275
- const r = random("contour")
276
-
277
- return {
278
- grid: 16,
279
- seedX: r() * 40,
280
- seedY: r() * 40,
281
- scale: 1.6 + r(),
282
- ...prefixed("r", ramped(colors(palette(random("palette"))))),
283
- }
284
- },
285
- paint: (pixels, p, t) => {
286
- const ramp = colors(p, "r", 5)
287
- const n = pixels.n
288
-
289
- const band = (x: number, y: number) => {
290
- const X = (x / n) * p.scale + p.seedX + t * 0.3
291
- const Y = (y / n) * p.scale + p.seedY
292
- const h = 0.65 * valueNoise(X, Y) + 0.35 * valueNoise(X * 2.1 + 5, Y * 2.1 + 5)
293
-
294
- return Math.max(0, Math.min(4, Math.floor(((h - 0.2) / 0.6) * 5)))
295
- }
296
-
297
- const bands = Array.from({ length: (n + 2) * (n + 2) }, (_, i) =>
298
- band((i % (n + 2)) - 1, Math.floor(i / (n + 2)) - 1),
299
- )
300
-
301
- const at = (x: number, y: number) => bands[(y + 1) * (n + 2) + x + 1]
302
-
303
- pixels.each((x, y) => {
304
- const b = at(x, y)
305
- const edge = at(x + 1, y) < b || at(x - 1, y) < b || at(x, y + 1) < b || at(x, y - 1) < b
306
-
307
- return edge ? shade(ramp[b], 0.7) : ramp[b]
308
- })
309
- },
310
- },
311
- {
312
- id: "cells",
313
- name: "Cells",
314
- family: "Pixel and dither",
315
- label: "Voronoi cells from four to six seeds, with one-pixel seams",
316
- animated: true,
317
- resolve: (random) => ({ grid: 16, seed: seed(random("cells")), ...palette(random("palette")) }),
318
- paint: (pixels, p, t) => {
319
- const all = colors(p)
320
- const rand = mulberry32(p.seed)
321
- const offset = Math.floor(rand() * 5)
322
-
323
- const sites = Array.from({ length: 4 + Math.floor(rand() * 3) }, (_, i) => {
324
- const phase = rand() * 6.28
325
-
326
- return {
327
- x: rand() * pixels.n + Math.sin(t * 1.2 + phase) * 1.5 * Math.min(1, t),
328
- y: rand() * pixels.n + Math.cos(t * 1.2 + phase) * 1.5 * Math.min(1, t),
329
- color: all[(i + offset) % 5],
330
- }
331
- })
332
-
333
- const seam = shade(ramped(all)[0], 0.55)
334
-
335
- pixels.each((x, y) => {
336
- const distances = sites
337
- .map((site) => ({ color: site.color, d: Math.hypot(x + 0.5 - site.x, y + 0.5 - site.y) }))
338
- .toSorted((a, b) => a.d - b.d)
339
-
340
- return distances[1].d - distances[0].d < 1 ? seam : distances[0].color
341
- })
342
- },
343
- },
344
- {
345
- id: "rings",
346
- name: "Rings",
347
- family: "Patterns",
348
- label: "Off-centre concentric rings stepping through three inks",
349
- animated: true,
350
- resolve: (random) => {
351
- const r = random("rings")
352
-
353
- return {
354
- grid: 16,
355
- cx: 3 + r() * 10,
356
- cy: 3 + r() * 10,
357
- width: 1.5 + r(),
358
- ...prefixed("r", shuffle(r, colors(palette(random("palette")))).slice(0, 3)),
359
- }
360
- },
361
- paint: (pixels, p, t) => {
362
- const cycle = colors(p, "r", 3)
363
-
364
- pixels.each((x, y) => {
365
- const ring = Math.floor((Math.hypot(x + 0.5 - p.cx, y + 0.5 - p.cy) - t * 3) / p.width)
366
-
367
- return cycle[((ring % 3) + 3) % 3]
368
- })
369
- },
370
- },
371
- {
372
- id: "kilim",
373
- name: "Kilim",
374
- family: "Patterns",
375
- label: "Stepped diamonds or squares, mirrored like a woven rug",
376
- animated: true,
377
- resolve: (random) => {
378
- const r = random("kilim")
379
-
380
- const [period, band] = pick(r, [
381
- [16, 2],
382
- [8, 1],
383
- [16, 3],
384
- ])
385
-
386
- return {
387
- grid: 16,
388
- period,
389
- band,
390
- metric: r() < 0.7 ? 0 : 1,
391
- ...prefixed("r", shuffle(r, colors(palette(random("palette")))).slice(0, 4)),
392
- }
393
- },
394
- paint: (pixels, p, t) => {
395
- const cycle = colors(p, "r", 4)
396
- const center = (p.period - 1) / 2
397
- const shift = Math.floor(t * 3)
398
-
399
- pixels.each((x, y) => {
400
- const dx = Math.abs((x % p.period) - center)
401
- const dy = Math.abs((y % p.period) - center)
402
- const band = Math.floor((p.metric === 0 ? dx + dy : Math.max(dx, dy)) / p.band) - shift
403
-
404
- return cycle[((band % 4) + 4) % 4]
405
- })
406
- },
407
- },
408
- {
409
- id: "triangles",
410
- name: "Triangles",
411
- family: "Patterns",
412
- label: "Four diagonal Truchet tiles; they flip one by one on hover",
413
- animated: true,
414
- resolve: (random) => {
415
- const r = random("triangles")
416
- const all = colors(palette(random("palette")))
417
- const ground = pick(r, all)
418
-
419
- return {
420
- grid: 16,
421
- seed: seed(r),
422
- ground,
423
- ink: legible(
424
- r,
425
- all.filter((color) => color !== ground),
426
- ground,
427
- ),
428
- }
429
- },
430
- paint: (pixels, p, t) => {
431
- const rand = mulberry32(p.seed)
432
- const tiles = Array.from({ length: 4 }, () => ({ o: Math.floor(rand() * 4), r: rand() }))
433
-
434
- pixels.each((x, y) => {
435
- const tile = tiles[Math.floor(y / 8) * 2 + Math.floor(x / 8)]
436
- const o = (tile.o + Math.floor(t * 1.2 + tile.r)) % 4
437
- const lx = o & 1 ? 7 - (x % 8) : x % 8
438
- const ly = o & 2 ? 7 - (y % 8) : y % 8
439
-
440
- return lx + ly < 7 || (lx + ly === 7 && lx < 4) ? p.ink : p.ground
441
- })
442
- },
443
- },
444
- {
445
- id: "quilt",
446
- name: "Quilt",
447
- family: "Patterns",
448
- label: "Half-square triangles mirrored into a four-patch block",
449
- resolve: (random) => {
450
- const r = random("quilt")
451
- const all = colors(palette(random("palette")))
452
-
453
- return { grid: 16, seed: seed(r), ...prefixed("q", [all[0], ...shuffle(r, all.slice(1)).slice(0, 2)]) }
454
- },
455
- paint: (pixels, p) => {
456
- const fabric = colors(p, "q", 3)
457
- const rand = mulberry32(p.seed)
458
-
459
- const blocks = Array.from({ length: 4 }, () => {
460
- const a = Math.floor(rand() * 3)
461
-
462
- return { o: Math.floor(rand() * 4), a, b: (a + 1 + Math.floor(rand() * 2)) % 3 }
463
- })
464
-
465
- pixels.each((x, y) => {
466
- const X = x < 8 ? x : 15 - x
467
- const Y = y < 8 ? y : 15 - y
468
- const block = blocks[Math.floor(Y / 4) * 2 + Math.floor(X / 4)]
469
- const lx = block.o & 1 ? 3 - (X % 4) : X % 4
470
- const ly = block.o & 2 ? 3 - (Y % 4) : Y % 4
471
-
472
- return fabric[lx + ly < 3 || (lx + ly === 3 && lx < 2) ? block.a : block.b]
473
- })
474
- },
475
- },
476
- {
477
- id: "weave",
478
- name: "Weave",
479
- family: "Patterns",
480
- label: "Basket or twill weave of flat two-pixel strands, each lit along one edge",
481
- resolve: (random) => {
482
- const r = random("weave")
483
- const all = shuffle(r, colors(palette(random("palette"))))
484
-
485
- return {
486
- grid: 16,
487
- twill: r() < 0.35 ? 1 : 0,
488
- strands: r() < 0.5 ? 2 : 1,
489
- warp: all[0],
490
- weft: legible(r, all.slice(1), all[0]),
491
- accent: all[1],
492
- stripe: r() < 0.4 ? 1 : 0,
493
- }
494
- },
495
- paint: (pixels, p) => {
496
- pixels.each((x, y) => {
497
- const cell = 4
498
- const i = Math.floor(x / cell)
499
- const j = Math.floor(y / cell)
500
- const across = p.twill ? (i + j) % 4 < 2 : (i + j) % 2 === 0
501
- const along = across ? y % cell : x % cell
502
- const strand = Math.floor(along / (cell / p.strands))
503
- const edge = along % (cell / p.strands)
504
- const base = across ? p.weft : p.stripe && i % 3 === 1 ? p.accent : p.warp
505
- const lit = edge === 0 ? tint(base, 0.18) : edge === cell / p.strands - 1 ? shade(base, 0.62) : base
506
-
507
- return strand % 2 && p.strands === 2 ? shade(lit, 0.9) : lit
508
- })
509
- },
510
- },
511
- {
512
- id: "one-bit",
513
- name: "1-bit",
514
- family: "Bits and symbols",
515
- label: "A classic 8×8 fill pattern in one ink; it scrolls on hover",
516
- animated: true,
517
- resolve: (random) => {
518
- const r = random("bits")
519
- const all = colors(palette(random("palette")))
520
- const ink = legible(r, all.slice(1), all[0])
521
- const invert = r() < 0.5
522
-
523
- return {
524
- grid: 8,
525
- pattern: Math.floor(r() * PATTERNS.length),
526
- ox: Math.floor(r() * 8),
527
- oy: Math.floor(r() * 8),
528
- ink: invert ? all[0] : ink,
529
- ground: invert ? ink : all[0],
530
- }
531
- },
532
- paint: (pixels, p, t) => {
533
- const shift = Math.floor(t * 3)
534
- const rows = PATTERNS[p.pattern]
535
-
536
- pixels.each((x, y) => ((rows[(y + p.oy + shift) & 7] >> (7 - ((x + p.ox + shift) & 7))) & 1 ? p.ink : p.ground))
537
- },
538
- },
539
- {
540
- id: "glyphs",
541
- name: "Glyphs",
542
- family: "Bits and symbols",
543
- label: "Four 3×3 runes on coloured tiles; they cycle on hover",
544
- animated: true,
545
- resolve: (random) => ({ grid: 16, seed: seed(random("glyphs")), ...palette(random("palette")) }),
546
- paint: (pixels, p, t) => {
547
- const all = colors(p)
548
- const rand = mulberry32(p.seed)
549
-
550
- const grounds = retry(
551
- () => Array.from({ length: 4 }, () => Math.floor(rand() * 5)),
552
- (list) => list[0] !== list[1] && list[0] !== list[2] && list[3] !== list[1] && list[3] !== list[2],
553
- )
554
-
555
- const tiles = grounds.map((ground) => ({
556
- ground: all[ground],
557
- ink: legible(
558
- rand,
559
- all.filter((_, i) => i !== ground),
560
- all[ground],
561
- ),
562
- glyph: Math.floor(rand() * GLYPHS.length),
563
- r: rand(),
564
- }))
565
-
566
- pixels.each((x, y) => {
567
- const tile = tiles[Math.floor(y / 8) * 2 + Math.floor(x / 8)]
568
- const lx = (x % 8) - 1
569
- const ly = (y % 8) - 1
570
-
571
- if (lx < 0 || ly < 0 || lx > 5 || ly > 5) return tile.ground
572
- const glyph = GLYPHS[(tile.glyph + Math.floor(t * 2 + tile.r)) % GLYPHS.length]
573
-
574
- return (glyph >> (8 - (Math.floor(ly / 2) * 3 + Math.floor(lx / 2)))) & 1 ? tile.ink : tile.ground
575
- })
576
- },
577
- },
578
- {
579
- id: "flag",
580
- name: "Flag",
581
- family: "Bits and symbols",
582
- label: "Stripe, cross and canton compositions, like an invented flag",
583
- resolve: (random) => {
584
- const r = random("flag")
585
-
586
- return {
587
- grid: 16,
588
- layout: Math.floor(r() * 9),
589
- ...prefixed("f", shuffle(r, colors(palette(random("palette")))).slice(0, 3)),
590
- }
591
- },
592
- paint: (pixels, p) => {
593
- const [a, b, c] = colors(p, "f", 3)
594
-
595
- const layouts = [
596
- (x: number, y: number) => (y < 5 ? a : y < 11 ? b : c),
597
- (x: number, _: number) => (x < 5 ? a : x < 11 ? b : c),
598
- (x: number, y: number) =>
599
- (x >= 5 && x <= 6) || (y >= 7 && y <= 8) ? c : (x >= 4 && x <= 7) || (y >= 6 && y <= 9) ? b : a,
600
- (x: number, y: number) => (x + y < 14 ? a : x + y > 16 ? b : c),
601
- (x: number, y: number) => (x < 7 && y < 7 ? c : Math.floor(y / 2) % 2 ? b : a),
602
- (x: number, y: number) => (x < 8 - Math.abs(y - 7.5) ? c : y < 8 ? a : b),
603
- (x: number, y: number) => (Math.hypot(x - 7.5, y - 7.5) < 4.6 ? b : a),
604
- (x: number, y: number) => (x < 8 !== y < 8 ? b : a),
605
- (x: number, y: number) => (Math.abs(x - y) <= 1 || Math.abs(x + y - 15) <= 1 ? b : a),
606
- ]
607
-
608
- pixels.each(layouts[p.layout])
609
- },
610
- },
611
- {
612
- id: "identicon",
613
- name: "Identicon",
614
- family: "Characters",
615
- label: "A mirrored 6×6 sprite on a tinted ground",
616
- resolve: (random) => {
617
- const r = random("sprite")
618
- const all = colors(palette(random("palette")))
619
- const ink = legible(r, all.slice(1), all[0])
620
- const invert = r() < 0.3
621
-
622
- return {
623
- grid: 8,
624
- bits: retry(
625
- () => Math.floor(r() * 2 ** 18),
626
- (bits) => ones(bits) >= 7 && ones(bits) <= 12,
627
- ),
628
- ink: invert ? all[0] : ink,
629
- ground: invert ? ink : mix(all[0], ink, 0.14),
630
- }
631
- },
632
- paint: (pixels, p) => {
633
- pixels.fill(p.ground)
634
-
635
- for (let row = 0; row < 6; row++)
636
- for (let column = 0; column < 3; column++) {
637
- if (!((p.bits >> (row * 3 + column)) & 1)) continue
638
- pixels.set(1 + column, 1 + row, p.ink)
639
- pixels.set(6 - column, 1 + row, p.ink)
640
- }
641
- },
642
- },
643
- {
644
- id: "critter",
645
- name: "Critter",
646
- family: "Characters",
647
- label: "A mirrored little creature with see-through eyes; it walks and blinks on hover",
648
- animated: true,
649
- resolve: (random) => {
650
- const r = random("critter")
651
- const all = colors(palette(random("palette")))
652
- const body = pick(r, all.slice(1))
653
-
654
- return {
655
- grid: 8,
656
- w1: 1 + Math.floor(r() * 2),
657
- w3: 2 + Math.floor(r() * 2),
658
- w4: 1 + Math.floor(r() * 3),
659
- antenna: Math.floor(r() * 3),
660
- arms: r() < 0.5 ? 1 : 0,
661
- legs: 1 + Math.floor(r() * 7),
662
- feet: Math.floor(r() * 3),
663
- cyclops: r() < 0.25 ? 1 : 0,
664
- mouth: r() < 0.35 ? 1 : 0,
665
- body,
666
- ground: luma(body) > 0.45 ? mix(0x14151a, body, 0.15) : mix(all[0], body, 0.1),
667
- }
668
- },
669
- paint: (pixels, p, t) => {
670
- // Rows: antenna, head, eyes, body, belly, legs, feet, and an empty bottom row.
671
- const widths = [0, p.w1, 3, p.w3, p.w4]
672
- const step = Math.floor(t * 5) % 2
673
- const blink = t % 2.2 > 2
674
-
675
- const put = (dc: number, row: number, color: number) => {
676
- pixels.set(3 - dc, row, color)
677
- pixels.set(4 + dc, row, color)
678
- }
679
-
680
- pixels.fill(p.ground)
681
- widths.forEach((width, row) => {
682
- for (let dc = 0; dc < width; dc++) put(dc, row, p.body)
683
- })
684
-
685
- if (p.antenna) put(p.antenna, 0, p.body)
686
-
687
- if (p.arms) put(3, 3, p.body)
688
-
689
- for (let dc = 0; dc < 3; dc++) {
690
- if (!((p.legs >> dc) & 1)) continue
691
- put(dc, 5, p.body)
692
- const shifted = Math.max(0, Math.min(3, dc + (p.feet === 1 ? 1 : p.feet === 2 ? -1 : 0)))
693
- put(step ? dc : shifted, 6, p.body)
694
- }
695
-
696
- if (!blink) put(p.cyclops ? 0 : 1, 2, p.ground)
697
-
698
- if (p.mouth && p.w4 > 1) put(0, 4, p.ground)
699
- },
700
- },
701
- {
702
- id: "phosphor",
703
- name: "Phosphor",
704
- family: "Characters",
705
- label: "A glowing sprite on a dark tube with scanlines; the roll bar passes on hover",
706
- animated: true,
707
- resolve: (random) => {
708
- const r = random("phosphor")
709
-
710
- return {
711
- grid: 16,
712
- phosphor: pick(r, PHOSPHORS),
713
- bits: retry(
714
- () => Math.floor(r() * 2 ** 15),
715
- (bits) => ones(bits) >= 7 && ones(bits) <= 11 && (bits & 0b100100100100100) !== 0,
716
- ),
717
- }
718
- },
719
- paint: (pixels, p, t) => {
720
- const ground = mix(0x060807, p.phosphor, 0.06)
721
-
722
- const lit = (x: number, y: number) => {
723
- if (x < 3 || y < 3 || x > 12 || y > 12) return false
724
- const gx = Math.floor((x - 3) / 2)
725
- const gy = Math.floor((y - 3) / 2)
726
-
727
- return ((p.bits >> (gy * 3 + (gx < 3 ? gx : 4 - gx))) & 1) === 1
728
- }
729
-
730
- const bar = ((t * 7) % 24) - 4
731
-
732
- pixels.each((x, y) => {
733
- const on = lit(x, y)
734
- const glow = !on && (lit(x - 1, y) || lit(x + 1, y) || lit(x, y - 1) || lit(x, y + 1))
735
- const base = on ? p.phosphor : glow ? mix(ground, p.phosphor, 0.3) : ground
736
- const roll = t > 0 ? Math.max(0, 1 - Math.abs(y - bar) / 2.5) : 0
737
- const scan = y % 2 ? 0.62 : 1
738
- const vignette = Math.hypot(x - 7.5, y - 7.5) > 7.5 ? 0.8 : 1
739
-
740
- return shade(mix(base, tint(p.phosphor, 0.5), roll * 0.35), scan * vignette)
741
- })
742
- },
743
- },
744
- {
745
- id: "planet",
746
- name: "Planet",
747
- family: "Scenes",
748
- label: "A banded, dithered planet, sometimes ringed; it turns on hover",
749
- animated: true,
750
- resolve: (random) => {
751
- const r = random("planet")
752
- const inks = colors(palette(random("palette"))).slice(1)
753
- const [a, b, ring] = shuffle(r, inks)
754
-
755
- return {
756
- grid: 16,
757
- seed: seed(r),
758
- space: pick(r, SPACE),
759
- a,
760
- b,
761
- ringColor: tint(ring, 0.35),
762
- ring: r() < 0.4 ? 1 : 0,
763
- tilt: (r() - 0.5) * 0.8,
764
- radius: 5.2 + r() * 1.2,
765
- bands: 2 + r() * 3,
766
- phase: r() * 6.28,
767
- }
768
- },
769
- paint: (pixels, p, t) => {
770
- pixels.fill(p.space)
771
- stars(pixels, mulberry32(p.seed), p.space, 5)
772
- const [lx, ly, lz] = normalize(-0.55, -0.5, 0.67)
773
- const cos = Math.cos(p.tilt)
774
- const sin = Math.sin(p.tilt)
775
-
776
- pixels.each((x, y) => {
777
- const dx = (x + 0.5 - 8) / p.radius
778
- const dy = (y + 0.5 - 8) / p.radius
779
- const rx = dx * cos + dy * sin
780
- const ry = -dx * sin + dy * cos
781
- const e = (rx / 1.75) ** 2 + (ry / 0.42) ** 2
782
- const ring = p.ring === 1 && e > 0.72 && e < 1
783
-
784
- if (dx * dx + dy * dy > 1) return ring ? p.ringColor : undefined
785
-
786
- if (ring && ry > 0) return p.ringColor
787
- const dz = Math.sqrt(1 - dx * dx - dy * dy)
788
- const lon = Math.atan2(dx, dz) + t * 1.2
789
- const base = Math.sin(dy * p.bands * Math.PI + p.phase + 0.6 * Math.sin(lon * 2 + dy * 3)) > 0 ? p.a : p.b
790
-
791
- return [shade(base, 0.5), base, tint(base, 0.3)][dither((dx * lx + dy * ly + dz * lz) * 0.75 + 0.3, 3, x, y)]
792
- })
793
- },
794
- },
795
- {
796
- id: "moon",
797
- name: "Moon",
798
- family: "Scenes",
799
- label: "A cratered moon in phase with a faint halo; it waxes on hover",
800
- animated: true,
801
- resolve: (random) => {
802
- const r = random("moon")
803
- const paper = colors(palette(random("palette")))[0]
804
-
805
- return {
806
- grid: 16,
807
- seed: seed(r),
808
- night: pick(r, SPACE),
809
- moon: mix(paper, 0xd8dce6, r() * 0.6),
810
- radius: 5.4 + r(),
811
- ox: (r() - 0.5) * 1.2,
812
- oy: (r() - 0.5) * 1.2,
813
- phase: 0.55 + r() * 0.9,
814
- side: r() < 0.5 ? -1 : 1,
815
- }
816
- },
817
- paint: (pixels, p, t) => {
818
- const rand = mulberry32(p.seed)
819
- const cx = 8 + p.ox
820
- const cy = 8 + p.oy
821
- pixels.fill(p.night)
822
- stars(pixels, rand, p.night, 4)
823
-
824
- const craters = Array.from({ length: 4 }, () => ({
825
- x: cx + (rand() * 2 - 1) * p.radius * 0.6,
826
- y: cy + (rand() * 2 - 1) * p.radius * 0.6,
827
- r: 0.8 + rand() * 1.2,
828
- }))
829
-
830
- const offset = (p.phase + Math.sin(t * 0.9) * 0.45) * p.radius * p.side
831
-
832
- pixels.each((x, y) => {
833
- const d = Math.hypot(x + 0.5 - cx, y + 0.5 - cy)
834
-
835
- if (d > p.radius) return d < p.radius + 1 ? mix(p.night, p.moon, 0.12) : undefined
836
-
837
- const surface = craters.some((crater) => Math.hypot(x + 0.5 - crater.x, y + 0.5 - crater.y) < crater.r)
838
- ? shade(p.moon, 0.8)
839
- : p.moon
840
-
841
- return Math.hypot(x + 0.5 - cx - offset, y + 0.5 - cy) < p.radius ? mix(p.night, surface, 0.16) : surface
842
- })
843
- },
844
- },
845
- {
846
- id: "starfield",
847
- name: "Starfield",
848
- family: "Scenes",
849
- label: "Stars, two with cross glints, over a dithered nebula; they twinkle on hover",
850
- animated: true,
851
- resolve: (random) => {
852
- const r = random("stars")
853
-
854
- return {
855
- grid: 16,
856
- seed: seed(r),
857
- space: pick(r, SPACE),
858
- nebula: pick(r, colors(palette(random("palette"))).slice(1)),
859
- seedX: r() * 40,
860
- seedY: r() * 40,
861
- }
862
- },
863
- paint: (pixels, p, t) => {
864
- const bottom = mix(p.space, p.nebula, 0.12)
865
-
866
- pixels.each((x, y) => {
867
- const base = dither(y / 15, 2, x, y) ? bottom : p.space
868
-
869
- const cloud =
870
- 0.7 * valueNoise(x * 0.22 + p.seedX, y * 0.22 + p.seedY) +
871
- 0.3 * valueNoise(x * 0.5 + p.seedY, y * 0.5 + p.seedX)
872
-
873
- const level = dither((cloud - 0.4) / 0.3, 3, x, y)
874
-
875
- return level ? mix(base, p.nebula, level * 0.18) : base
876
- })
877
- const rand = mulberry32(p.seed)
878
- Array.from({ length: 10 }, (_, i) => {
879
- const x = i < 2 ? 2 + Math.floor(rand() * 12) : Math.floor(rand() * 16)
880
- const y = i < 2 ? 2 + Math.floor(rand() * 12) : Math.floor(rand() * 16)
881
- const level = [0.55, 0.8, 1][Math.floor(rand() * 3)]
882
- const twinkle = 1 - 0.45 * (1 - Math.cos(t * (2 + rand() * 4)))
883
- pixels.set(x, y, mix(p.space, i % 3 ? 0xfff6e0 : 0xdfe9ff, (i < 2 ? 1 : level) * twinkle))
884
-
885
- if (i >= 2) return
886
- const glint = mix(p.space, 0xfff6e0, 0.7 * twinkle)
887
- pixels.set(x - 1, y, glint)
888
- pixels.set(x + 1, y, glint)
889
- pixels.set(x, y - 1, glint)
890
- pixels.set(x, y + 1, glint)
891
- })
892
- },
893
- },
894
- {
895
- id: "horizon",
896
- name: "Horizon",
897
- family: "Scenes",
898
- label: "A dithered sky, a sun and two ridgelines; they drift on hover",
899
- animated: true,
900
- resolve: (random) => {
901
- const r = random("horizon")
902
-
903
- return {
904
- grid: 16,
905
- ...prefixed("s", pick(r, SCENES)),
906
- sunX: 4 + r() * 8,
907
- sunY: 4.5 + r() * 3.5,
908
- back: 6 + r() * 2,
909
- front: 3 + r() * 1.5,
910
- p1: r() * 6.28,
911
- p2: r() * 6.28,
912
- p3: r() * 6.28,
913
- p4: r() * 6.28,
914
- }
915
- },
916
- paint: (pixels, p, t) => {
917
- const [top, bottom, sun, far, near] = colors(p, "s", 5)
918
- const sky = [top, mix(top, bottom, 0.5), bottom]
919
-
920
- pixels.each((x, y) => {
921
- const front = p.front + 1.3 * (Math.sin(x * 0.7 + p.p3 + t * 1.4) + 0.5 * Math.sin(x * 1.6 + p.p4 + t * 1.4))
922
-
923
- if (y >= 16 - front) return near
924
- const back = p.back + 1.6 * (Math.sin(x * 0.5 + p.p1 + t * 0.6) + 0.5 * Math.sin(x * 1.1 + p.p2 + t * 0.6))
925
-
926
- if (y >= 16 - back) return far
927
-
928
- if (Math.hypot(x + 0.5 - p.sunX, y + 0.5 - p.sunY) < 2.6) return sun
929
-
930
- return sky[dither(y / 12, 3, x, y)]
931
- })
932
- },
933
- },
934
- {
935
- id: "sundown",
936
- name: "Sundown",
937
- family: "Scenes",
938
- label: "A slatted retro sun over a perspective grid; the slats rise on hover",
939
- animated: true,
940
- resolve: (random) => {
941
- const r = random("sundown")
942
-
943
- return { grid: 16, radius: 4.6 + r(), ...prefixed("s", pick(r, SYNTH)) }
944
- },
945
- paint: (pixels, p, t) => {
946
- const [top, bottom, sunTop, sunBottom, ground, line] = colors(p, "s", 6)
947
- const sky = [top, mix(top, bottom, 0.5), bottom]
948
- const shift = Math.floor(t * 4)
949
-
950
- pixels.each((x, y) => {
951
- if (y === 11) return line
952
-
953
- if (y > 11) {
954
- const depth = (y + 0.5 - 11) / 4.5
955
- const lane = (x + 0.5 - 8) / depth / 5
956
- const horizontal = y === 13 || y === 15
957
-
958
- return horizontal || Math.abs(lane - Math.round(lane)) < 0.5 / (5 * depth) ? mix(ground, line, 0.75) : ground
959
- }
960
-
961
- if (Math.hypot(x + 0.5 - 8, y + 0.5 - 11) < p.radius && !(y >= 7 && (y + shift) % 3 === 0))
962
- return dither((y - (11 - p.radius)) / p.radius, 2, x, y) ? sunBottom : sunTop
963
-
964
- return sky[dither(y / 11, 3, x, y)]
965
- })
966
- },
967
- },
968
- {
969
- id: "sprout",
970
- name: "Sprout",
971
- family: "Scenes",
972
- label: "A plant with leaves and a bloom on a strip of soil; it sways on hover",
973
- animated: true,
974
- resolve: (random) => {
975
- const r = random("sprout")
976
- const all = colors(palette(random("palette")))
977
- const bloom = legible(r, all.slice(1), all[0])
978
-
979
- return {
980
- grid: 16,
981
- seed: seed(r),
982
- paper: all[0],
983
- leaf: pick(r, LEAVES),
984
- soil: pick(r, SOILS),
985
- bloom,
986
- center: luma(bloom) > 0.6 ? shade(bloom, 0.55) : 0xf6c344,
987
- height: 6 + Math.floor(r() * 3),
988
- x: 7 + Math.floor(r() * 2),
989
- flower: Math.floor(r() * 3),
990
- leafA: 2 + Math.floor(r() * 2),
991
- leafB: 4 + Math.floor(r() * 2),
992
- side: r() < 0.5 ? -1 : 1,
993
- }
994
- },
995
- paint: (pixels, p, t) => {
996
- const top = 12 - p.height
997
- const sway = (y: number) => Math.round(Math.sin(t * 2.2) * ((12 - y) / p.height) * 1.4 * Math.min(1, t * 2))
998
- const rand = mulberry32(p.seed)
999
- pixels.fill(p.paper)
1000
- pixels.rect(0, 13, 16, 3, p.soil)
1001
- pixels.rect(0, 13, 16, 1, tint(p.soil, 0.18))
1002
- Array.from({ length: 3 }, () => pixels.set(Math.floor(rand() * 16), 12, p.leaf))
1003
-
1004
- for (let y = 12; y > top; y--) pixels.set(p.x + sway(y), y, p.leaf)
1005
- ;[
1006
- [p.leafA, p.side],
1007
- [p.leafB, -p.side],
1008
- ].forEach(([height, side]) => {
1009
- const y = 12 - height
1010
- const x = p.x + sway(y)
1011
- pixels.set(x + side, y, p.leaf)
1012
- pixels.set(x + side * 2, y - 1, p.leaf)
1013
- pixels.set(x + side, y - 1, tint(p.leaf, 0.2))
1014
- })
1015
- const x = p.x + sway(top)
1016
-
1017
- const flowers = [
1018
- () => {
1019
- ;[
1020
- [0, -1],
1021
- [-1, 0],
1022
- [1, 0],
1023
- [0, 1],
1024
- ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.bloom))
1025
- pixels.set(x, top, p.center)
1026
- },
1027
- () => {
1028
- pixels.rect(x - 1, top - 1, 3, 2, p.bloom)
1029
- pixels.set(x - 1, top - 2, p.bloom)
1030
- pixels.set(x + 1, top - 2, p.bloom)
1031
- pixels.set(x, top - 1, shade(p.bloom, 0.75))
1032
- },
1033
- () => {
1034
- ;[
1035
- [-2, 0],
1036
- [2, 0],
1037
- [0, -2],
1038
- [0, 2],
1039
- [-1, -1],
1040
- [1, -1],
1041
- [-1, 1],
1042
- [1, 1],
1043
- ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.bloom))
1044
- ;[
1045
- [0, 0],
1046
- [-1, 0],
1047
- [1, 0],
1048
- [0, -1],
1049
- [0, 1],
1050
- ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.center))
1051
- },
1052
- ]
1053
-
1054
- flowers[p.flower]()
1055
- },
1056
- },
1057
- {
1058
- id: "iso",
1059
- name: "Iso blocks",
1060
- family: "Scenes",
1061
- label: "Isometric cubes stacked on a 2×2 footprint, lit from the top left",
1062
- resolve: (random) => {
1063
- const r = random("iso")
1064
-
1065
- const heights = retry(
1066
- () => Array.from({ length: 4 }, () => Math.floor(r() * 3)),
1067
- (list) => list.reduce((sum, h) => sum + h, 0) >= 3,
1068
- )
1069
-
1070
- return {
1071
- grid: 16,
1072
- ...prefixed("h", heights),
1073
- ...prefixed(
1074
- "k",
1075
- heights.map(() => Math.floor(r() * 4)),
1076
- ),
1077
- ...palette(random("palette")),
1078
- }
1079
- },
1080
- paint: (pixels, p) => {
1081
- const inks = colors(p).slice(1)
1082
-
1083
- const cubes = [
1084
- [0, 0],
1085
- [1, 0],
1086
- [0, 1],
1087
- [1, 1],
1088
- ]
1089
- .flatMap(([i, j], index) =>
1090
- Array.from({ length: p[`h${index}`] }, (_, k) => ({ i, j, k, ink: inks[p[`k${index}`]] })),
1091
- )
1092
- .toSorted((a, b) => a.i + a.j - (b.i + b.j) || a.k - b.k)
1093
-
1094
- const tops = cubes.map((cube) => (cube.i + cube.j) * 2 - cube.k * 4)
1095
- const extent = Math.max(...tops) + 8 - Math.min(...tops)
1096
- const oy = Math.round((16 - extent) / 2) - Math.min(...tops)
1097
-
1098
- pixels.fill(p.c0)
1099
- cubes.forEach((cube) => {
1100
- const faces = { T: tint(cube.ink, 0.3), L: cube.ink, R: shade(cube.ink, 0.72) }
1101
- const x0 = 4 + (cube.i - cube.j) * 4
1102
- const y0 = oy + (cube.i + cube.j) * 2 - cube.k * 4
1103
- CUBE.forEach((row, dy) =>
1104
- [...row].forEach((face, dx) => {
1105
- if (face === "T" || face === "L" || face === "R") pixels.set(x0 + dx, y0 + dy, faces[face])
1106
- }),
1107
- )
1108
- })
1109
- },
1110
- },
1111
- {
1112
- id: "stack",
1113
- name: "Stack",
1114
- family: "Geometry",
1115
- label: "Tetrominoes dropped into an eight-wide well, with the next piece falling; it lands on hover",
1116
- animated: true,
1117
- resolve: (random) => {
1118
- const r = random("stack")
1119
-
1120
- return {
1121
- grid: 16,
1122
- seed: seed(r),
1123
- pieces: int(r, 12, 18),
1124
- ...prefixed("t", pick(r, TETROMINO_COLORS)),
1125
- well: pick(r, [0x0b0d14, 0x101010, 0x14102a, 0x0a1a1f]),
1126
- }
1127
- },
1128
- paint: (pixels, p, t) => {
1129
- const tints = colors(p, "t", 7)
1130
- const rand = mulberry32(p.seed)
1131
- const board = Array.from({ length: 64 }, () => -1)
1132
- const filled = (x: number, y: number) => x < 0 || x > 7 || y > 7 || (y >= 0 && board[y * 8 + x] >= 0)
1133
- const fits = (cells: number[][], x: number, y: number) => cells.every(([cx, cy]) => !filled(x + cx, y + cy))
1134
-
1135
- // Drop each piece where it leaves the fewest holes of six random columns and turns, as a player would, keeping
1136
- // the top three rows clear.
1137
- Array.from({ length: p.pieces }, () => {
1138
- const kind = Math.floor(rand() * 7)
1139
-
1140
- const [cells, x, y] = Array.from({ length: 6 }, () => {
1141
- const cells = turned(TETROMINOES[kind], Math.floor(rand() * 4))
1142
- const x = Math.floor(rand() * (9 - (Math.max(...cells.map(([cx]) => cx)) + 1)))
1143
- let y = -2
1144
-
1145
- while (fits(cells, x, y + 1)) y++
1146
- const own = (cx: number, cy: number) => cells.some(([ox, oy]) => ox === cx && oy === cy)
1147
- const holes = cells.filter(([cx, cy]) => !own(cx, cy + 1) && !filled(x + cx, y + cy + 1)).length
1148
-
1149
- return [cells, x, y, y - holes * 3] as const
1150
- }).toSorted((a, b) => b[3] - a[3])[0]
1151
-
1152
- if (cells.some(([, cy]) => y + cy < 3)) return
1153
- cells.forEach(([cx, cy]) => (board[(y + cy) * 8 + x + cx] = kind))
1154
- })
1155
-
1156
- const kind = Math.floor(rand() * 7)
1157
- const falling = turned(TETROMINOES[kind], Math.floor(rand() * 4))
1158
- const fx = Math.floor(rand() * (9 - (Math.max(...falling.map(([x]) => x)) + 1)))
1159
- let landing = 0
1160
-
1161
- while (fits(falling, fx, landing + 1)) landing++
1162
- const fy = Math.min(landing, Math.floor(t * 4))
1163
-
1164
- pixels.fill(p.well)
1165
-
1166
- const block = (bx: number, by: number, color: number) => {
1167
- pixels.set(bx * 2, by * 2, tint(color, 0.45))
1168
- pixels.set(bx * 2 + 1, by * 2, color)
1169
- pixels.set(bx * 2, by * 2 + 1, color)
1170
- pixels.set(bx * 2 + 1, by * 2 + 1, shade(color, 0.6))
1171
- }
1172
-
1173
- board.forEach((piece, i) => piece >= 0 && block(i % 8, Math.floor(i / 8), tints[piece]))
1174
- falling.forEach(([cx, cy]) => block(fx + cx, fy + cy, tints[kind]))
1175
- },
1176
- },
1177
- {
1178
- id: "maze",
1179
- name: "Maze",
1180
- family: "Geometry",
1181
- label: "A 5×5 backtracker maze with its route marked; a runner walks it on hover",
1182
- animated: true,
1183
- resolve: (random) => {
1184
- const r = random("maze")
1185
- const all = colors(palette(random("palette")))
1186
- const wall = ramped(all.slice(1))[0]
1187
-
1188
- return {
1189
- grid: 16,
1190
- seed: seed(r),
1191
- wall,
1192
- path: all[0],
1193
- route: legible(
1194
- r,
1195
- all.slice(1).filter((color) => color !== wall),
1196
- all[0],
1197
- ),
1198
- }
1199
- },
1200
- paint: (pixels, p, t) => {
1201
- const rand = mulberry32(p.seed)
1202
- const passages = new Set<string>()
1203
- const visited = new Set([0])
1204
- const stack = [0]
1205
- const link = (a: number, b: number) => `${Math.min(a, b)}-${Math.max(a, b)}`
1206
-
1207
- const neighbours = (cell: number) =>
1208
- [
1209
- [1, 0],
1210
- [-1, 0],
1211
- [0, 1],
1212
- [0, -1],
1213
- ].flatMap(([dx, dy]) => {
1214
- const x = (cell % 5) + dx
1215
- const y = Math.floor(cell / 5) + dy
1216
-
1217
- return x >= 0 && y >= 0 && x < 5 && y < 5 ? [y * 5 + x] : []
1218
- })
1219
-
1220
- while (stack.length) {
1221
- const cell = stack[stack.length - 1]
1222
- const options = neighbours(cell).filter((next) => !visited.has(next))
1223
-
1224
- if (!options.length) {
1225
- stack.pop()
1226
- continue
1227
- }
1228
-
1229
- const next = options[Math.floor(rand() * options.length)]
1230
- visited.add(next)
1231
- passages.add(link(cell, next))
1232
- stack.push(next)
1233
- }
1234
-
1235
- // The tree has one path between any two cells: walk back from the exit through each cell's parent.
1236
- const parents = new Map([[0, -1]])
1237
- const queue = [0]
1238
-
1239
- while (queue.length) {
1240
- const cell = queue.shift()!
1241
- neighbours(cell)
1242
- .filter((next) => passages.has(link(cell, next)) && !parents.has(next))
1243
- .forEach((next) => {
1244
- parents.set(next, cell)
1245
- queue.push(next)
1246
- })
1247
- }
1248
-
1249
- const route = [24]
1250
-
1251
- while (route[route.length - 1] !== 0) route.push(parents.get(route[route.length - 1])!)
1252
-
1253
- const open = (a: number, b: number, color: number) => {
1254
- const ax = 1 + 3 * (a % 5)
1255
- const ay = 1 + 3 * Math.floor(a / 5)
1256
- pixels.rect(ax, ay, 2, 2, color)
1257
-
1258
- if (b < 0) return
1259
- const bx = 1 + 3 * (b % 5)
1260
- const by = 1 + 3 * Math.floor(b / 5)
1261
- pixels.rect(Math.min(ax, bx), Math.min(ay, by), Math.abs(ax - bx) + 2, Math.abs(ay - by) + 2, color)
1262
- }
1263
-
1264
- pixels.fill(p.wall)
1265
- Array.from({ length: 25 }, (_, cell) => open(cell, -1, p.path))
1266
- passages.forEach((key) => {
1267
- const [a, b] = key.split("-").map(Number)
1268
- open(a, b, p.path)
1269
- })
1270
- route.forEach((cell, i) => open(cell, route[i + 1] ?? -1, p.route))
1271
-
1272
- if (t <= 0) return
1273
- const runner = route.toReversed()[Math.floor(t * 5) % route.length]
1274
- open(runner, -1, tint(p.route, 0.65))
1275
- },
1276
- },
1277
- {
1278
- id: "rule",
1279
- name: "Rule",
1280
- family: "Geometry",
1281
- label: "An elementary cellular automaton grown from a random first row; it scrolls on hover",
1282
- animated: true,
1283
- resolve: (random) => {
1284
- const r = random("rule")
1285
- const all = colors(palette(random("palette")))
1286
- const a = legible(r, all.slice(1), all[0])
1287
-
1288
- return {
1289
- grid: 16,
1290
- rule: pick(r, RULES),
1291
- first: Array.from({ length: 1 + Math.floor(r() * 3) }, () => 1 << Math.floor(r() * 16)).reduce(
1292
- (bits, bit) => bits | bit,
1293
- 0,
1294
- ),
1295
- ground: all[0],
1296
- a,
1297
- b: legible(
1298
- r,
1299
- all.slice(1).filter((color) => color !== a),
1300
- all[0],
1301
- ),
1302
- }
1303
- },
1304
- paint: (pixels, p, t) => {
1305
- const next = (cells: number[]) =>
1306
- cells.map((cell, i) => (p.rule >> ((cells[(i + 15) % 16] << 2) | (cell << 1) | cells[(i + 1) % 16])) & 1)
1307
-
1308
- const first = Array.from({ length: 16 }, (_, i) => (p.first >> i) & 1)
1309
-
1310
- const rows = Array.from({ length: 15 + Math.floor(t * 6) }).reduce<number[][]>(
1311
- (history) => [...history, next(history[history.length - 1])],
1312
- [first],
1313
- )
1314
-
1315
- const visible = rows.slice(-16)
1316
-
1317
- pixels.each((x, y) => (visible[y][x] ? (dither(y / 15, 2, x, y) ? p.b : p.a) : p.ground))
1318
- },
1319
- },
1320
- {
1321
- id: "arcs",
1322
- name: "Arcs",
1323
- family: "Geometry",
1324
- label: "Smooth Truchet quarter-circles; tiles turn on hover",
1325
- animated: true,
1326
- resolve: (random) => {
1327
- const r = random("arcs")
1328
- const all = colors(palette(random("palette")))
1329
- const ground = pick(r, all.slice(1))
1330
-
1331
- return {
1332
- seed: seed(r),
1333
- tiles: r() < 0.5 ? 2 : 3,
1334
- weight: 0.2 + r() * 0.08,
1335
- ground,
1336
- ink: legible(
1337
- r,
1338
- all.filter((color) => color !== ground),
1339
- ground,
1340
- ),
1341
- }
1342
- },
1343
- vector: (ctx, px, p, t) => {
1344
- const size = px / p.tiles
1345
- const rand = mulberry32(p.seed)
1346
- ctx.fillStyle = css(p.ground)
1347
- ctx.fillRect(0, 0, px, px)
1348
- ctx.strokeStyle = css(p.ink)
1349
- ctx.lineWidth = size * p.weight
1350
-
1351
- for (let i = 0; i < p.tiles; i++)
1352
- for (let j = 0; j < p.tiles; j++) {
1353
- const turn = rand() < 0.5 ? Math.PI / 2 : 0
1354
- const delay = rand()
1355
- ctx.save()
1356
- ctx.translate((i + 0.5) * size, (j + 0.5) * size)
1357
- ctx.rotate(turn + ease(t * 1.2 - delay * 0.8) * (Math.PI / 2))
1358
- ctx.beginPath()
1359
- ctx.arc(-size / 2, -size / 2, size / 2, 0, Math.PI / 2)
1360
- ctx.moveTo(0, size / 2)
1361
- ctx.arc(size / 2, size / 2, size / 2, Math.PI, Math.PI * 1.5)
1362
- ctx.stroke()
1363
- ctx.restore()
1364
- }
1365
- },
1366
- },
1367
- {
1368
- id: "bauhaus",
1369
- name: "Bauhaus",
1370
- family: "Geometry",
1371
- label: "Circles, halves and quarters on a 2×2 grid; forms turn on hover",
1372
- animated: true,
1373
- resolve: (random) => ({ seed: seed(random("bauhaus")), ...palette(random("palette")) }),
1374
- vector: (ctx, px, p, t) => {
1375
- const all = colors(p)
1376
- const rand = mulberry32(p.seed)
1377
- const size = px / 2
1378
-
1379
- const grounds = retry(
1380
- () => Array.from({ length: 4 }, () => Math.floor(rand() * 5)),
1381
- (list) => list[0] !== list[1] && list[0] !== list[2] && list[3] !== list[1] && list[3] !== list[2],
1382
- )
1383
-
1384
- grounds.forEach((ground, index) => {
1385
- const inks = all.filter((_, i) => i !== ground)
1386
- const ink = inks[Math.floor(rand() * inks.length)]
1387
- const form = Math.floor(rand() * 4)
1388
- const turn = Math.floor(rand() * 4)
1389
- const delay = rand()
1390
- ctx.save()
1391
- ctx.translate(((index % 2) + 0.5) * size, (Math.floor(index / 2) + 0.5) * size)
1392
- ctx.fillStyle = css(all[ground])
1393
- ctx.fillRect(-size / 2 - 0.5, -size / 2 - 0.5, size + 1, size + 1)
1394
- ctx.rotate((turn + ease(t * 1.1 - delay * 0.6)) * (Math.PI / 2))
1395
- ctx.fillStyle = css(ink)
1396
- ctx.beginPath()
1397
-
1398
- const forms = [
1399
- () => ctx.arc(0, 0, size * 0.34, 0, Math.PI * 2),
1400
- () => ctx.arc(0, size / 2, size / 2, Math.PI, Math.PI * 2),
1401
- () => {
1402
- ctx.moveTo(-size / 2, -size / 2)
1403
- ctx.arc(-size / 2, -size / 2, size, 0, Math.PI / 2)
1404
- },
1405
- () => {
1406
- ctx.moveTo(-size / 2, -size / 2)
1407
- ctx.lineTo(size / 2, -size / 2)
1408
- ctx.lineTo(-size / 2, size / 2)
1409
- },
1410
- ]
1411
-
1412
- forms[form]()
1413
- ctx.closePath()
1414
- ctx.fill()
1415
- ctx.restore()
1416
- })
1417
- },
1418
- },
1419
- {
1420
- id: "sweep",
1421
- name: "Sweep",
1422
- family: "Gradients",
1423
- label: "A conic sweep through three inks with a soft highlight; it turns on hover",
1424
- animated: true,
1425
- resolve: (random) => {
1426
- const r = random("sweep")
1427
-
1428
- return {
1429
- angle: r() * Math.PI * 2,
1430
- cx: 0.25 + r() * 0.5,
1431
- cy: 0.25 + r() * 0.5,
1432
- ...prefixed("s", shuffle(r, colors(palette(random("palette"))).slice(1)).slice(0, 3)),
1433
- }
1434
- },
1435
- vector: (ctx, px, p, t) => {
1436
- const [a, b, c] = colors(p, "s", 3)
1437
- const sweep = ctx.createConicGradient(p.angle + t * 0.8, p.cx * px, p.cy * px)
1438
- sweep.addColorStop(0, css(a))
1439
- sweep.addColorStop(1 / 3, css(b))
1440
- sweep.addColorStop(2 / 3, css(c))
1441
- sweep.addColorStop(1, css(a))
1442
- ctx.fillStyle = sweep
1443
- ctx.fillRect(0, 0, px, px)
1444
- const light = ctx.createRadialGradient(px * 0.3, px * 0.2, 0, px * 0.3, px * 0.2, px * 0.8)
1445
- light.addColorStop(0, "rgba(255, 255, 255, 0.28)")
1446
- light.addColorStop(1, "rgba(255, 255, 255, 0)")
1447
- ctx.fillStyle = light
1448
- ctx.fillRect(0, 0, px, px)
1449
- },
1450
- },
1451
- ]
1452
-
1453
- const MESH: ProjectIconStyle = {
1454
- id: "mesh",
1455
- name: "Mesh",
1456
- label: "The current default: James's mesh gradient with film grain",
1457
- family: "Gradients",
1458
- animated: true,
1459
- generate: generateProjectIcon,
1460
- draw: drawProjectIcon,
1461
- }
1462
-
1463
- /** The gallery's groups, in order: the first set of styles, then the second set from the craft, world and machine files. */
1464
- export const PROJECT_ICON_FAMILIES = [
1465
- "Gradients",
1466
- "Pixel and dither",
1467
- "Patterns",
1468
- "Bits and symbols",
1469
- "Characters",
1470
- "Scenes",
1471
- "Geometry",
1472
- "Textiles",
1473
- "Print",
1474
- "Art movements",
1475
- "Nature and materials",
1476
- "Creatures",
1477
- "Objects",
1478
- "Emblems",
1479
- "Retro tech",
1480
- "Tiling and curves",
1481
- ]
1482
-
1483
- export const PROJECT_ICON_STYLES: readonly ProjectIconStyle[] = [
1484
- MESH,
1485
- ...[...DEFINITIONS, ...CRAFT, ...WORLD, ...MACHINE].map(define),
1486
- ].toSorted((a, b) => PROJECT_ICON_FAMILIES.indexOf(a.family) - PROJECT_ICON_FAMILIES.indexOf(b.family))
1487
-
1488
- export function projectIconStyle(id: string) {
1489
- return PROJECT_ICON_STYLES.find((style) => style.id === id) ?? MESH
1490
- }
1491
-
1492
- // A tetromino's cells after `turns` quarter turns, moved back to the origin.
1493
- function turned(cells: number[][], turns: number) {
1494
- const rotated = Array.from({ length: turns }).reduce<number[][]>(
1495
- (list) => list.map(([x, y]) => [-y, x]),
1496
- cells,
1497
- )
1498
- const minX = Math.min(...rotated.map(([x]) => x))
1499
- const minY = Math.min(...rotated.map(([, y]) => y))
1500
-
1501
- return rotated.map(([x, y]) => [x - minX, y - minY])
1502
- }
1503
-
1504
- function define(definition: Definition): ProjectIconStyle {
1505
- return {
1506
- id: definition.id,
1507
- name: definition.name,
1508
- label: definition.label,
1509
- family: definition.family,
1510
- animated: definition.animated ?? false,
1511
- generate: (key) => ({
1512
- style: definition.id,
1513
- version: 1,
1514
- params: definition.resolve((tag) => mulberry32(cyrb53(`${key}|${definition.id}|${tag}`))),
1515
- }),
1516
- draw: (ctx, px, icon, seconds) => {
1517
- if ("vector" in definition) {
1518
- ctx.clearRect(0, 0, px, px)
1519
- definition.vector(ctx, px, icon.params, seconds)
1520
- clip(ctx, px)
1521
-
1522
- return
1523
- }
1524
-
1525
- const pixels = new Pixels(icon.params.grid)
1526
- definition.paint(pixels, icon.params, seconds)
1527
- blit(ctx, px, pixels)
1528
- },
1529
- }
1530
- }
1531
-
1532
- // Scales the grid up nearest-neighbour, so every cell stays a hard-edged block, and cuts the rounded tile.
1533
- function blit(ctx: CanvasRenderingContext2D, px: number, pixels: Pixels) {
1534
- const image = ctx.createImageData(px, px)
1535
-
1536
- for (let row = 0; row < px; row++) {
1537
- const y = Math.floor((row * pixels.n) / px)
1538
-
1539
- for (let column = 0; column < px; column++) {
1540
- const mask = tileMask((column + 0.5) / px, (row + 0.5) / px, px)
1541
-
1542
- if (mask <= 0) continue
1543
- const color = pixels.cells[y * pixels.n + Math.floor((column * pixels.n) / px)]
1544
- const index = (row * px + column) * 4
1545
- image.data[index] = (color >> 16) & 255
1546
- image.data[index + 1] = (color >> 8) & 255
1547
- image.data[index + 2] = color & 255
1548
- image.data[index + 3] = mask * 255
1549
- }
1550
- }
1551
-
1552
- ctx.putImageData(image, 0, 0)
1553
- }
1554
-
1555
- function clip(ctx: CanvasRenderingContext2D, px: number) {
1556
- const image = ctx.getImageData(0, 0, px, px)
1557
-
1558
- for (let row = 0; row < px; row++)
1559
- for (let column = 0; column < px; column++)
1560
- image.data[(row * px + column) * 4 + 3] *= tileMask((column + 0.5) / px, (row + 0.5) / px, px)
1561
-
1562
- ctx.putImageData(image, 0, 0)
1563
- }
1
+ // Experimental generators for the default project avatar, compared side by side in the components lab. Each keeps the
2
+ // mesh's contract (see generated.ts): the values that define an icon are resolved once from a key, so a stored icon
3
+ // never changes, and drawing is a CPU pass on a 2D canvas clipped to the same rounded tile. Most styles paint a small
4
+ // grid of pixels that is scaled up nearest-neighbour, with limited palettes and ordered dithering. Only the components
5
+ // lab imports this module.
6
+
7
+ import { cyrb53, drawProjectIcon, generateProjectIcon, mulberry32, tileMask, valueNoise, type GeneratedProjectIcon } from "./generated"
8
+ import { CRAFT } from "./procedural-craft"
9
+ import {
10
+ clamp01,
11
+ colors,
12
+ css,
13
+ dither,
14
+ ease,
15
+ int,
16
+ legible,
17
+ luma,
18
+ mix,
19
+ normalize,
20
+ ones,
21
+ palette,
22
+ pick,
23
+ Pixels,
24
+ prefixed,
25
+ ramped,
26
+ retry,
27
+ seed,
28
+ shade,
29
+ shuffle,
30
+ smoothstep,
31
+ stars,
32
+ threshold,
33
+ tint,
34
+ type Definition,
35
+ } from "./procedural-kit"
36
+ import { MACHINE } from "./procedural-machine"
37
+ import { WORLD } from "./procedural-world"
38
+
39
+ export type ProjectIconStyle = {
40
+ readonly id: string
41
+ readonly name: string
42
+ readonly label: string
43
+ /** The gallery group the style belongs to. */
44
+ readonly family: string
45
+ /** Whether the style has a hover animation. */
46
+ readonly animated: boolean
47
+ readonly generate: (key: string) => GeneratedProjectIcon
48
+ /** Draws the icon `seconds` into its hover animation (0 is the static frame) into a square `px` × `px` context. */
49
+ readonly draw: (ctx: CanvasRenderingContext2D, px: number, icon: GeneratedProjectIcon, seconds: number) => void
50
+ }
51
+
52
+ // Curated colors for scenes James's paper-and-ink palettes do not cover.
53
+ const SPACE = [0x0e1027, 0x111827, 0x1a1033, 0x071a26, 0x14121f]
54
+
55
+ const LEAVES = [0x4c956c, 0x2a9d8f, 0x606c38, 0x81b29a, 0x419d78, 0x3f7d3a]
56
+
57
+ const SOILS = [0x6b4423, 0x5c3d2e, 0x3d2b1f, 0x7a5230]
58
+
59
+ const PHOSPHORS = [0x39ff7a, 0xffb43a, 0x6fe3ff, 0xd6e4ff, 0xff6fb5]
60
+
61
+ // Sky top, sky bottom, sun, far ridge, near ridge.
62
+ const SCENES = [
63
+ [0x2b1b4a, 0xf28c5a, 0xffe08a, 0x7a3d6b, 0x3a1f3d],
64
+ [0x5fb4e8, 0xd9f1ff, 0xfff3b0, 0x6aa56a, 0x2f6b4f],
65
+ [0x0b1030, 0x2a3a7a, 0xf0f0d0, 0x1f2a55, 0x0a0f24],
66
+ [0xf2a65a, 0xfbe7c2, 0xfff8e0, 0xc4703f, 0x7a3e28],
67
+ [0x8fc7e6, 0xeaf6fb, 0xffffff, 0x9fb8c8, 0x5c7488],
68
+ [0xe89aa8, 0xfde2c8, 0xfff1d6, 0x6d8f71, 0x33503c],
69
+ ]
70
+
71
+ // Sky top, sky bottom, sun top, sun bottom, ground, grid lines.
72
+ const SYNTH = [
73
+ [0x1b0b3b, 0xe8467c, 0xffd166, 0xff5f7e, 0x13072e, 0xff4fd8],
74
+ [0x0b132b, 0x5b4b8a, 0xfff07a, 0xff8c42, 0x0a0f1f, 0x3ad6ff],
75
+ [0x2d1e4f, 0xff9a62, 0xfff3b0, 0xff6b6b, 0x24133b, 0xffb0d9],
76
+ [0x08263b, 0x1f8a9e, 0xf9f871, 0xf2a65a, 0x061a26, 0x7af5d1],
77
+ ]
78
+
79
+ // Classic 8 × 8 one-bit fills, one byte per row.
80
+ const PATTERNS = [
81
+ [0xff, 0x80, 0x80, 0x80, 0xff, 0x08, 0x08, 0x08],
82
+ [0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33],
83
+ [0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0],
84
+ [0x80, 0x80, 0x41, 0x3e, 0x08, 0x08, 0x14, 0xe3],
85
+ [0x00, 0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x00],
86
+ [0x81, 0x42, 0x24, 0x18, 0x81, 0x42, 0x24, 0x18],
87
+ [0x00, 0x18, 0x18, 0x7e, 0x7e, 0x18, 0x18, 0x00],
88
+ [0xff, 0x88, 0x88, 0x88, 0xff, 0x88, 0x88, 0x88],
89
+ [0x18, 0x3c, 0x7e, 0xff, 0x7e, 0x3c, 0x18, 0x00],
90
+ [0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc, 0x99],
91
+ ]
92
+
93
+ // 3 × 3 runes, top row in the high bits.
94
+ const GLYPHS = [
95
+ 0b010111010, 0b101010101, 0b111101111, 0b100100111, 0b111010010, 0b111000111, 0b101101101, 0b100010001, 0b110011001,
96
+ 0b101101111, 0b111100111, 0b010101010, 0b011010110, 0b111001001,
97
+ ]
98
+
99
+ // The seven tetrominoes as cells, and their colors: the guideline set, a handheld's greys, an 8-bit set and pastels.
100
+ const TETROMINOES = [
101
+ [
102
+ [0, 0],
103
+ [1, 0],
104
+ [2, 0],
105
+ [3, 0],
106
+ ],
107
+ [
108
+ [0, 0],
109
+ [1, 0],
110
+ [0, 1],
111
+ [1, 1],
112
+ ],
113
+ [
114
+ [0, 0],
115
+ [1, 0],
116
+ [2, 0],
117
+ [1, 1],
118
+ ],
119
+ [
120
+ [1, 0],
121
+ [2, 0],
122
+ [0, 1],
123
+ [1, 1],
124
+ ],
125
+ [
126
+ [0, 0],
127
+ [1, 0],
128
+ [1, 1],
129
+ [2, 1],
130
+ ],
131
+ [
132
+ [0, 0],
133
+ [0, 1],
134
+ [1, 1],
135
+ [2, 1],
136
+ ],
137
+ [
138
+ [2, 0],
139
+ [0, 1],
140
+ [1, 1],
141
+ [2, 1],
142
+ ],
143
+ ]
144
+
145
+ const TETROMINO_COLORS = [
146
+ [0x2ad4e6, 0xf2d230, 0xa64ce0, 0x46d04a, 0xe8413c, 0x3a64e8, 0xf0902a],
147
+ [0x9bbc0f, 0x8bac0f, 0x306230, 0x8bac0f, 0x306230, 0x9bbc0f, 0x306230],
148
+ [0x3cbcfc, 0xf8b800, 0xd800cc, 0x58d854, 0xf83800, 0x0058f8, 0xfca044],
149
+ [0x9ad8e8, 0xf6e3a1, 0xc9b1e8, 0xb5e3b0, 0xf2a7a7, 0xa7b8f2, 0xf5c09a],
150
+ ]
151
+
152
+ const RULES = [18, 22, 30, 60, 86, 90, 102, 110, 126, 150, 182]
153
+
154
+ // An isometric cube eight pixels wide: top, left and right faces.
155
+ const CUBE = ["...TT...", ".TTTTTT.", "LTTTTTTR", "LLLTTRRR", "LLLLRRRR", "LLLLRRRR", ".LLLRRR.", "...LR..."]
156
+
157
+ const DEFINITIONS: Definition[] = [
158
+ {
159
+ id: "pixel-mesh",
160
+ name: "Pixel mesh",
161
+ family: "Gradients",
162
+ label: "James's mesh waves on a 16 grid, dithered to its four inks",
163
+ animated: true,
164
+ resolve: (random) => {
165
+ const position = random("mesh")
166
+
167
+ return { grid: 16, seedX: position() * 40, seedY: position() * 40, ...palette(random("palette")) }
168
+ },
169
+ paint: (pixels, p, t) => {
170
+ const inks = colors(p).slice(1)
171
+
172
+ pixels.each((x, y) => {
173
+ const u = (x + 0.5) / pixels.n
174
+ const v = 1 - (y + 0.5) / pixels.n
175
+ const mx = u * 3.6 + p.seedX
176
+ const my = (v - u * 0.02) * 2.4 + p.seedY
177
+
178
+ return [0, 1, 2].reduce((color, i) => {
179
+ const sx = mx * (0.35 + 0.12 * i) + t * 0.2 * (i + 1)
180
+ const sy = my * 0.6 + i * 3.7
181
+ const k = smoothstep(0.35, 0.75, 0.65 * valueNoise(sx, sy) + 0.35 * valueNoise(sx * 2.1 + 7, sy * 2.1 + 7))
182
+
183
+ return k > threshold(x, y) ? inks[i + 1] : color
184
+ }, inks[0])
185
+ })
186
+ },
187
+ },
188
+ {
189
+ id: "dither",
190
+ name: "Dither ramp",
191
+ family: "Pixel and dither",
192
+ label: "A three-step gradient through a 4×4 Bayer matrix",
193
+ animated: true,
194
+ resolve: (random) => {
195
+ const r = random("dither")
196
+ const all = colors(palette(random("palette")))
197
+ const ramp = ramped(shuffle(r, all).slice(0, 3))
198
+
199
+ return {
200
+ grid: 16,
201
+ mode: r() < 0.6 ? 0 : 1,
202
+ angle: r() * Math.PI * 2,
203
+ cx: 0.15 + r() * 0.7,
204
+ cy: 0.15 + r() * 0.7,
205
+ ...prefixed("r", ramp),
206
+ }
207
+ },
208
+ paint: (pixels, p, t) => {
209
+ const ramp = colors(p, "r", 3)
210
+ const angle = p.angle + t * 0.9
211
+ const cx = p.cx + Math.sin(t * 1.3) * 0.2
212
+ const cy = p.cy + Math.sin(t * 1.1) * 0.2
213
+
214
+ pixels.each((x, y) => {
215
+ const u = (x + 0.5) / pixels.n
216
+ const v = (y + 0.5) / pixels.n
217
+
218
+ const value =
219
+ p.mode === 0
220
+ ? ((u - 0.5) * Math.cos(angle) + (v - 0.5) * Math.sin(angle)) * 1.1 + 0.5
221
+ : Math.hypot(u - cx, v - cy)
222
+
223
+ return ramp[dither(value, 3, x, y)]
224
+ })
225
+ },
226
+ },
227
+ {
228
+ id: "plasma",
229
+ name: "Plasma",
230
+ family: "Pixel and dither",
231
+ label: "Demoscene sine plasma posterised to a five-step ramp",
232
+ animated: true,
233
+ resolve: (random) => {
234
+ const r = random("plasma")
235
+
236
+ return {
237
+ grid: 16,
238
+ a: 0.5 + r() * 0.7,
239
+ b: 0.5 + r() * 0.7,
240
+ c: 0.3 + r() * 0.5,
241
+ d: 0.6 + r() * 0.8,
242
+ p1: r() * 6.28,
243
+ p2: r() * 6.28,
244
+ p3: r() * 6.28,
245
+ cx: r(),
246
+ cy: r(),
247
+ ...prefixed("r", ramped(colors(palette(random("palette"))))),
248
+ }
249
+ },
250
+ paint: (pixels, p, t) => {
251
+ const ramp = colors(p, "r", 5)
252
+
253
+ pixels.each((x, y) => {
254
+ const X = ((x + 0.5) / pixels.n) * 6.28
255
+ const Y = ((y + 0.5) / pixels.n) * 6.28
256
+
257
+ const value =
258
+ (Math.sin(X * p.a + p.p1 + t * 1.6) +
259
+ Math.sin(Y * p.b + p.p2 - t * 1.1) +
260
+ Math.sin((X + Y) * p.c + p.p3 + t * 0.8) +
261
+ Math.sin(Math.hypot(X - p.cx * 6.28, Y - p.cy * 6.28) * p.d - t * 2)) /
262
+ 4
263
+
264
+ return ramp[Math.min(4, Math.floor(clamp01(value * 0.6 + 0.5) * 5))]
265
+ })
266
+ },
267
+ },
268
+ {
269
+ id: "contour",
270
+ name: "Contours",
271
+ family: "Pixel and dither",
272
+ label: "Topographic bands of value noise with darker iso-lines",
273
+ animated: true,
274
+ resolve: (random) => {
275
+ const r = random("contour")
276
+
277
+ return {
278
+ grid: 16,
279
+ seedX: r() * 40,
280
+ seedY: r() * 40,
281
+ scale: 1.6 + r(),
282
+ ...prefixed("r", ramped(colors(palette(random("palette"))))),
283
+ }
284
+ },
285
+ paint: (pixels, p, t) => {
286
+ const ramp = colors(p, "r", 5)
287
+ const n = pixels.n
288
+
289
+ const band = (x: number, y: number) => {
290
+ const X = (x / n) * p.scale + p.seedX + t * 0.3
291
+ const Y = (y / n) * p.scale + p.seedY
292
+ const h = 0.65 * valueNoise(X, Y) + 0.35 * valueNoise(X * 2.1 + 5, Y * 2.1 + 5)
293
+
294
+ return Math.max(0, Math.min(4, Math.floor(((h - 0.2) / 0.6) * 5)))
295
+ }
296
+
297
+ const bands = Array.from({ length: (n + 2) * (n + 2) }, (_, i) =>
298
+ band((i % (n + 2)) - 1, Math.floor(i / (n + 2)) - 1),
299
+ )
300
+
301
+ const at = (x: number, y: number) => bands[(y + 1) * (n + 2) + x + 1]
302
+
303
+ pixels.each((x, y) => {
304
+ const b = at(x, y)
305
+ const edge = at(x + 1, y) < b || at(x - 1, y) < b || at(x, y + 1) < b || at(x, y - 1) < b
306
+
307
+ return edge ? shade(ramp[b], 0.7) : ramp[b]
308
+ })
309
+ },
310
+ },
311
+ {
312
+ id: "cells",
313
+ name: "Cells",
314
+ family: "Pixel and dither",
315
+ label: "Voronoi cells from four to six seeds, with one-pixel seams",
316
+ animated: true,
317
+ resolve: (random) => ({ grid: 16, seed: seed(random("cells")), ...palette(random("palette")) }),
318
+ paint: (pixels, p, t) => {
319
+ const all = colors(p)
320
+ const rand = mulberry32(p.seed)
321
+ const offset = Math.floor(rand() * 5)
322
+
323
+ const sites = Array.from({ length: 4 + Math.floor(rand() * 3) }, (_, i) => {
324
+ const phase = rand() * 6.28
325
+
326
+ return {
327
+ x: rand() * pixels.n + Math.sin(t * 1.2 + phase) * 1.5 * Math.min(1, t),
328
+ y: rand() * pixels.n + Math.cos(t * 1.2 + phase) * 1.5 * Math.min(1, t),
329
+ color: all[(i + offset) % 5],
330
+ }
331
+ })
332
+
333
+ const seam = shade(ramped(all)[0], 0.55)
334
+
335
+ pixels.each((x, y) => {
336
+ const distances = sites
337
+ .map((site) => ({ color: site.color, d: Math.hypot(x + 0.5 - site.x, y + 0.5 - site.y) }))
338
+ .toSorted((a, b) => a.d - b.d)
339
+
340
+ return distances[1].d - distances[0].d < 1 ? seam : distances[0].color
341
+ })
342
+ },
343
+ },
344
+ {
345
+ id: "rings",
346
+ name: "Rings",
347
+ family: "Patterns",
348
+ label: "Off-centre concentric rings stepping through three inks",
349
+ animated: true,
350
+ resolve: (random) => {
351
+ const r = random("rings")
352
+
353
+ return {
354
+ grid: 16,
355
+ cx: 3 + r() * 10,
356
+ cy: 3 + r() * 10,
357
+ width: 1.5 + r(),
358
+ ...prefixed("r", shuffle(r, colors(palette(random("palette")))).slice(0, 3)),
359
+ }
360
+ },
361
+ paint: (pixels, p, t) => {
362
+ const cycle = colors(p, "r", 3)
363
+
364
+ pixels.each((x, y) => {
365
+ const ring = Math.floor((Math.hypot(x + 0.5 - p.cx, y + 0.5 - p.cy) - t * 3) / p.width)
366
+
367
+ return cycle[((ring % 3) + 3) % 3]
368
+ })
369
+ },
370
+ },
371
+ {
372
+ id: "kilim",
373
+ name: "Kilim",
374
+ family: "Patterns",
375
+ label: "Stepped diamonds or squares, mirrored like a woven rug",
376
+ animated: true,
377
+ resolve: (random) => {
378
+ const r = random("kilim")
379
+
380
+ const [period, band] = pick(r, [
381
+ [16, 2],
382
+ [8, 1],
383
+ [16, 3],
384
+ ])
385
+
386
+ return {
387
+ grid: 16,
388
+ period,
389
+ band,
390
+ metric: r() < 0.7 ? 0 : 1,
391
+ ...prefixed("r", shuffle(r, colors(palette(random("palette")))).slice(0, 4)),
392
+ }
393
+ },
394
+ paint: (pixels, p, t) => {
395
+ const cycle = colors(p, "r", 4)
396
+ const center = (p.period - 1) / 2
397
+ const shift = Math.floor(t * 3)
398
+
399
+ pixels.each((x, y) => {
400
+ const dx = Math.abs((x % p.period) - center)
401
+ const dy = Math.abs((y % p.period) - center)
402
+ const band = Math.floor((p.metric === 0 ? dx + dy : Math.max(dx, dy)) / p.band) - shift
403
+
404
+ return cycle[((band % 4) + 4) % 4]
405
+ })
406
+ },
407
+ },
408
+ {
409
+ id: "triangles",
410
+ name: "Triangles",
411
+ family: "Patterns",
412
+ label: "Four diagonal Truchet tiles; they flip one by one on hover",
413
+ animated: true,
414
+ resolve: (random) => {
415
+ const r = random("triangles")
416
+ const all = colors(palette(random("palette")))
417
+ const ground = pick(r, all)
418
+
419
+ return {
420
+ grid: 16,
421
+ seed: seed(r),
422
+ ground,
423
+ ink: legible(
424
+ r,
425
+ all.filter((color) => color !== ground),
426
+ ground,
427
+ ),
428
+ }
429
+ },
430
+ paint: (pixels, p, t) => {
431
+ const rand = mulberry32(p.seed)
432
+ const tiles = Array.from({ length: 4 }, () => ({ o: Math.floor(rand() * 4), r: rand() }))
433
+
434
+ pixels.each((x, y) => {
435
+ const tile = tiles[Math.floor(y / 8) * 2 + Math.floor(x / 8)]
436
+ const o = (tile.o + Math.floor(t * 1.2 + tile.r)) % 4
437
+ const lx = o & 1 ? 7 - (x % 8) : x % 8
438
+ const ly = o & 2 ? 7 - (y % 8) : y % 8
439
+
440
+ return lx + ly < 7 || (lx + ly === 7 && lx < 4) ? p.ink : p.ground
441
+ })
442
+ },
443
+ },
444
+ {
445
+ id: "quilt",
446
+ name: "Quilt",
447
+ family: "Patterns",
448
+ label: "Half-square triangles mirrored into a four-patch block",
449
+ resolve: (random) => {
450
+ const r = random("quilt")
451
+ const all = colors(palette(random("palette")))
452
+
453
+ return { grid: 16, seed: seed(r), ...prefixed("q", [all[0], ...shuffle(r, all.slice(1)).slice(0, 2)]) }
454
+ },
455
+ paint: (pixels, p) => {
456
+ const fabric = colors(p, "q", 3)
457
+ const rand = mulberry32(p.seed)
458
+
459
+ const blocks = Array.from({ length: 4 }, () => {
460
+ const a = Math.floor(rand() * 3)
461
+
462
+ return { o: Math.floor(rand() * 4), a, b: (a + 1 + Math.floor(rand() * 2)) % 3 }
463
+ })
464
+
465
+ pixels.each((x, y) => {
466
+ const X = x < 8 ? x : 15 - x
467
+ const Y = y < 8 ? y : 15 - y
468
+ const block = blocks[Math.floor(Y / 4) * 2 + Math.floor(X / 4)]
469
+ const lx = block.o & 1 ? 3 - (X % 4) : X % 4
470
+ const ly = block.o & 2 ? 3 - (Y % 4) : Y % 4
471
+
472
+ return fabric[lx + ly < 3 || (lx + ly === 3 && lx < 2) ? block.a : block.b]
473
+ })
474
+ },
475
+ },
476
+ {
477
+ id: "weave",
478
+ name: "Weave",
479
+ family: "Patterns",
480
+ label: "Basket or twill weave of flat two-pixel strands, each lit along one edge",
481
+ resolve: (random) => {
482
+ const r = random("weave")
483
+ const all = shuffle(r, colors(palette(random("palette"))))
484
+
485
+ return {
486
+ grid: 16,
487
+ twill: r() < 0.35 ? 1 : 0,
488
+ strands: r() < 0.5 ? 2 : 1,
489
+ warp: all[0],
490
+ weft: legible(r, all.slice(1), all[0]),
491
+ accent: all[1],
492
+ stripe: r() < 0.4 ? 1 : 0,
493
+ }
494
+ },
495
+ paint: (pixels, p) => {
496
+ pixels.each((x, y) => {
497
+ const cell = 4
498
+ const i = Math.floor(x / cell)
499
+ const j = Math.floor(y / cell)
500
+ const across = p.twill ? (i + j) % 4 < 2 : (i + j) % 2 === 0
501
+ const along = across ? y % cell : x % cell
502
+ const strand = Math.floor(along / (cell / p.strands))
503
+ const edge = along % (cell / p.strands)
504
+ const base = across ? p.weft : p.stripe && i % 3 === 1 ? p.accent : p.warp
505
+ const lit = edge === 0 ? tint(base, 0.18) : edge === cell / p.strands - 1 ? shade(base, 0.62) : base
506
+
507
+ return strand % 2 && p.strands === 2 ? shade(lit, 0.9) : lit
508
+ })
509
+ },
510
+ },
511
+ {
512
+ id: "one-bit",
513
+ name: "1-bit",
514
+ family: "Bits and symbols",
515
+ label: "A classic 8×8 fill pattern in one ink; it scrolls on hover",
516
+ animated: true,
517
+ resolve: (random) => {
518
+ const r = random("bits")
519
+ const all = colors(palette(random("palette")))
520
+ const ink = legible(r, all.slice(1), all[0])
521
+ const invert = r() < 0.5
522
+
523
+ return {
524
+ grid: 8,
525
+ pattern: Math.floor(r() * PATTERNS.length),
526
+ ox: Math.floor(r() * 8),
527
+ oy: Math.floor(r() * 8),
528
+ ink: invert ? all[0] : ink,
529
+ ground: invert ? ink : all[0],
530
+ }
531
+ },
532
+ paint: (pixels, p, t) => {
533
+ const shift = Math.floor(t * 3)
534
+ const rows = PATTERNS[p.pattern]
535
+
536
+ pixels.each((x, y) => ((rows[(y + p.oy + shift) & 7] >> (7 - ((x + p.ox + shift) & 7))) & 1 ? p.ink : p.ground))
537
+ },
538
+ },
539
+ {
540
+ id: "glyphs",
541
+ name: "Glyphs",
542
+ family: "Bits and symbols",
543
+ label: "Four 3×3 runes on coloured tiles; they cycle on hover",
544
+ animated: true,
545
+ resolve: (random) => ({ grid: 16, seed: seed(random("glyphs")), ...palette(random("palette")) }),
546
+ paint: (pixels, p, t) => {
547
+ const all = colors(p)
548
+ const rand = mulberry32(p.seed)
549
+
550
+ const grounds = retry(
551
+ () => Array.from({ length: 4 }, () => Math.floor(rand() * 5)),
552
+ (list) => list[0] !== list[1] && list[0] !== list[2] && list[3] !== list[1] && list[3] !== list[2],
553
+ )
554
+
555
+ const tiles = grounds.map((ground) => ({
556
+ ground: all[ground],
557
+ ink: legible(
558
+ rand,
559
+ all.filter((_, i) => i !== ground),
560
+ all[ground],
561
+ ),
562
+ glyph: Math.floor(rand() * GLYPHS.length),
563
+ r: rand(),
564
+ }))
565
+
566
+ pixels.each((x, y) => {
567
+ const tile = tiles[Math.floor(y / 8) * 2 + Math.floor(x / 8)]
568
+ const lx = (x % 8) - 1
569
+ const ly = (y % 8) - 1
570
+
571
+ if (lx < 0 || ly < 0 || lx > 5 || ly > 5) return tile.ground
572
+ const glyph = GLYPHS[(tile.glyph + Math.floor(t * 2 + tile.r)) % GLYPHS.length]
573
+
574
+ return (glyph >> (8 - (Math.floor(ly / 2) * 3 + Math.floor(lx / 2)))) & 1 ? tile.ink : tile.ground
575
+ })
576
+ },
577
+ },
578
+ {
579
+ id: "flag",
580
+ name: "Flag",
581
+ family: "Bits and symbols",
582
+ label: "Stripe, cross and canton compositions, like an invented flag",
583
+ resolve: (random) => {
584
+ const r = random("flag")
585
+
586
+ return {
587
+ grid: 16,
588
+ layout: Math.floor(r() * 9),
589
+ ...prefixed("f", shuffle(r, colors(palette(random("palette")))).slice(0, 3)),
590
+ }
591
+ },
592
+ paint: (pixels, p) => {
593
+ const [a, b, c] = colors(p, "f", 3)
594
+
595
+ const layouts = [
596
+ (x: number, y: number) => (y < 5 ? a : y < 11 ? b : c),
597
+ (x: number, _: number) => (x < 5 ? a : x < 11 ? b : c),
598
+ (x: number, y: number) =>
599
+ (x >= 5 && x <= 6) || (y >= 7 && y <= 8) ? c : (x >= 4 && x <= 7) || (y >= 6 && y <= 9) ? b : a,
600
+ (x: number, y: number) => (x + y < 14 ? a : x + y > 16 ? b : c),
601
+ (x: number, y: number) => (x < 7 && y < 7 ? c : Math.floor(y / 2) % 2 ? b : a),
602
+ (x: number, y: number) => (x < 8 - Math.abs(y - 7.5) ? c : y < 8 ? a : b),
603
+ (x: number, y: number) => (Math.hypot(x - 7.5, y - 7.5) < 4.6 ? b : a),
604
+ (x: number, y: number) => (x < 8 !== y < 8 ? b : a),
605
+ (x: number, y: number) => (Math.abs(x - y) <= 1 || Math.abs(x + y - 15) <= 1 ? b : a),
606
+ ]
607
+
608
+ pixels.each(layouts[p.layout])
609
+ },
610
+ },
611
+ {
612
+ id: "identicon",
613
+ name: "Identicon",
614
+ family: "Characters",
615
+ label: "A mirrored 6×6 sprite on a tinted ground",
616
+ resolve: (random) => {
617
+ const r = random("sprite")
618
+ const all = colors(palette(random("palette")))
619
+ const ink = legible(r, all.slice(1), all[0])
620
+ const invert = r() < 0.3
621
+
622
+ return {
623
+ grid: 8,
624
+ bits: retry(
625
+ () => Math.floor(r() * 2 ** 18),
626
+ (bits) => ones(bits) >= 7 && ones(bits) <= 12,
627
+ ),
628
+ ink: invert ? all[0] : ink,
629
+ ground: invert ? ink : mix(all[0], ink, 0.14),
630
+ }
631
+ },
632
+ paint: (pixels, p) => {
633
+ pixels.fill(p.ground)
634
+
635
+ for (let row = 0; row < 6; row++)
636
+ for (let column = 0; column < 3; column++) {
637
+ if (!((p.bits >> (row * 3 + column)) & 1)) continue
638
+ pixels.set(1 + column, 1 + row, p.ink)
639
+ pixels.set(6 - column, 1 + row, p.ink)
640
+ }
641
+ },
642
+ },
643
+ {
644
+ id: "critter",
645
+ name: "Critter",
646
+ family: "Characters",
647
+ label: "A mirrored little creature with see-through eyes; it walks and blinks on hover",
648
+ animated: true,
649
+ resolve: (random) => {
650
+ const r = random("critter")
651
+ const all = colors(palette(random("palette")))
652
+ const body = pick(r, all.slice(1))
653
+
654
+ return {
655
+ grid: 8,
656
+ w1: 1 + Math.floor(r() * 2),
657
+ w3: 2 + Math.floor(r() * 2),
658
+ w4: 1 + Math.floor(r() * 3),
659
+ antenna: Math.floor(r() * 3),
660
+ arms: r() < 0.5 ? 1 : 0,
661
+ legs: 1 + Math.floor(r() * 7),
662
+ feet: Math.floor(r() * 3),
663
+ cyclops: r() < 0.25 ? 1 : 0,
664
+ mouth: r() < 0.35 ? 1 : 0,
665
+ body,
666
+ ground: luma(body) > 0.45 ? mix(0x14151a, body, 0.15) : mix(all[0], body, 0.1),
667
+ }
668
+ },
669
+ paint: (pixels, p, t) => {
670
+ // Rows: antenna, head, eyes, body, belly, legs, feet, and an empty bottom row.
671
+ const widths = [0, p.w1, 3, p.w3, p.w4]
672
+ const step = Math.floor(t * 5) % 2
673
+ const blink = t % 2.2 > 2
674
+
675
+ const put = (dc: number, row: number, color: number) => {
676
+ pixels.set(3 - dc, row, color)
677
+ pixels.set(4 + dc, row, color)
678
+ }
679
+
680
+ pixels.fill(p.ground)
681
+ widths.forEach((width, row) => {
682
+ for (let dc = 0; dc < width; dc++) put(dc, row, p.body)
683
+ })
684
+
685
+ if (p.antenna) put(p.antenna, 0, p.body)
686
+
687
+ if (p.arms) put(3, 3, p.body)
688
+
689
+ for (let dc = 0; dc < 3; dc++) {
690
+ if (!((p.legs >> dc) & 1)) continue
691
+ put(dc, 5, p.body)
692
+ const shifted = Math.max(0, Math.min(3, dc + (p.feet === 1 ? 1 : p.feet === 2 ? -1 : 0)))
693
+ put(step ? dc : shifted, 6, p.body)
694
+ }
695
+
696
+ if (!blink) put(p.cyclops ? 0 : 1, 2, p.ground)
697
+
698
+ if (p.mouth && p.w4 > 1) put(0, 4, p.ground)
699
+ },
700
+ },
701
+ {
702
+ id: "phosphor",
703
+ name: "Phosphor",
704
+ family: "Characters",
705
+ label: "A glowing sprite on a dark tube with scanlines; the roll bar passes on hover",
706
+ animated: true,
707
+ resolve: (random) => {
708
+ const r = random("phosphor")
709
+
710
+ return {
711
+ grid: 16,
712
+ phosphor: pick(r, PHOSPHORS),
713
+ bits: retry(
714
+ () => Math.floor(r() * 2 ** 15),
715
+ (bits) => ones(bits) >= 7 && ones(bits) <= 11 && (bits & 0b100100100100100) !== 0,
716
+ ),
717
+ }
718
+ },
719
+ paint: (pixels, p, t) => {
720
+ const ground = mix(0x060807, p.phosphor, 0.06)
721
+
722
+ const lit = (x: number, y: number) => {
723
+ if (x < 3 || y < 3 || x > 12 || y > 12) return false
724
+ const gx = Math.floor((x - 3) / 2)
725
+ const gy = Math.floor((y - 3) / 2)
726
+
727
+ return ((p.bits >> (gy * 3 + (gx < 3 ? gx : 4 - gx))) & 1) === 1
728
+ }
729
+
730
+ const bar = ((t * 7) % 24) - 4
731
+
732
+ pixels.each((x, y) => {
733
+ const on = lit(x, y)
734
+ const glow = !on && (lit(x - 1, y) || lit(x + 1, y) || lit(x, y - 1) || lit(x, y + 1))
735
+ const base = on ? p.phosphor : glow ? mix(ground, p.phosphor, 0.3) : ground
736
+ const roll = t > 0 ? Math.max(0, 1 - Math.abs(y - bar) / 2.5) : 0
737
+ const scan = y % 2 ? 0.62 : 1
738
+ const vignette = Math.hypot(x - 7.5, y - 7.5) > 7.5 ? 0.8 : 1
739
+
740
+ return shade(mix(base, tint(p.phosphor, 0.5), roll * 0.35), scan * vignette)
741
+ })
742
+ },
743
+ },
744
+ {
745
+ id: "planet",
746
+ name: "Planet",
747
+ family: "Scenes",
748
+ label: "A banded, dithered planet, sometimes ringed; it turns on hover",
749
+ animated: true,
750
+ resolve: (random) => {
751
+ const r = random("planet")
752
+ const inks = colors(palette(random("palette"))).slice(1)
753
+ const [a, b, ring] = shuffle(r, inks)
754
+
755
+ return {
756
+ grid: 16,
757
+ seed: seed(r),
758
+ space: pick(r, SPACE),
759
+ a,
760
+ b,
761
+ ringColor: tint(ring, 0.35),
762
+ ring: r() < 0.4 ? 1 : 0,
763
+ tilt: (r() - 0.5) * 0.8,
764
+ radius: 5.2 + r() * 1.2,
765
+ bands: 2 + r() * 3,
766
+ phase: r() * 6.28,
767
+ }
768
+ },
769
+ paint: (pixels, p, t) => {
770
+ pixels.fill(p.space)
771
+ stars(pixels, mulberry32(p.seed), p.space, 5)
772
+ const [lx, ly, lz] = normalize(-0.55, -0.5, 0.67)
773
+ const cos = Math.cos(p.tilt)
774
+ const sin = Math.sin(p.tilt)
775
+
776
+ pixels.each((x, y) => {
777
+ const dx = (x + 0.5 - 8) / p.radius
778
+ const dy = (y + 0.5 - 8) / p.radius
779
+ const rx = dx * cos + dy * sin
780
+ const ry = -dx * sin + dy * cos
781
+ const e = (rx / 1.75) ** 2 + (ry / 0.42) ** 2
782
+ const ring = p.ring === 1 && e > 0.72 && e < 1
783
+
784
+ if (dx * dx + dy * dy > 1) return ring ? p.ringColor : undefined
785
+
786
+ if (ring && ry > 0) return p.ringColor
787
+ const dz = Math.sqrt(1 - dx * dx - dy * dy)
788
+ const lon = Math.atan2(dx, dz) + t * 1.2
789
+ const base = Math.sin(dy * p.bands * Math.PI + p.phase + 0.6 * Math.sin(lon * 2 + dy * 3)) > 0 ? p.a : p.b
790
+
791
+ return [shade(base, 0.5), base, tint(base, 0.3)][dither((dx * lx + dy * ly + dz * lz) * 0.75 + 0.3, 3, x, y)]
792
+ })
793
+ },
794
+ },
795
+ {
796
+ id: "moon",
797
+ name: "Moon",
798
+ family: "Scenes",
799
+ label: "A cratered moon in phase with a faint halo; it waxes on hover",
800
+ animated: true,
801
+ resolve: (random) => {
802
+ const r = random("moon")
803
+ const paper = colors(palette(random("palette")))[0]
804
+
805
+ return {
806
+ grid: 16,
807
+ seed: seed(r),
808
+ night: pick(r, SPACE),
809
+ moon: mix(paper, 0xd8dce6, r() * 0.6),
810
+ radius: 5.4 + r(),
811
+ ox: (r() - 0.5) * 1.2,
812
+ oy: (r() - 0.5) * 1.2,
813
+ phase: 0.55 + r() * 0.9,
814
+ side: r() < 0.5 ? -1 : 1,
815
+ }
816
+ },
817
+ paint: (pixels, p, t) => {
818
+ const rand = mulberry32(p.seed)
819
+ const cx = 8 + p.ox
820
+ const cy = 8 + p.oy
821
+ pixels.fill(p.night)
822
+ stars(pixels, rand, p.night, 4)
823
+
824
+ const craters = Array.from({ length: 4 }, () => ({
825
+ x: cx + (rand() * 2 - 1) * p.radius * 0.6,
826
+ y: cy + (rand() * 2 - 1) * p.radius * 0.6,
827
+ r: 0.8 + rand() * 1.2,
828
+ }))
829
+
830
+ const offset = (p.phase + Math.sin(t * 0.9) * 0.45) * p.radius * p.side
831
+
832
+ pixels.each((x, y) => {
833
+ const d = Math.hypot(x + 0.5 - cx, y + 0.5 - cy)
834
+
835
+ if (d > p.radius) return d < p.radius + 1 ? mix(p.night, p.moon, 0.12) : undefined
836
+
837
+ const surface = craters.some((crater) => Math.hypot(x + 0.5 - crater.x, y + 0.5 - crater.y) < crater.r)
838
+ ? shade(p.moon, 0.8)
839
+ : p.moon
840
+
841
+ return Math.hypot(x + 0.5 - cx - offset, y + 0.5 - cy) < p.radius ? mix(p.night, surface, 0.16) : surface
842
+ })
843
+ },
844
+ },
845
+ {
846
+ id: "starfield",
847
+ name: "Starfield",
848
+ family: "Scenes",
849
+ label: "Stars, two with cross glints, over a dithered nebula; they twinkle on hover",
850
+ animated: true,
851
+ resolve: (random) => {
852
+ const r = random("stars")
853
+
854
+ return {
855
+ grid: 16,
856
+ seed: seed(r),
857
+ space: pick(r, SPACE),
858
+ nebula: pick(r, colors(palette(random("palette"))).slice(1)),
859
+ seedX: r() * 40,
860
+ seedY: r() * 40,
861
+ }
862
+ },
863
+ paint: (pixels, p, t) => {
864
+ const bottom = mix(p.space, p.nebula, 0.12)
865
+
866
+ pixels.each((x, y) => {
867
+ const base = dither(y / 15, 2, x, y) ? bottom : p.space
868
+
869
+ const cloud =
870
+ 0.7 * valueNoise(x * 0.22 + p.seedX, y * 0.22 + p.seedY) +
871
+ 0.3 * valueNoise(x * 0.5 + p.seedY, y * 0.5 + p.seedX)
872
+
873
+ const level = dither((cloud - 0.4) / 0.3, 3, x, y)
874
+
875
+ return level ? mix(base, p.nebula, level * 0.18) : base
876
+ })
877
+ const rand = mulberry32(p.seed)
878
+ Array.from({ length: 10 }, (_, i) => {
879
+ const x = i < 2 ? 2 + Math.floor(rand() * 12) : Math.floor(rand() * 16)
880
+ const y = i < 2 ? 2 + Math.floor(rand() * 12) : Math.floor(rand() * 16)
881
+ const level = [0.55, 0.8, 1][Math.floor(rand() * 3)]
882
+ const twinkle = 1 - 0.45 * (1 - Math.cos(t * (2 + rand() * 4)))
883
+ pixels.set(x, y, mix(p.space, i % 3 ? 0xfff6e0 : 0xdfe9ff, (i < 2 ? 1 : level) * twinkle))
884
+
885
+ if (i >= 2) return
886
+ const glint = mix(p.space, 0xfff6e0, 0.7 * twinkle)
887
+ pixels.set(x - 1, y, glint)
888
+ pixels.set(x + 1, y, glint)
889
+ pixels.set(x, y - 1, glint)
890
+ pixels.set(x, y + 1, glint)
891
+ })
892
+ },
893
+ },
894
+ {
895
+ id: "horizon",
896
+ name: "Horizon",
897
+ family: "Scenes",
898
+ label: "A dithered sky, a sun and two ridgelines; they drift on hover",
899
+ animated: true,
900
+ resolve: (random) => {
901
+ const r = random("horizon")
902
+
903
+ return {
904
+ grid: 16,
905
+ ...prefixed("s", pick(r, SCENES)),
906
+ sunX: 4 + r() * 8,
907
+ sunY: 4.5 + r() * 3.5,
908
+ back: 6 + r() * 2,
909
+ front: 3 + r() * 1.5,
910
+ p1: r() * 6.28,
911
+ p2: r() * 6.28,
912
+ p3: r() * 6.28,
913
+ p4: r() * 6.28,
914
+ }
915
+ },
916
+ paint: (pixels, p, t) => {
917
+ const [top, bottom, sun, far, near] = colors(p, "s", 5)
918
+ const sky = [top, mix(top, bottom, 0.5), bottom]
919
+
920
+ pixels.each((x, y) => {
921
+ const front = p.front + 1.3 * (Math.sin(x * 0.7 + p.p3 + t * 1.4) + 0.5 * Math.sin(x * 1.6 + p.p4 + t * 1.4))
922
+
923
+ if (y >= 16 - front) return near
924
+ const back = p.back + 1.6 * (Math.sin(x * 0.5 + p.p1 + t * 0.6) + 0.5 * Math.sin(x * 1.1 + p.p2 + t * 0.6))
925
+
926
+ if (y >= 16 - back) return far
927
+
928
+ if (Math.hypot(x + 0.5 - p.sunX, y + 0.5 - p.sunY) < 2.6) return sun
929
+
930
+ return sky[dither(y / 12, 3, x, y)]
931
+ })
932
+ },
933
+ },
934
+ {
935
+ id: "sundown",
936
+ name: "Sundown",
937
+ family: "Scenes",
938
+ label: "A slatted retro sun over a perspective grid; the slats rise on hover",
939
+ animated: true,
940
+ resolve: (random) => {
941
+ const r = random("sundown")
942
+
943
+ return { grid: 16, radius: 4.6 + r(), ...prefixed("s", pick(r, SYNTH)) }
944
+ },
945
+ paint: (pixels, p, t) => {
946
+ const [top, bottom, sunTop, sunBottom, ground, line] = colors(p, "s", 6)
947
+ const sky = [top, mix(top, bottom, 0.5), bottom]
948
+ const shift = Math.floor(t * 4)
949
+
950
+ pixels.each((x, y) => {
951
+ if (y === 11) return line
952
+
953
+ if (y > 11) {
954
+ const depth = (y + 0.5 - 11) / 4.5
955
+ const lane = (x + 0.5 - 8) / depth / 5
956
+ const horizontal = y === 13 || y === 15
957
+
958
+ return horizontal || Math.abs(lane - Math.round(lane)) < 0.5 / (5 * depth) ? mix(ground, line, 0.75) : ground
959
+ }
960
+
961
+ if (Math.hypot(x + 0.5 - 8, y + 0.5 - 11) < p.radius && !(y >= 7 && (y + shift) % 3 === 0))
962
+ return dither((y - (11 - p.radius)) / p.radius, 2, x, y) ? sunBottom : sunTop
963
+
964
+ return sky[dither(y / 11, 3, x, y)]
965
+ })
966
+ },
967
+ },
968
+ {
969
+ id: "sprout",
970
+ name: "Sprout",
971
+ family: "Scenes",
972
+ label: "A plant with leaves and a bloom on a strip of soil; it sways on hover",
973
+ animated: true,
974
+ resolve: (random) => {
975
+ const r = random("sprout")
976
+ const all = colors(palette(random("palette")))
977
+ const bloom = legible(r, all.slice(1), all[0])
978
+
979
+ return {
980
+ grid: 16,
981
+ seed: seed(r),
982
+ paper: all[0],
983
+ leaf: pick(r, LEAVES),
984
+ soil: pick(r, SOILS),
985
+ bloom,
986
+ center: luma(bloom) > 0.6 ? shade(bloom, 0.55) : 0xf6c344,
987
+ height: 6 + Math.floor(r() * 3),
988
+ x: 7 + Math.floor(r() * 2),
989
+ flower: Math.floor(r() * 3),
990
+ leafA: 2 + Math.floor(r() * 2),
991
+ leafB: 4 + Math.floor(r() * 2),
992
+ side: r() < 0.5 ? -1 : 1,
993
+ }
994
+ },
995
+ paint: (pixels, p, t) => {
996
+ const top = 12 - p.height
997
+ const sway = (y: number) => Math.round(Math.sin(t * 2.2) * ((12 - y) / p.height) * 1.4 * Math.min(1, t * 2))
998
+ const rand = mulberry32(p.seed)
999
+ pixels.fill(p.paper)
1000
+ pixels.rect(0, 13, 16, 3, p.soil)
1001
+ pixels.rect(0, 13, 16, 1, tint(p.soil, 0.18))
1002
+ Array.from({ length: 3 }, () => pixels.set(Math.floor(rand() * 16), 12, p.leaf))
1003
+
1004
+ for (let y = 12; y > top; y--) pixels.set(p.x + sway(y), y, p.leaf)
1005
+ ;[
1006
+ [p.leafA, p.side],
1007
+ [p.leafB, -p.side],
1008
+ ].forEach(([height, side]) => {
1009
+ const y = 12 - height
1010
+ const x = p.x + sway(y)
1011
+ pixels.set(x + side, y, p.leaf)
1012
+ pixels.set(x + side * 2, y - 1, p.leaf)
1013
+ pixels.set(x + side, y - 1, tint(p.leaf, 0.2))
1014
+ })
1015
+ const x = p.x + sway(top)
1016
+
1017
+ const flowers = [
1018
+ () => {
1019
+ ;[
1020
+ [0, -1],
1021
+ [-1, 0],
1022
+ [1, 0],
1023
+ [0, 1],
1024
+ ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.bloom))
1025
+ pixels.set(x, top, p.center)
1026
+ },
1027
+ () => {
1028
+ pixels.rect(x - 1, top - 1, 3, 2, p.bloom)
1029
+ pixels.set(x - 1, top - 2, p.bloom)
1030
+ pixels.set(x + 1, top - 2, p.bloom)
1031
+ pixels.set(x, top - 1, shade(p.bloom, 0.75))
1032
+ },
1033
+ () => {
1034
+ ;[
1035
+ [-2, 0],
1036
+ [2, 0],
1037
+ [0, -2],
1038
+ [0, 2],
1039
+ [-1, -1],
1040
+ [1, -1],
1041
+ [-1, 1],
1042
+ [1, 1],
1043
+ ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.bloom))
1044
+ ;[
1045
+ [0, 0],
1046
+ [-1, 0],
1047
+ [1, 0],
1048
+ [0, -1],
1049
+ [0, 1],
1050
+ ].forEach(([dx, dy]) => pixels.set(x + dx, top + dy, p.center))
1051
+ },
1052
+ ]
1053
+
1054
+ flowers[p.flower]()
1055
+ },
1056
+ },
1057
+ {
1058
+ id: "iso",
1059
+ name: "Iso blocks",
1060
+ family: "Scenes",
1061
+ label: "Isometric cubes stacked on a 2×2 footprint, lit from the top left",
1062
+ resolve: (random) => {
1063
+ const r = random("iso")
1064
+
1065
+ const heights = retry(
1066
+ () => Array.from({ length: 4 }, () => Math.floor(r() * 3)),
1067
+ (list) => list.reduce((sum, h) => sum + h, 0) >= 3,
1068
+ )
1069
+
1070
+ return {
1071
+ grid: 16,
1072
+ ...prefixed("h", heights),
1073
+ ...prefixed(
1074
+ "k",
1075
+ heights.map(() => Math.floor(r() * 4)),
1076
+ ),
1077
+ ...palette(random("palette")),
1078
+ }
1079
+ },
1080
+ paint: (pixels, p) => {
1081
+ const inks = colors(p).slice(1)
1082
+
1083
+ const cubes = [
1084
+ [0, 0],
1085
+ [1, 0],
1086
+ [0, 1],
1087
+ [1, 1],
1088
+ ]
1089
+ .flatMap(([i, j], index) =>
1090
+ Array.from({ length: p[`h${index}`] }, (_, k) => ({ i, j, k, ink: inks[p[`k${index}`]] })),
1091
+ )
1092
+ .toSorted((a, b) => a.i + a.j - (b.i + b.j) || a.k - b.k)
1093
+
1094
+ const tops = cubes.map((cube) => (cube.i + cube.j) * 2 - cube.k * 4)
1095
+ const extent = Math.max(...tops) + 8 - Math.min(...tops)
1096
+ const oy = Math.round((16 - extent) / 2) - Math.min(...tops)
1097
+
1098
+ pixels.fill(p.c0)
1099
+ cubes.forEach((cube) => {
1100
+ const faces = { T: tint(cube.ink, 0.3), L: cube.ink, R: shade(cube.ink, 0.72) }
1101
+ const x0 = 4 + (cube.i - cube.j) * 4
1102
+ const y0 = oy + (cube.i + cube.j) * 2 - cube.k * 4
1103
+ CUBE.forEach((row, dy) =>
1104
+ [...row].forEach((face, dx) => {
1105
+ if (face === "T" || face === "L" || face === "R") pixels.set(x0 + dx, y0 + dy, faces[face])
1106
+ }),
1107
+ )
1108
+ })
1109
+ },
1110
+ },
1111
+ {
1112
+ id: "stack",
1113
+ name: "Stack",
1114
+ family: "Geometry",
1115
+ label: "Tetrominoes dropped into an eight-wide well, with the next piece falling; it lands on hover",
1116
+ animated: true,
1117
+ resolve: (random) => {
1118
+ const r = random("stack")
1119
+
1120
+ return {
1121
+ grid: 16,
1122
+ seed: seed(r),
1123
+ pieces: int(r, 12, 18),
1124
+ ...prefixed("t", pick(r, TETROMINO_COLORS)),
1125
+ well: pick(r, [0x0b0d14, 0x101010, 0x14102a, 0x0a1a1f]),
1126
+ }
1127
+ },
1128
+ paint: (pixels, p, t) => {
1129
+ const tints = colors(p, "t", 7)
1130
+ const rand = mulberry32(p.seed)
1131
+ const board = Array.from({ length: 64 }, () => -1)
1132
+ const filled = (x: number, y: number) => x < 0 || x > 7 || y > 7 || (y >= 0 && board[y * 8 + x] >= 0)
1133
+ const fits = (cells: number[][], x: number, y: number) => cells.every(([cx, cy]) => !filled(x + cx, y + cy))
1134
+
1135
+ // Drop each piece where it leaves the fewest holes of six random columns and turns, as a player would, keeping
1136
+ // the top three rows clear.
1137
+ Array.from({ length: p.pieces }, () => {
1138
+ const kind = Math.floor(rand() * 7)
1139
+
1140
+ const [cells, x, y] = Array.from({ length: 6 }, () => {
1141
+ const cells = turned(TETROMINOES[kind], Math.floor(rand() * 4))
1142
+ const x = Math.floor(rand() * (9 - (Math.max(...cells.map(([cx]) => cx)) + 1)))
1143
+ let y = -2
1144
+
1145
+ while (fits(cells, x, y + 1)) y++
1146
+ const own = (cx: number, cy: number) => cells.some(([ox, oy]) => ox === cx && oy === cy)
1147
+ const holes = cells.filter(([cx, cy]) => !own(cx, cy + 1) && !filled(x + cx, y + cy + 1)).length
1148
+
1149
+ return [cells, x, y, y - holes * 3] as const
1150
+ }).toSorted((a, b) => b[3] - a[3])[0]
1151
+
1152
+ if (cells.some(([, cy]) => y + cy < 3)) return
1153
+ cells.forEach(([cx, cy]) => (board[(y + cy) * 8 + x + cx] = kind))
1154
+ })
1155
+
1156
+ const kind = Math.floor(rand() * 7)
1157
+ const falling = turned(TETROMINOES[kind], Math.floor(rand() * 4))
1158
+ const fx = Math.floor(rand() * (9 - (Math.max(...falling.map(([x]) => x)) + 1)))
1159
+ let landing = 0
1160
+
1161
+ while (fits(falling, fx, landing + 1)) landing++
1162
+ const fy = Math.min(landing, Math.floor(t * 4))
1163
+
1164
+ pixels.fill(p.well)
1165
+
1166
+ const block = (bx: number, by: number, color: number) => {
1167
+ pixels.set(bx * 2, by * 2, tint(color, 0.45))
1168
+ pixels.set(bx * 2 + 1, by * 2, color)
1169
+ pixels.set(bx * 2, by * 2 + 1, color)
1170
+ pixels.set(bx * 2 + 1, by * 2 + 1, shade(color, 0.6))
1171
+ }
1172
+
1173
+ board.forEach((piece, i) => piece >= 0 && block(i % 8, Math.floor(i / 8), tints[piece]))
1174
+ falling.forEach(([cx, cy]) => block(fx + cx, fy + cy, tints[kind]))
1175
+ },
1176
+ },
1177
+ {
1178
+ id: "maze",
1179
+ name: "Maze",
1180
+ family: "Geometry",
1181
+ label: "A 5×5 backtracker maze with its route marked; a runner walks it on hover",
1182
+ animated: true,
1183
+ resolve: (random) => {
1184
+ const r = random("maze")
1185
+ const all = colors(palette(random("palette")))
1186
+ const wall = ramped(all.slice(1))[0]
1187
+
1188
+ return {
1189
+ grid: 16,
1190
+ seed: seed(r),
1191
+ wall,
1192
+ path: all[0],
1193
+ route: legible(
1194
+ r,
1195
+ all.slice(1).filter((color) => color !== wall),
1196
+ all[0],
1197
+ ),
1198
+ }
1199
+ },
1200
+ paint: (pixels, p, t) => {
1201
+ const rand = mulberry32(p.seed)
1202
+ const passages = new Set<string>()
1203
+ const visited = new Set([0])
1204
+ const stack = [0]
1205
+ const link = (a: number, b: number) => `${Math.min(a, b)}-${Math.max(a, b)}`
1206
+
1207
+ const neighbours = (cell: number) =>
1208
+ [
1209
+ [1, 0],
1210
+ [-1, 0],
1211
+ [0, 1],
1212
+ [0, -1],
1213
+ ].flatMap(([dx, dy]) => {
1214
+ const x = (cell % 5) + dx
1215
+ const y = Math.floor(cell / 5) + dy
1216
+
1217
+ return x >= 0 && y >= 0 && x < 5 && y < 5 ? [y * 5 + x] : []
1218
+ })
1219
+
1220
+ while (stack.length) {
1221
+ const cell = stack[stack.length - 1]
1222
+ const options = neighbours(cell).filter((next) => !visited.has(next))
1223
+
1224
+ if (!options.length) {
1225
+ stack.pop()
1226
+ continue
1227
+ }
1228
+
1229
+ const next = options[Math.floor(rand() * options.length)]
1230
+ visited.add(next)
1231
+ passages.add(link(cell, next))
1232
+ stack.push(next)
1233
+ }
1234
+
1235
+ // The tree has one path between any two cells: walk back from the exit through each cell's parent.
1236
+ const parents = new Map([[0, -1]])
1237
+ const queue = [0]
1238
+
1239
+ while (queue.length) {
1240
+ const cell = queue.shift()!
1241
+ neighbours(cell)
1242
+ .filter((next) => passages.has(link(cell, next)) && !parents.has(next))
1243
+ .forEach((next) => {
1244
+ parents.set(next, cell)
1245
+ queue.push(next)
1246
+ })
1247
+ }
1248
+
1249
+ const route = [24]
1250
+
1251
+ while (route[route.length - 1] !== 0) route.push(parents.get(route[route.length - 1])!)
1252
+
1253
+ const open = (a: number, b: number, color: number) => {
1254
+ const ax = 1 + 3 * (a % 5)
1255
+ const ay = 1 + 3 * Math.floor(a / 5)
1256
+ pixels.rect(ax, ay, 2, 2, color)
1257
+
1258
+ if (b < 0) return
1259
+ const bx = 1 + 3 * (b % 5)
1260
+ const by = 1 + 3 * Math.floor(b / 5)
1261
+ pixels.rect(Math.min(ax, bx), Math.min(ay, by), Math.abs(ax - bx) + 2, Math.abs(ay - by) + 2, color)
1262
+ }
1263
+
1264
+ pixels.fill(p.wall)
1265
+ Array.from({ length: 25 }, (_, cell) => open(cell, -1, p.path))
1266
+ passages.forEach((key) => {
1267
+ const [a, b] = key.split("-").map(Number)
1268
+ open(a, b, p.path)
1269
+ })
1270
+ route.forEach((cell, i) => open(cell, route[i + 1] ?? -1, p.route))
1271
+
1272
+ if (t <= 0) return
1273
+ const runner = route.toReversed()[Math.floor(t * 5) % route.length]
1274
+ open(runner, -1, tint(p.route, 0.65))
1275
+ },
1276
+ },
1277
+ {
1278
+ id: "rule",
1279
+ name: "Rule",
1280
+ family: "Geometry",
1281
+ label: "An elementary cellular automaton grown from a random first row; it scrolls on hover",
1282
+ animated: true,
1283
+ resolve: (random) => {
1284
+ const r = random("rule")
1285
+ const all = colors(palette(random("palette")))
1286
+ const a = legible(r, all.slice(1), all[0])
1287
+
1288
+ return {
1289
+ grid: 16,
1290
+ rule: pick(r, RULES),
1291
+ first: Array.from({ length: 1 + Math.floor(r() * 3) }, () => 1 << Math.floor(r() * 16)).reduce(
1292
+ (bits, bit) => bits | bit,
1293
+ 0,
1294
+ ),
1295
+ ground: all[0],
1296
+ a,
1297
+ b: legible(
1298
+ r,
1299
+ all.slice(1).filter((color) => color !== a),
1300
+ all[0],
1301
+ ),
1302
+ }
1303
+ },
1304
+ paint: (pixels, p, t) => {
1305
+ const next = (cells: number[]) =>
1306
+ cells.map((cell, i) => (p.rule >> ((cells[(i + 15) % 16] << 2) | (cell << 1) | cells[(i + 1) % 16])) & 1)
1307
+
1308
+ const first = Array.from({ length: 16 }, (_, i) => (p.first >> i) & 1)
1309
+
1310
+ const rows = Array.from({ length: 15 + Math.floor(t * 6) }).reduce<number[][]>(
1311
+ (history) => [...history, next(history[history.length - 1])],
1312
+ [first],
1313
+ )
1314
+
1315
+ const visible = rows.slice(-16)
1316
+
1317
+ pixels.each((x, y) => (visible[y][x] ? (dither(y / 15, 2, x, y) ? p.b : p.a) : p.ground))
1318
+ },
1319
+ },
1320
+ {
1321
+ id: "arcs",
1322
+ name: "Arcs",
1323
+ family: "Geometry",
1324
+ label: "Smooth Truchet quarter-circles; tiles turn on hover",
1325
+ animated: true,
1326
+ resolve: (random) => {
1327
+ const r = random("arcs")
1328
+ const all = colors(palette(random("palette")))
1329
+ const ground = pick(r, all.slice(1))
1330
+
1331
+ return {
1332
+ seed: seed(r),
1333
+ tiles: r() < 0.5 ? 2 : 3,
1334
+ weight: 0.2 + r() * 0.08,
1335
+ ground,
1336
+ ink: legible(
1337
+ r,
1338
+ all.filter((color) => color !== ground),
1339
+ ground,
1340
+ ),
1341
+ }
1342
+ },
1343
+ vector: (ctx, px, p, t) => {
1344
+ const size = px / p.tiles
1345
+ const rand = mulberry32(p.seed)
1346
+ ctx.fillStyle = css(p.ground)
1347
+ ctx.fillRect(0, 0, px, px)
1348
+ ctx.strokeStyle = css(p.ink)
1349
+ ctx.lineWidth = size * p.weight
1350
+
1351
+ for (let i = 0; i < p.tiles; i++)
1352
+ for (let j = 0; j < p.tiles; j++) {
1353
+ const turn = rand() < 0.5 ? Math.PI / 2 : 0
1354
+ const delay = rand()
1355
+ ctx.save()
1356
+ ctx.translate((i + 0.5) * size, (j + 0.5) * size)
1357
+ ctx.rotate(turn + ease(t * 1.2 - delay * 0.8) * (Math.PI / 2))
1358
+ ctx.beginPath()
1359
+ ctx.arc(-size / 2, -size / 2, size / 2, 0, Math.PI / 2)
1360
+ ctx.moveTo(0, size / 2)
1361
+ ctx.arc(size / 2, size / 2, size / 2, Math.PI, Math.PI * 1.5)
1362
+ ctx.stroke()
1363
+ ctx.restore()
1364
+ }
1365
+ },
1366
+ },
1367
+ {
1368
+ id: "bauhaus",
1369
+ name: "Bauhaus",
1370
+ family: "Geometry",
1371
+ label: "Circles, halves and quarters on a 2×2 grid; forms turn on hover",
1372
+ animated: true,
1373
+ resolve: (random) => ({ seed: seed(random("bauhaus")), ...palette(random("palette")) }),
1374
+ vector: (ctx, px, p, t) => {
1375
+ const all = colors(p)
1376
+ const rand = mulberry32(p.seed)
1377
+ const size = px / 2
1378
+
1379
+ const grounds = retry(
1380
+ () => Array.from({ length: 4 }, () => Math.floor(rand() * 5)),
1381
+ (list) => list[0] !== list[1] && list[0] !== list[2] && list[3] !== list[1] && list[3] !== list[2],
1382
+ )
1383
+
1384
+ grounds.forEach((ground, index) => {
1385
+ const inks = all.filter((_, i) => i !== ground)
1386
+ const ink = inks[Math.floor(rand() * inks.length)]
1387
+ const form = Math.floor(rand() * 4)
1388
+ const turn = Math.floor(rand() * 4)
1389
+ const delay = rand()
1390
+ ctx.save()
1391
+ ctx.translate(((index % 2) + 0.5) * size, (Math.floor(index / 2) + 0.5) * size)
1392
+ ctx.fillStyle = css(all[ground])
1393
+ ctx.fillRect(-size / 2 - 0.5, -size / 2 - 0.5, size + 1, size + 1)
1394
+ ctx.rotate((turn + ease(t * 1.1 - delay * 0.6)) * (Math.PI / 2))
1395
+ ctx.fillStyle = css(ink)
1396
+ ctx.beginPath()
1397
+
1398
+ const forms = [
1399
+ () => ctx.arc(0, 0, size * 0.34, 0, Math.PI * 2),
1400
+ () => ctx.arc(0, size / 2, size / 2, Math.PI, Math.PI * 2),
1401
+ () => {
1402
+ ctx.moveTo(-size / 2, -size / 2)
1403
+ ctx.arc(-size / 2, -size / 2, size, 0, Math.PI / 2)
1404
+ },
1405
+ () => {
1406
+ ctx.moveTo(-size / 2, -size / 2)
1407
+ ctx.lineTo(size / 2, -size / 2)
1408
+ ctx.lineTo(-size / 2, size / 2)
1409
+ },
1410
+ ]
1411
+
1412
+ forms[form]()
1413
+ ctx.closePath()
1414
+ ctx.fill()
1415
+ ctx.restore()
1416
+ })
1417
+ },
1418
+ },
1419
+ {
1420
+ id: "sweep",
1421
+ name: "Sweep",
1422
+ family: "Gradients",
1423
+ label: "A conic sweep through three inks with a soft highlight; it turns on hover",
1424
+ animated: true,
1425
+ resolve: (random) => {
1426
+ const r = random("sweep")
1427
+
1428
+ return {
1429
+ angle: r() * Math.PI * 2,
1430
+ cx: 0.25 + r() * 0.5,
1431
+ cy: 0.25 + r() * 0.5,
1432
+ ...prefixed("s", shuffle(r, colors(palette(random("palette"))).slice(1)).slice(0, 3)),
1433
+ }
1434
+ },
1435
+ vector: (ctx, px, p, t) => {
1436
+ const [a, b, c] = colors(p, "s", 3)
1437
+ const sweep = ctx.createConicGradient(p.angle + t * 0.8, p.cx * px, p.cy * px)
1438
+ sweep.addColorStop(0, css(a))
1439
+ sweep.addColorStop(1 / 3, css(b))
1440
+ sweep.addColorStop(2 / 3, css(c))
1441
+ sweep.addColorStop(1, css(a))
1442
+ ctx.fillStyle = sweep
1443
+ ctx.fillRect(0, 0, px, px)
1444
+ const light = ctx.createRadialGradient(px * 0.3, px * 0.2, 0, px * 0.3, px * 0.2, px * 0.8)
1445
+ light.addColorStop(0, "rgba(255, 255, 255, 0.28)")
1446
+ light.addColorStop(1, "rgba(255, 255, 255, 0)")
1447
+ ctx.fillStyle = light
1448
+ ctx.fillRect(0, 0, px, px)
1449
+ },
1450
+ },
1451
+ ]
1452
+
1453
+ const MESH: ProjectIconStyle = {
1454
+ id: "mesh",
1455
+ name: "Mesh",
1456
+ label: "The current default: James's mesh gradient with film grain",
1457
+ family: "Gradients",
1458
+ animated: true,
1459
+ generate: generateProjectIcon,
1460
+ draw: drawProjectIcon,
1461
+ }
1462
+
1463
+ /** The gallery's groups, in order: the first set of styles, then the second set from the craft, world and machine files. */
1464
+ export const PROJECT_ICON_FAMILIES = [
1465
+ "Gradients",
1466
+ "Pixel and dither",
1467
+ "Patterns",
1468
+ "Bits and symbols",
1469
+ "Characters",
1470
+ "Scenes",
1471
+ "Geometry",
1472
+ "Textiles",
1473
+ "Print",
1474
+ "Art movements",
1475
+ "Nature and materials",
1476
+ "Creatures",
1477
+ "Objects",
1478
+ "Emblems",
1479
+ "Retro tech",
1480
+ "Tiling and curves",
1481
+ ]
1482
+
1483
+ export const PROJECT_ICON_STYLES: readonly ProjectIconStyle[] = [
1484
+ MESH,
1485
+ ...[...DEFINITIONS, ...CRAFT, ...WORLD, ...MACHINE].map(define),
1486
+ ].toSorted((a, b) => PROJECT_ICON_FAMILIES.indexOf(a.family) - PROJECT_ICON_FAMILIES.indexOf(b.family))
1487
+
1488
+ export function projectIconStyle(id: string) {
1489
+ return PROJECT_ICON_STYLES.find((style) => style.id === id) ?? MESH
1490
+ }
1491
+
1492
+ // A tetromino's cells after `turns` quarter turns, moved back to the origin.
1493
+ function turned(cells: number[][], turns: number) {
1494
+ const rotated = Array.from({ length: turns }).reduce<number[][]>(
1495
+ (list) => list.map(([x, y]) => [-y, x]),
1496
+ cells,
1497
+ )
1498
+ const minX = Math.min(...rotated.map(([x]) => x))
1499
+ const minY = Math.min(...rotated.map(([, y]) => y))
1500
+
1501
+ return rotated.map(([x, y]) => [x - minX, y - minY])
1502
+ }
1503
+
1504
+ function define(definition: Definition): ProjectIconStyle {
1505
+ return {
1506
+ id: definition.id,
1507
+ name: definition.name,
1508
+ label: definition.label,
1509
+ family: definition.family,
1510
+ animated: definition.animated ?? false,
1511
+ generate: (key) => ({
1512
+ style: definition.id,
1513
+ version: 1,
1514
+ params: definition.resolve((tag) => mulberry32(cyrb53(`${key}|${definition.id}|${tag}`))),
1515
+ }),
1516
+ draw: (ctx, px, icon, seconds) => {
1517
+ if ("vector" in definition) {
1518
+ ctx.clearRect(0, 0, px, px)
1519
+ definition.vector(ctx, px, icon.params, seconds)
1520
+ clip(ctx, px)
1521
+
1522
+ return
1523
+ }
1524
+
1525
+ const pixels = new Pixels(icon.params.grid)
1526
+ definition.paint(pixels, icon.params, seconds)
1527
+ blit(ctx, px, pixels)
1528
+ },
1529
+ }
1530
+ }
1531
+
1532
+ // Scales the grid up nearest-neighbour, so every cell stays a hard-edged block, and cuts the rounded tile.
1533
+ function blit(ctx: CanvasRenderingContext2D, px: number, pixels: Pixels) {
1534
+ const image = ctx.createImageData(px, px)
1535
+
1536
+ for (let row = 0; row < px; row++) {
1537
+ const y = Math.floor((row * pixels.n) / px)
1538
+
1539
+ for (let column = 0; column < px; column++) {
1540
+ const mask = tileMask((column + 0.5) / px, (row + 0.5) / px, px)
1541
+
1542
+ if (mask <= 0) continue
1543
+ const color = pixels.cells[y * pixels.n + Math.floor((column * pixels.n) / px)]
1544
+ const index = (row * px + column) * 4
1545
+ image.data[index] = (color >> 16) & 255
1546
+ image.data[index + 1] = (color >> 8) & 255
1547
+ image.data[index + 2] = color & 255
1548
+ image.data[index + 3] = mask * 255
1549
+ }
1550
+ }
1551
+
1552
+ ctx.putImageData(image, 0, 0)
1553
+ }
1554
+
1555
+ function clip(ctx: CanvasRenderingContext2D, px: number) {
1556
+ const image = ctx.getImageData(0, 0, px, px)
1557
+
1558
+ for (let row = 0; row < px; row++)
1559
+ for (let column = 0; column < px; column++)
1560
+ image.data[(row * px + column) * 4 + 3] *= tileMask((column + 0.5) / px, (row + 0.5) / px, px)
1561
+
1562
+ ctx.putImageData(image, 0, 0)
1563
+ }