Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
anidoodle 0.1.0 — draw, animate and illustrate entirely in code
Alex Greenshpun226abd66f1ee
diff --git a/.gitignore b/.gitignorenew file mode 100644index 0000000..bc7d14d--- /dev/null+++ b/.gitignore@@ -0,0 +1,17 @@+# build + render output+engine/node_modules/+engine/out/+engine/dist/+engine/.tmp/+**/*.log+.DS_Store++# local scratch (internal, never ship)+_readme-preview.html+_*.png+.style-gallery-brief.md+.banner-brief.md++# work in progress, lands in a later release+engine/src/canvas-core/banner.ts+engine/src/hosts/page-banner.tsdiff --git a/LICENSE b/LICENSEnew file mode 100644index 0000000..9fb19f7--- /dev/null+++ b/LICENSE@@ -0,0 +1,204 @@+Copyright 2026 Alex Greenshpun+++ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONS++ APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++ Copyright [yyyy] [name of copyright owner]++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.diff --git a/NOTICE b/NOTICEnew file mode 100644index 0000000..d744f1c--- /dev/null+++ b/NOTICE@@ -0,0 +1,5 @@+anidoodle+Copyright 2026 Alex Greenshpun++This product includes software developed as an original work,+licensed under the Apache License, Version 2.0.diff --git a/README.md b/README.mdnew file mode 100644index 0000000..1471ca1--- /dev/null+++ b/README.md@@ -0,0 +1,80 @@+# anidoodle++**A film, drawn entirely in code. Every pixel is painted by a function, every note is synthesized, and the same seed draws the same picture forever.**++<p align="center">+ <img src="assets/alive.gif" width="480" alt="A clockwork butterfly comes to life in watercolour and flits between ranunculus"><br>+ <em>This clockwork butterfly was written, not filmed. It drafts itself as a blueprint, wakes in watercolour, and flies off leaving the plate in the grass.</em>+</p>++<p align="center"><strong>▶ <a href="assets/mechanical-lepidoptera.mp4">Watch the full 47-second film</a></strong> · 1080×1080, with an original score, every frame and sample generated in code</p>++## The idea++anidoodle hands you the source of a picture: a small program that draws it. Change a seed and you get a sister image. Nudge a number and the wing lifts higher. Commit it and your art lives in git, beside your code, rebuilding identically on any machine, at any size, this year and next.++One pure function paints each frame. A single call is a finished illustration. A run of them is a film. The same guarantees hold for both.++## What it packs++The engine is the easy half. The craft is the part anidoodle carries for you, five lessons, each one earned by getting a film wrong first and written down so you start where the last project ended:++- **Story** decides everything. One transformation, one payoff, one visual token that returns, so a film has a spine and the medium shifts only when the story changes state. → [`references/storytelling.md`](references/storytelling.md)+- **Realism** comes from naming it. The anatomy, the view, and the reference you opened, so a butterfly reads as a creature with a body and veins. → [`references/realism-and-craft.md`](references/realism-and-craft.md)+- **Music** follows a recipe. Major key, plucked, a phrase that asks a question and resolves home, warm and sure. → [`references/music-recipe.md`](references/music-recipe.md)+- **Determinism** is the guarantee. Pure functions and a seeded random, so anyone who has the source rebuilds the exact same film, forever. → [`references/determinism-and-contract.md`](references/determinism-and-contract.md)+- **Method** keeps you fast. Prove the look on one still, then build straight through to the end, and spend approval where being wrong is expensive. → [`references/working-method.md`](references/working-method.md)++## It draws stills too++A single call is a complete illustration. Render your landing-page hero at full size, a thumbnail, and a social card from the one source, on brand, at any resolution you ask for.++<p align="center">+ <img src="assets/act1.gif" width="460" alt="A cyanotype blueprint plate drawing itself, line by line"><br>+ <em>The marks are <strong>made</strong>, in the order a hand would make them.</em>+</p>++**Reach for it when you want:** website and product art, hero images and empty states that stay on brand at every size; editorial diagrams and cutaways that move to show how a thing works; title sequences, animated logos, and brand stories that render the same in every pipeline; storyboards and animatics, sketched fast and grown into the finished film; and generative series, where one program yields a whole family of images from different seeds.++## Many styles, one engine++<p align="center">+ <img src="assets/styles.png" width="900" alt="Eight subjects, each drawn in a different illustration style, all in code"><br>+ <em>Eight subjects, eight hands. Pick the style your art wants, and the engine draws it.</em>+</p>++Every style is its own way of making a mark: the taper of a nib, the bleed of a wash, the scumble of chalk on slate, the torn edge of cut paper, the halftone of a risograph drum. One engine drives them all, so eight looks read as eight different artists, and reaching a ninth is a page of code.++## Pay once, draw forever++A picture model spends tokens and compute on every frame of every render, and it never draws the same thing twice. Code spends them once. The 47-second film is a single program: written one time, it renders all 1,410 frames and a full stereo score, at any size, on any machine, free every time it runs. That is about sixty tokens of code per frame on the first pass, and zero on every pass after. A single still is a few hundred lines. A whole family of images is just new seeds.++## Try it++```bash+node engine/tools/scaffold.mjs ~/my-film --film myFilm # a new project with a starter film+cd ~/my-film && npm install++node tools/still.mjs myFilm --out out/look.png # a single finished illustration+node tools/emit.mjs myFilm --out out/my-film.html # a self-contained player, one file+node tools/gate.mjs myFilm --mp4 out/my-film.mp4 # determinism, contract and dead-air in one pass+node tools/render.mjs myFilm # the MP4+```++`emit` writes one HTML file, around 100 KB, that plays the whole film with sound on a double-click, offline. It carries the recipe and draws the whole thing again from scratch every time you open it. Attach it to an email and you have shipped a studio.++Four backends share one art core, and the core stays blissfully unaware of which is drawing it: `playwright`, `html-player`, `remotion`, `hyperframes`.++## The example film++`example/` holds **Mechanical Lepidoptera**: 1,410 frames, 47 seconds, a clockwork butterfly that drafts itself, comes alive in watercolour, and leaves its blueprint in the grass. It is the whole engine in one piece: control points placed by hand over real anatomy, a cache key that names every input a pixel depends on, a score built from the recipe, and one unbroken move from built to alive. Open it, change a number, and watch what moves.++## Honest by design++Sound and motion earn their claims. Every statement about the score or the movement carries a measurement or a human's eye behind it, and a green checkmark counts once it has been re-run. That discipline is why the same film comes back byte for byte, every time, on every machine.++---++Licensed under the [Apache License 2.0](LICENSE). Copyright 2026 Alex Greenshpun.++<sub>Built with anidoodle, which learned everything it knows by drawing the butterfly a few honest times.</sub>diff --git a/SKILL.md b/SKILL.mdnew file mode 100644index 0000000..434dbf9--- /dev/null+++ b/SKILL.md@@ -0,0 +1,125 @@+---+name: anidoodle+description: Draw, animate and illustrate entirely in code, no image or audio assets, deterministic on any backend. Use for a code-drawn film or animation, an illustration or still, a storyboard, or sketching a visual idea.+metadata:+ created_by: Alex Greenshpun (10x Company)+ license: Apache-2.0+---++# anidoodle++A 30 to 90 second film where one pure function `renderFrame(film, ctx, frame, env)` draws every+frame and a second pure function writes every audio sample. One generated HTML page IS the film;+adapters turn it into an MP4. Nothing downloaded, nothing sampled, nothing random, so anyone can+rebuild it bit for bit from source.++That is the easy half. The films that get thrown away are never thrown away for engineering+reasons. They are thrown away because they had no story, because the subject did not look real,+because the music sounded like a ghost crying, and because the client's patience was spent+approving stills of a film that did not yet exist.++## The seven laws++1. **Story is the spine.** One transformation, one payoff, one visual token that returns. Style is+ how you say it, never the point. → `references/storytelling.md`+2. **State the realism.** "A butterfly" gets you the road-sign icon of a butterfly. Name the+ anatomy, the view, and the reference you opened. → `references/realism-and-craft.md`+3. **Music gets a recipe, never an adjective.** Major key, plucked, I-IV-V-I, no pads, no drones,+ no long reverb. You cannot hear your output, so you do not improvise. → `references/music-recipe.md`+4. **Prove the look on ONE still, then build end to end.** One still buys the look. After that,+ gates cost more than they save. → `references/working-method.md`+5. **The contract is absolute.** Pure in `(frame, env)`, `rng(seed)` only, no clock, no+ `ctx.filter`, no assets. → `references/determinism-and-contract.md`+6. **One directs, one builds, both write everything down.** When a session degrades, reset it; the+ files are the memory. → `references/working-method.md`+7. **Texture is geometry and seeded tiles.** Anything a filter would have done, you do with noise+ you made yourself. → `references/realism-and-craft.md`++## Workflow++1. **Write the story in three sentences** (setup, transformation, payoff) and name the token. If+ you cannot, stop. Do not open an editor.+2. **Put it on the grid.** 120 bpm at 30 fps is a 15-frame beat. Cuts on multiples of 15, events on+ multiples of 5. ONE cue table per film holds every frame number, and a checker runs at load.+3. **Open real reference** for anything that exists in the world, and write down which images.+4. **ONE look still** — the hardest frame: hero subject, large, in its world, in the final medium+ and light. Critique it yourself in writing first. ✋ **Approval gate.**+5. **ONE 8-second music sample** from the recipe. ✋ **Approval gate.** The client listens; you can't.+6. **Build the whole film.** No per-shot approvals. Mechanical checks run continuously and need+ nobody: types, grid, contract scan, draw budget, determinism, dead air.+7. **Review the whole film once**, from the rendered file: contact sheet at one tile per beat, each+ cut as a before/after pair, the dead-air numbers. One ranked fix list. One rebuild.+8. **Verify and deliver.** ✋ **Final approval.** Say what you verified and what you cannot — you+ cannot hear it and you cannot watch it move.++Three approval gates. Not thirty. Approval is a budget; spend it where being wrong is expensive.++## The craft bar++The test: would a proud human illustrator ship this, or is it mechanical shape-assembly?++| The tell | What passes |+|---|---|+| A row of style vignettes | One arc. The medium changes only when the STORY changes state |+| Things fade or scale in | Marks are MADE, in the order a hand makes them |+| Both sides do the same thing at once | One side leads, by a few frames, never half a cycle |+| Every stroke the same weight and speed | Long strokes fast, fiddly ones slow, thick-thin, tapered |+| Flat colour fields | Wash, then pattern wet-on-damp, then line; one named light; cast shadows |+| A subject built from ellipses and capsules | Hand-placed control points over real anatomy |+| Even scatter, one flower stamped 200 times | Hand-placed drifts with bare rests; 4-5 authored views per species |+| Gradient sky, disc sun, oval bokeh | Granulating wash, sun as paper left light, lost edges |+| Decoration | Every element has a one-line reason or it is not drawn |+| A hold | The camera may creep. The subject never stops |++**No dead air**: something visibly moves in every second, from frame 0. Check it with the tool AND+by eye — a creeping camera changes every pixel and satisfies the tool while the eye sees a still.++## The engine++`engine/` is the portable art core plus the tooling. Nothing in `engine/src/canvas-core` knows+about React, Remotion, the DOM, or any backend — that separation is verified, not asserted.++```bash+node <skill>/engine/tools/scaffold.mjs ~/my-film --film myFilm # new project, starter film+cd ~/my-film && npm install+node tools/still.mjs myFilm --out out/look.png # step 4: the ONE look still+node tools/gate.mjs myFilm --mp4 out/my-film.mp4 # determinism + contract + dead air+node tools/emit.mjs myFilm --out out/my-film.html # the self-contained player+node tools/render.mjs myFilm # the MP4+```++| Tool | What it does |+|---|---|+| `scaffold.mjs` | engine + (optionally) the example into one working project |+| `still.mjs` | one frame, full size, with its hash so a re-render can be proved identical |+| `gate.mjs` | the three bars: determinism, contract, dead air. Any adapter |+| `emit.mjs` | one self-contained offline HTML file, then verifies the file it just wrote |+| `render.mjs` / `snap.mjs` | MP4; contact sheets |+| `deadair.mjs` | per-frame changed-pixel fraction |+| `verify-frame-adapter.mjs` | holds a page-side seek adapter to its contract |++Four backends, one art core: `playwright`, `html-player`, `remotion`, `hyperframes`. Each is+roughly 100 lines and none is visible from the core. → `references/backends-and-adapters.md`++## The worked example++`example/` is MECHANICAL LEPIDOPTERA: 1410 frames, 47 s, a clockwork butterfly that is drawn,+comes alive, and leaves its blueprint in the grass. Its full spec is `example/butterfly-film-spec.md`.++**Study it. Do not copy it.** It is there so you can see what "hand-placed control points over real+anatomy" actually looks like in code — `example/src/canvas-core/butterfly/alive/anatomy.ts` builds+a discal cell and veins that fork and never cross; `butterfly/surface.ts` beside it shows a cache+key that names everything its pixels depend on. Copying it gets you somebody else's film with your title on it, and the craft bar+above is not satisfied by inheritance.++```bash+node <skill>/engine/tools/scaffold.mjs ~/study --example+```++## Honest limits++You cannot hear the score and you cannot watch the film move. Every claim about either must come+from a measurement or from a human. Say which. A green checkmark is a claim, not evidence, until+you re-run it — on this film the dead-air gate passed while a second of near-stillness sat in the+cut, and a cache key that was wrong in one frame order survived every eye that read the code. The+machine found that one; no human was ever going to.diff --git a/assets/act1.gif b/assets/act1.gifnew file mode 100644index 0000000..87c7fafBinary files /dev/null and b/assets/act1.gif differdiff --git a/assets/alive.gif b/assets/alive.gifnew file mode 100644index 0000000..3628e7cBinary files /dev/null and b/assets/alive.gif differdiff --git a/assets/mechanical-lepidoptera.mp4 b/assets/mechanical-lepidoptera.mp4new file mode 100644index 0000000..602da49Binary files /dev/null and b/assets/mechanical-lepidoptera.mp4 differdiff --git a/assets/mellan-spiral.png b/assets/mellan-spiral.pngnew file mode 100644index 0000000..336fe5eBinary files /dev/null and b/assets/mellan-spiral.png differdiff --git a/assets/styles.png b/assets/styles.pngnew file mode 100644index 0000000..9c9c287Binary files /dev/null and b/assets/styles.png differdiff --git a/engine/package-lock.json b/engine/package-lock.jsonnew file mode 100644index 0000000..69ddb2d--- /dev/null+++ b/engine/package-lock.json@@ -0,0 +1,3303 @@+{+ "name": "anidoodle-engine",+ "version": "1.0.0",+ "lockfileVersion": 3,+ "requires": true,+ "packages": {+ "": {+ "name": "anidoodle-engine",+ "version": "1.0.0",+ "dependencies": {+ "esbuild": "^0.25.0"+ },+ "devDependencies": {+ "playwright-core": "^1.48.0",+ "typescript": "^5.9.0"+ },+ "optionalDependencies": {+ "@remotion/bundler": "4.0.522",+ "@remotion/renderer": "4.0.522",+ "react": "^19.0.0",+ "remotion": "4.0.522"+ }+ },+ "node_modules/@babel/helper-string-parser": {+ "version": "7.29.7",+ "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",+ "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6.9.0"+ }+ },+ "node_modules/@babel/helper-validator-identifier": {+ "version": "7.29.7",+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",+ "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6.9.0"+ }+ },+ "node_modules/@babel/parser": {+ "version": "7.24.1",+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.1.tgz",+ "integrity": "sha512-Zo9c7N3xdOIQrNip7Lc9wvRPzlRtovHVE4lkz8WEDr7uYh/GMQhSiIgFxGIArRHYdJE5kxtZjAf8rT0xhdLCzg==",+ "license": "MIT",+ "optional": true,+ "bin": {+ "parser": "bin/babel-parser.js"+ },+ "engines": {+ "node": ">=6.0.0"+ }+ },+ "node_modules/@babel/types": {+ "version": "7.24.0",+ "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.0.tgz",+ "integrity": "sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@babel/helper-string-parser": "^7.23.4",+ "@babel/helper-validator-identifier": "^7.22.20",+ "to-fast-properties": "^2.0.0"+ },+ "engines": {+ "node": ">=6.9.0"+ }+ },+ "node_modules/@emnapi/core": {+ "version": "1.11.3",+ "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz",+ "integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@emnapi/wasi-threads": "1.2.3",+ "tslib": "^2.4.0"+ }+ },+ "node_modules/@emnapi/runtime": {+ "version": "1.11.3",+ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",+ "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "tslib": "^2.4.0"+ }+ },+ "node_modules/@emnapi/wasi-threads": {+ "version": "1.2.3",+ "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz",+ "integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "tslib": "^2.4.0"+ }+ },+ "node_modules/@esbuild/aix-ppc64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz",+ "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==",+ "cpu": [+ "ppc64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "aix"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/android-arm": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz",+ "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/android-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz",+ "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/android-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz",+ "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/darwin-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz",+ "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/darwin-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz",+ "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/freebsd-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz",+ "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "freebsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/freebsd-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz",+ "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "freebsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-arm": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz",+ "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz",+ "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-ia32": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz",+ "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==",+ "cpu": [+ "ia32"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-loong64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz",+ "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==",+ "cpu": [+ "loong64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-mips64el": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz",+ "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==",+ "cpu": [+ "mips64el"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-ppc64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz",+ "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==",+ "cpu": [+ "ppc64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-riscv64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz",+ "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==",+ "cpu": [+ "riscv64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-s390x": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz",+ "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==",+ "cpu": [+ "s390x"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/linux-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz",+ "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/netbsd-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz",+ "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "netbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/netbsd-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz",+ "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "netbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/openbsd-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz",+ "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/openbsd-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz",+ "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/openharmony-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz",+ "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openharmony"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/sunos-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz",+ "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "sunos"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/win32-arm64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz",+ "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/win32-ia32": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz",+ "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==",+ "cpu": [+ "ia32"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@esbuild/win32-x64": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz",+ "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@jridgewell/gen-mapping": {+ "version": "0.3.13",+ "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",+ "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@jridgewell/sourcemap-codec": "^1.5.0",+ "@jridgewell/trace-mapping": "^0.3.24"+ }+ },+ "node_modules/@jridgewell/resolve-uri": {+ "version": "3.1.2",+ "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",+ "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6.0.0"+ }+ },+ "node_modules/@jridgewell/source-map": {+ "version": "0.3.11",+ "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.11.tgz",+ "integrity": "sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@jridgewell/gen-mapping": "^0.3.5",+ "@jridgewell/trace-mapping": "^0.3.25"+ }+ },+ "node_modules/@jridgewell/sourcemap-codec": {+ "version": "1.6.0",+ "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz",+ "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@jridgewell/trace-mapping": {+ "version": "0.3.31",+ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",+ "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@jridgewell/resolve-uri": "^3.1.0",+ "@jridgewell/sourcemap-codec": "^1.4.14"+ }+ },+ "node_modules/@mediabunny/aac-encoder": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/@mediabunny/aac-encoder/-/aac-encoder-1.55.5.tgz",+ "integrity": "sha512-u5x296ofN0Gf3tNW9zmFDYxejUFeibiTytbc2qBKilOHpf+RWAeyO7byDgwj48WweVOVC5x9dGSpnkJNnUK5mg==",+ "license": "MPL-2.0",+ "optional": true,+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ },+ "peerDependencies": {+ "mediabunny": "^1.0.0"+ }+ },+ "node_modules/@mediabunny/flac-encoder": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/@mediabunny/flac-encoder/-/flac-encoder-1.55.5.tgz",+ "integrity": "sha512-vGtetM8SwjTweqWmQ+zER49aWKw3bzuGv1t/AEdS5N9SiHntiwoiBFOSzm18b+7Zah6I/vHLF9DRaHB85jqrMg==",+ "license": "MPL-2.0",+ "optional": true,+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ },+ "peerDependencies": {+ "mediabunny": "^1.0.0"+ }+ },+ "node_modules/@mediabunny/mp3-encoder": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/@mediabunny/mp3-encoder/-/mp3-encoder-1.55.5.tgz",+ "integrity": "sha512-WNdWY40KXy6P23iXboIJ8IuLaUsukEF3m+kQ4jCXnDwHTOlyRd+hyq4trTDq7g9kVwB+rpj5ZSzsBq8LKsRYwQ==",+ "license": "MPL-2.0",+ "optional": true,+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ },+ "peerDependencies": {+ "mediabunny": "^1.0.0"+ }+ },+ "node_modules/@module-federation/error-codes": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/error-codes/-/error-codes-0.22.0.tgz",+ "integrity": "sha512-xF9SjnEy7vTdx+xekjPCV5cIHOGCkdn3pIxo9vU7gEZMIw0SvAEdsy6Uh17xaCpm8V0FWvR0SZoK9Ik6jGOaug==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@module-federation/runtime": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/runtime/-/runtime-0.22.0.tgz",+ "integrity": "sha512-38g5iPju2tPC3KHMPxRKmy4k4onNp6ypFPS1eKGsNLUkXgHsPMBFqAjDw96iEcjri91BrahG4XcdyKi97xZzlA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@module-federation/error-codes": "0.22.0",+ "@module-federation/runtime-core": "0.22.0",+ "@module-federation/sdk": "0.22.0"+ }+ },+ "node_modules/@module-federation/runtime-core": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/runtime-core/-/runtime-core-0.22.0.tgz",+ "integrity": "sha512-GR1TcD6/s7zqItfhC87zAp30PqzvceoeDGYTgF3Vx2TXvsfDrhP6Qw9T4vudDQL3uJRne6t7CzdT29YyVxlgIA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@module-federation/error-codes": "0.22.0",+ "@module-federation/sdk": "0.22.0"+ }+ },+ "node_modules/@module-federation/runtime-tools": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/runtime-tools/-/runtime-tools-0.22.0.tgz",+ "integrity": "sha512-4ScUJ/aUfEernb+4PbLdhM/c60VHl698Gn1gY21m9vyC1Ucn69fPCA1y2EwcCB7IItseRMoNhdcWQnzt/OPCNA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@module-federation/runtime": "0.22.0",+ "@module-federation/webpack-bundler-runtime": "0.22.0"+ }+ },+ "node_modules/@module-federation/sdk": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/sdk/-/sdk-0.22.0.tgz",+ "integrity": "sha512-x4aFNBKn2KVQRuNVC5A7SnrSCSqyfIWmm1DvubjbO9iKFe7ith5niw8dqSFBekYBg2Fwy+eMg4sEFNVvCAdo6g==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@module-federation/webpack-bundler-runtime": {+ "version": "0.22.0",+ "resolved": "https://registry.npmjs.org/@module-federation/webpack-bundler-runtime/-/webpack-bundler-runtime-0.22.0.tgz",+ "integrity": "sha512-aM8gCqXu+/4wBmJtVeMeeMN5guw3chf+2i6HajKtQv7SJfxV/f4IyNQJUeUQu9HfiAZHjqtMV5Lvq/Lvh8LdyA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@module-federation/runtime": "0.22.0",+ "@module-federation/sdk": "0.22.0"+ }+ },+ "node_modules/@napi-rs/wasm-runtime": {+ "version": "1.0.7",+ "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.0.7.tgz",+ "integrity": "sha512-SeDnOO0Tk7Okiq6DbXmmBODgOAb9dp9gjlphokTUxmt8U3liIP1ZsozBahH69j/RJv+Rfs6IwUKHTgQYJ/HBAw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@emnapi/core": "^1.5.0",+ "@emnapi/runtime": "^1.5.0",+ "@tybys/wasm-util": "^0.10.1"+ }+ },+ "node_modules/@remotion/bundler": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/bundler/-/bundler-4.0.522.tgz",+ "integrity": "sha512-eHyDmC7lj9hemVIpmzIz8WFI3bBx4b2sOZmWu9qzgRyywRP0WCeWqH9agCINdgWKcxOJ3SqhQn6MiZZHuuUMFw==",+ "license": "SEE LICENSE IN LICENSE.md",+ "optional": true,+ "dependencies": {+ "@remotion/media-parser": "4.0.522",+ "@remotion/studio": "4.0.522",+ "@remotion/studio-shared": "4.0.522",+ "@remotion/timeline-utils": "4.0.522",+ "@rspack/core": "1.7.11",+ "@rspack/plugin-react-refresh": "1.6.1",+ "css-loader": "7.1.4",+ "esbuild": "0.28.1",+ "react-refresh": "0.18.0",+ "remotion": "4.0.522",+ "style-loader": "4.0.0",+ "webpack": "5.105.0"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/aix-ppc64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz",+ "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==",+ "cpu": [+ "ppc64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "aix"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/android-arm": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz",+ "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/android-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz",+ "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/android-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz",+ "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "android"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/darwin-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz",+ "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/darwin-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz",+ "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/freebsd-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz",+ "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "freebsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/freebsd-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz",+ "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "freebsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-arm": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz",+ "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==",+ "cpu": [+ "arm"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz",+ "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-ia32": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz",+ "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==",+ "cpu": [+ "ia32"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-loong64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz",+ "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==",+ "cpu": [+ "loong64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-mips64el": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz",+ "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==",+ "cpu": [+ "mips64el"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-ppc64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz",+ "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==",+ "cpu": [+ "ppc64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-riscv64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz",+ "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==",+ "cpu": [+ "riscv64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-s390x": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz",+ "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==",+ "cpu": [+ "s390x"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/linux-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz",+ "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/netbsd-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz",+ "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "netbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/netbsd-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz",+ "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "netbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/openbsd-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz",+ "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/openbsd-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz",+ "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openbsd"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/openharmony-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz",+ "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "openharmony"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/sunos-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz",+ "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "sunos"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/win32-arm64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz",+ "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/win32-ia32": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz",+ "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==",+ "cpu": [+ "ia32"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/@esbuild/win32-x64": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz",+ "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@remotion/bundler/node_modules/esbuild": {+ "version": "0.28.1",+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz",+ "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==",+ "hasInstallScript": true,+ "license": "MIT",+ "optional": true,+ "bin": {+ "esbuild": "bin/esbuild"+ },+ "engines": {+ "node": ">=18"+ },+ "optionalDependencies": {+ "@esbuild/aix-ppc64": "0.28.1",+ "@esbuild/android-arm": "0.28.1",+ "@esbuild/android-arm64": "0.28.1",+ "@esbuild/android-x64": "0.28.1",+ "@esbuild/darwin-arm64": "0.28.1",+ "@esbuild/darwin-x64": "0.28.1",+ "@esbuild/freebsd-arm64": "0.28.1",+ "@esbuild/freebsd-x64": "0.28.1",+ "@esbuild/linux-arm": "0.28.1",+ "@esbuild/linux-arm64": "0.28.1",+ "@esbuild/linux-ia32": "0.28.1",+ "@esbuild/linux-loong64": "0.28.1",+ "@esbuild/linux-mips64el": "0.28.1",+ "@esbuild/linux-ppc64": "0.28.1",+ "@esbuild/linux-riscv64": "0.28.1",+ "@esbuild/linux-s390x": "0.28.1",+ "@esbuild/linux-x64": "0.28.1",+ "@esbuild/netbsd-arm64": "0.28.1",+ "@esbuild/netbsd-x64": "0.28.1",+ "@esbuild/openbsd-arm64": "0.28.1",+ "@esbuild/openbsd-x64": "0.28.1",+ "@esbuild/openharmony-arm64": "0.28.1",+ "@esbuild/sunos-x64": "0.28.1",+ "@esbuild/win32-arm64": "0.28.1",+ "@esbuild/win32-ia32": "0.28.1",+ "@esbuild/win32-x64": "0.28.1"+ }+ },+ "node_modules/@remotion/canvas": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/canvas/-/canvas-4.0.522.tgz",+ "integrity": "sha512-+gvm3FXviqHHtr+IuSPuWVRgTltwq6/pMnUWrxZzQ7Lj8h6n2KdrGfFj1/2dGniuulZZTu+4NJptQkEmrrqLUA==",+ "license": "Remotion License",+ "optional": true,+ "dependencies": {+ "@remotion/player": "4.0.522",+ "remotion": "4.0.522"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/captions": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/captions/-/captions-4.0.522.tgz",+ "integrity": "sha512-z9mUXHQBFuXRdqAuXudzyWb02De+K5MNZQ2ztLksLVBKlNhs7LQMv/Wo9SDAda4Mq6iIUXjwd6fcl0X4aRGRKQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@remotion/compositor-darwin-arm64": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-darwin-arm64/-/compositor-darwin-arm64-4.0.522.tgz",+ "integrity": "sha512-Otzfsfo4T5msyAiIn4aIB4NNITCuds6B4CVNBwYMBWAWbwoWarmqHUPaG/m+Exolcglbvc/wX3C3XMaYCSx6KQ==",+ "cpu": [+ "arm64"+ ],+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@remotion/compositor-darwin-x64": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-darwin-x64/-/compositor-darwin-x64-4.0.522.tgz",+ "integrity": "sha512-7MvQylPSY9qWkhSy3CT5rWo+jnGy3ieTMe79lRv/BMG0zvX6xJObki3cDVZNaiS3g1BUk2fqScb3C12A/EROgQ==",+ "cpu": [+ "x64"+ ],+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@remotion/compositor-linux-arm64-gnu": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-linux-arm64-gnu/-/compositor-linux-arm64-gnu-4.0.522.tgz",+ "integrity": "sha512-3KuzK/cgYKXhqFpOaQOACw7dWlfxJ5BONnhvMIAGrgDc8ng1suEuwFFKEB47dQV1/f4aPcXKRr+IRten9cmkWQ==",+ "cpu": [+ "arm64"+ ],+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@remotion/compositor-linux-arm64-musl": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-linux-arm64-musl/-/compositor-linux-arm64-musl-4.0.522.tgz",+ "integrity": "sha512-myt2a/Z94GNl7/cr+12DMxflvzxWjLcAQ4AUH8JebM7EAmtF+y4Bb54tPZKXTt2Pz868QOZTyHi6iD8bZRhd9g==",+ "cpu": [+ "arm64"+ ],+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@remotion/compositor-linux-x64-gnu": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-linux-x64-gnu/-/compositor-linux-x64-gnu-4.0.522.tgz",+ "integrity": "sha512-ie5AbHIpQQiDvrZ7HQHQTiaeil4eFlugpPFjMOmodbTwLym2822f9jfaov5MGVMTw2VXe+Fiq5Jk9kL84IvPfQ==",+ "cpu": [+ "x64"+ ],+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@remotion/compositor-linux-x64-musl": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-linux-x64-musl/-/compositor-linux-x64-musl-4.0.522.tgz",+ "integrity": "sha512-G/VX1hC83cHEA7JK6j7Jq+DCjNGEKP8WRTrpCUvW7XZ3Fn69heGnjUkEPSclhhSA5MaRvihejZJdgDDFVgrKjg==",+ "cpu": [+ "x64"+ ],+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@remotion/compositor-win32-x64-msvc": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/compositor-win32-x64-msvc/-/compositor-win32-x64-msvc-4.0.522.tgz",+ "integrity": "sha512-h50JjMkE6wJQlBYcvF0+sMiLiTqE5aRHhKkNhRemFpRMH1JwWxBvcgwFkOsb1lA2Wyy6EUzfL1QbJknczdfQIA==",+ "cpu": [+ "x64"+ ],+ "optional": true,+ "os": [+ "win32"+ ]+ },+ "node_modules/@remotion/licensing": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/licensing/-/licensing-4.0.522.tgz",+ "integrity": "sha512-RSu7Pze1omLFHBTdAzvIB7PBoNHJZBcac4yRDtSsF0tRmaSpf1E7qZlVZmj+M+BnzG3ut6eMS9c3wTW3K0izKw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@remotion/media": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/media/-/media-4.0.522.tgz",+ "integrity": "sha512-G9qpjtgz1uuUdHxrZncE/yL4qESUQmPgbVeMXs2n8jJvqLhxB+BCDkom2CCuMZR/Ym+/wlAsqyV+zbGPL8uvEw==",+ "optional": true,+ "dependencies": {+ "mediabunny": "1.55.5",+ "remotion": "4.0.522",+ "zod": "4.5.4"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/media-parser": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/media-parser/-/media-parser-4.0.522.tgz",+ "integrity": "sha512-NU3XDC0gsx7fouGVBkcBtwEx6vB+WMzP2AF1iEosb/qBtv+0NEaAGcZx2xo6ki0XrlMSaZDr+0fzeZ//eSi6yA==",+ "license": "Remotion License https://remotion.dev/license",+ "optional": true+ },+ "node_modules/@remotion/media-utils": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/media-utils/-/media-utils-4.0.522.tgz",+ "integrity": "sha512-wzko6H2xtBwP/x+O2NWaZmGZE+vY+qqfpIe3DI1gJzJjw7DMtGvabmEJD20YUZP8O95KoWWx0W4cCwzywCpJew==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "mediabunny": "1.55.5",+ "remotion": "4.0.522"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/media-utils/node_modules/mediabunny": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.55.5.tgz",+ "integrity": "sha512-m0v6y8FGXiK+HKOc3AZqU+kJPLYsSKaLitmQNQIIHZKIGlTwQ34OF+X6Ul0K8iV4b03oPse10apwuoqbvmKeAA==",+ "license": "MPL-2.0",+ "optional": true,+ "workspaces": [+ ".",+ "packages/*"+ ],+ "dependencies": {+ "@types/dom-mediacapture-transform": "^0.1.11",+ "@types/dom-webcodecs": "0.1.13"+ },+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ }+ },+ "node_modules/@remotion/media/node_modules/mediabunny": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.55.5.tgz",+ "integrity": "sha512-m0v6y8FGXiK+HKOc3AZqU+kJPLYsSKaLitmQNQIIHZKIGlTwQ34OF+X6Ul0K8iV4b03oPse10apwuoqbvmKeAA==",+ "license": "MPL-2.0",+ "optional": true,+ "workspaces": [+ ".",+ "packages/*"+ ],+ "dependencies": {+ "@types/dom-mediacapture-transform": "^0.1.11",+ "@types/dom-webcodecs": "0.1.13"+ },+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ }+ },+ "node_modules/@remotion/player": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/player/-/player-4.0.522.tgz",+ "integrity": "sha512-IAdV0Qu90Orl0fETLY8MVTJBSMo8zHDTvjxo0ghj9sfb+ouk2IDhOZEqzfCOqmBEEmFHgDVMcC8P01hnxaHR/g==",+ "license": "SEE LICENSE IN LICENSE.md",+ "optional": true,+ "dependencies": {+ "remotion": "4.0.522"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/renderer": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/renderer/-/renderer-4.0.522.tgz",+ "integrity": "sha512-Eu6MuGLnt0LNSAxuIzjjBXHXjxr1qRnhRd3RkQUkAqGJxsOYFnEXURv7DnBj7qmS2At4TFnv+Men9sCYTWOP1A==",+ "license": "SEE LICENSE IN LICENSE.md",+ "optional": true,+ "dependencies": {+ "@remotion/licensing": "4.0.522",+ "@remotion/streaming": "4.0.522",+ "execa": "5.1.1",+ "remotion": "4.0.522",+ "source-map": "0.8.0",+ "ws": "8.21.0"+ },+ "optionalDependencies": {+ "@remotion/compositor-darwin-arm64": "4.0.522",+ "@remotion/compositor-darwin-x64": "4.0.522",+ "@remotion/compositor-linux-arm64-gnu": "4.0.522",+ "@remotion/compositor-linux-arm64-musl": "4.0.522",+ "@remotion/compositor-linux-x64-gnu": "4.0.522",+ "@remotion/compositor-linux-x64-musl": "4.0.522",+ "@remotion/compositor-win32-x64-msvc": "4.0.522"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/streaming": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/streaming/-/streaming-4.0.522.tgz",+ "integrity": "sha512-aJIH00LjftHX5tf0wKEKi826+ivIsbE7RqUpHoX8Qp46e+yuh+SyIdTIH5975NV9q9nifAOR5nyBrz9nQa59uw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@remotion/studio": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/studio/-/studio-4.0.522.tgz",+ "integrity": "sha512-49ZEUd5R5o3wwKwjg0WYaEUlqBxuY45LkbEEwKvmbKTJWt1tc5UBSD7077e3Twv/9gsEnoz2FvRcfU4qS5wFcw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@jridgewell/trace-mapping": "0.3.31",+ "@remotion/canvas": "4.0.522",+ "@remotion/captions": "4.0.522",+ "@remotion/media": "4.0.522",+ "@remotion/media-utils": "4.0.522",+ "@remotion/player": "4.0.522",+ "@remotion/renderer": "4.0.522",+ "@remotion/studio-codemods": "4.0.522",+ "@remotion/studio-protocol": "4.0.522",+ "@remotion/studio-shared": "4.0.522",+ "@remotion/timeline-utils": "4.0.522",+ "@remotion/web-renderer": "4.0.522",+ "@remotion/zod-types": "4.0.522",+ "@tanstack/react-virtual": "3.14.9",+ "mediabunny": "1.55.5",+ "memfs": "3.4.3",+ "open": "8.4.2",+ "remotion": "4.0.522",+ "semver": "7.5.3",+ "zod": "4.5.4"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@remotion/studio-codemods": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/studio-codemods/-/studio-codemods-4.0.522.tgz",+ "integrity": "sha512-e2lbBANu73SQEuEiy0MNmsjoMRUrAt4lUfAKaaYi0Zd1Ygvx/KIfhghPutBg6IRYjH12ORljuZdY0amZaO/xEg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@babel/parser": "7.24.1",+ "@babel/types": "7.24.0",+ "@remotion/studio-shared": "4.0.522",+ "ast-types": "0.16.1",+ "recast": "0.23.21",+ "remotion": "4.0.522"+ }+ },+ "node_modules/@remotion/studio-protocol": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/studio-protocol/-/studio-protocol-4.0.522.tgz",+ "integrity": "sha512-OFmFI5f2J1IiIXKdD6WKz1Gj0wqZkt8b5FhkQsEkoFVXEvH3dmQLLPuYPde3bVbvORS3MVUAS0RuofXRraUybw==",+ "license": "Remotion License",+ "optional": true,+ "dependencies": {+ "zod": "4.5.4"+ }+ },+ "node_modules/@remotion/studio-shared": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/studio-shared/-/studio-shared-4.0.522.tgz",+ "integrity": "sha512-TUVB8bMaCDIel7YFlLFc9nxFgfocW/gGh0/Bvj6ioFGI4qXitmcT3qaAMwCuC/jL4eLXIV7DjpIQ/rVDjCVWDA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "remotion": "4.0.522"+ }+ },+ "node_modules/@remotion/studio/node_modules/mediabunny": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.55.5.tgz",+ "integrity": "sha512-m0v6y8FGXiK+HKOc3AZqU+kJPLYsSKaLitmQNQIIHZKIGlTwQ34OF+X6Ul0K8iV4b03oPse10apwuoqbvmKeAA==",+ "license": "MPL-2.0",+ "optional": true,+ "workspaces": [+ ".",+ "packages/*"+ ],+ "dependencies": {+ "@types/dom-mediacapture-transform": "^0.1.11",+ "@types/dom-webcodecs": "0.1.13"+ },+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ }+ },+ "node_modules/@remotion/timeline-utils": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/timeline-utils/-/timeline-utils-4.0.522.tgz",+ "integrity": "sha512-nG9MayoC2+5bADdOxp7bhcZi9ALnhcGW3UTYnIHtrc3opKOqxt1mzd8A+glNYjcv5xskFdGcGm5qtSHD3ZsdWw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "mediabunny": "1.55.5",+ "remotion": "4.0.522"+ }+ },+ "node_modules/@remotion/timeline-utils/node_modules/mediabunny": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.55.5.tgz",+ "integrity": "sha512-m0v6y8FGXiK+HKOc3AZqU+kJPLYsSKaLitmQNQIIHZKIGlTwQ34OF+X6Ul0K8iV4b03oPse10apwuoqbvmKeAA==",+ "license": "MPL-2.0",+ "optional": true,+ "workspaces": [+ ".",+ "packages/*"+ ],+ "dependencies": {+ "@types/dom-mediacapture-transform": "^0.1.11",+ "@types/dom-webcodecs": "0.1.13"+ },+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ }+ },+ "node_modules/@remotion/web-renderer": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/web-renderer/-/web-renderer-4.0.522.tgz",+ "integrity": "sha512-fOy0fhXbxXLGO+GT124D4o9GlY+2AhNvk56mmXj8Cax2DPjk35JphaMeKEwZZfVjQulLD79ssN5RAz6OpaCjaw==",+ "license": "SEE LICENSE IN LICENSE.md",+ "optional": true,+ "dependencies": {+ "@mediabunny/aac-encoder": "1.55.5",+ "@mediabunny/flac-encoder": "1.55.5",+ "@mediabunny/mp3-encoder": "1.55.5",+ "@remotion/licensing": "4.0.522",+ "mediabunny": "1.55.5",+ "remotion": "4.0.522"+ },+ "peerDependencies": {+ "react": ">=18.0.0",+ "react-dom": ">=18.0.0"+ }+ },+ "node_modules/@remotion/web-renderer/node_modules/mediabunny": {+ "version": "1.55.5",+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.55.5.tgz",+ "integrity": "sha512-m0v6y8FGXiK+HKOc3AZqU+kJPLYsSKaLitmQNQIIHZKIGlTwQ34OF+X6Ul0K8iV4b03oPse10apwuoqbvmKeAA==",+ "license": "MPL-2.0",+ "optional": true,+ "workspaces": [+ ".",+ "packages/*"+ ],+ "dependencies": {+ "@types/dom-mediacapture-transform": "^0.1.11",+ "@types/dom-webcodecs": "0.1.13"+ },+ "funding": {+ "type": "individual",+ "url": "https://github.com/sponsors/Vanilagy"+ }+ },+ "node_modules/@remotion/zod-types": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/@remotion/zod-types/-/zod-types-4.0.522.tgz",+ "integrity": "sha512-V3YoJgvO724sSszieLO+8ji421JzmzzcCWOdcn95B8l+8/i4hKteKeUM9ey+qbvjt+WAeSOosnhQ3zWOTauvfQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "remotion": "4.0.522"+ }+ },+ "node_modules/@rspack/binding": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-1.7.11.tgz",+ "integrity": "sha512-2MGdy2s2HimsDT444Bp5XnALzNRxuBNc7y0JzyuqKbHBywd4x2NeXyhWXXoxufaCFu5PBc9Qq9jyfjW2Aeh06Q==",+ "license": "MIT",+ "optional": true,+ "optionalDependencies": {+ "@rspack/binding-darwin-arm64": "1.7.11",+ "@rspack/binding-darwin-x64": "1.7.11",+ "@rspack/binding-linux-arm64-gnu": "1.7.11",+ "@rspack/binding-linux-arm64-musl": "1.7.11",+ "@rspack/binding-linux-x64-gnu": "1.7.11",+ "@rspack/binding-linux-x64-musl": "1.7.11",+ "@rspack/binding-wasm32-wasi": "1.7.11",+ "@rspack/binding-win32-arm64-msvc": "1.7.11",+ "@rspack/binding-win32-ia32-msvc": "1.7.11",+ "@rspack/binding-win32-x64-msvc": "1.7.11"+ }+ },+ "node_modules/@rspack/binding-darwin-arm64": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-1.7.11.tgz",+ "integrity": "sha512-oduECiZVqbO5zlVw+q7Vy65sJFth99fWPTyucwvLJJtJkPL5n17Uiql2cYP6Ijn0pkqtf1SXgK8WjiKLG5bIig==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@rspack/binding-darwin-x64": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-1.7.11.tgz",+ "integrity": "sha512-a1+TtTE9ap6RalgFi7FGIgkJP6O4Vy6ctv+9WGJy53E4kuqHR0RygzaiVxCI/GMc/vBT9vY23hyrpWb3d1vtXA==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ]+ },+ "node_modules/@rspack/binding-linux-arm64-gnu": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.7.11.tgz",+ "integrity": "sha512-P0QrGRPbTWu6RKWfN0bDtbnEps3rXH0MWIMreZABoUrVmNQKtXR6e73J3ub6a+di5s2+K0M2LJ9Bh2/H4UsDUA==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@rspack/binding-linux-arm64-musl": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.7.11.tgz",+ "integrity": "sha512-6ky7R43VMjWwmx3Yx7Jl7faLBBMAgMDt+/bN35RgwjiPgsIByz65EwytUVuW9rikB43BGHvA/eqlnjLrUzNBqw==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@rspack/binding-linux-x64-gnu": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.7.11.tgz",+ "integrity": "sha512-cuOJMfCOvb2Wgsry5enXJ3iT1FGUjdPqtGUBVupQlEG4ntSYsQ2PtF4wIDVasR3wdxC5nQbipOrDiN/u6fYsdQ==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@rspack/binding-linux-x64-musl": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-1.7.11.tgz",+ "integrity": "sha512-CoK37hva4AmHGh3VCsQXmGr40L36m1/AdnN5LEjUX6kx5rEH7/1nEBN6Ii72pejqDVvk9anEROmPDiPw10tpFg==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "linux"+ ]+ },+ "node_modules/@rspack/binding-wasm32-wasi": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-1.7.11.tgz",+ "integrity": "sha512-OtrmnPUVJMxjNa3eDMfHyPdtlLRmmp/aIm0fQHlAOATbZvlGm12q7rhPW5BXTu1yh+1rQ1/uqvz+SzKEZXuJaQ==",+ "cpu": [+ "wasm32"+ ],+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@napi-rs/wasm-runtime": "1.0.7"+ }+ },+ "node_modules/@rspack/binding-win32-arm64-msvc": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.7.11.tgz",+ "integrity": "sha512-lObFW6e5lCWNgTBNwT//yiEDbsxm9QG4BYUojqeXxothuzJ/L6ibXz6+gLMvbOvLGV3nKgkXmx8GvT9WDKR0mA==",+ "cpu": [+ "arm64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ]+ },+ "node_modules/@rspack/binding-win32-ia32-msvc": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-1.7.11.tgz",+ "integrity": "sha512-0pYGnZd8PPqNR68zQ8skamqNAXEA1sUfXuAdYcknIIRq2wsbiwFzIc0Pov1cIfHYab37G7sSIPBiOUdOWF5Ivw==",+ "cpu": [+ "ia32"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ]+ },+ "node_modules/@rspack/binding-win32-x64-msvc": {+ "version": "1.7.11",+ "resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.7.11.tgz",+ "integrity": "sha512-EeQXayoQk/uBkI3pdoXfQBXNIUrADq56L3s/DFyM2pJeUDrWmhfIw2UFIGkYPTMSCo8F2JcdcGM32FGJrSnU0Q==",+ "cpu": [+ "x64"+ ],+ "license": "MIT",+ "optional": true,+ "os": [+ "win32"+ ]+ },+ "node_modules/@rspack/lite-tapable": {+ "version": "1.1.0",+ "resolved": "https://registry.npmjs.org/@rspack/lite-tapable/-/lite-tapable-1.1.0.tgz",+ "integrity": "sha512-E2B0JhYFmVAwdDiG14+DW0Di4Ze4Jg10Pc4/lILUrd5DRCaklduz2OvJ5HYQ6G+hd+WTzqQb3QnDNfK4yvAFYw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@rspack/plugin-react-refresh": {+ "version": "1.6.1",+ "resolved": "https://registry.npmjs.org/@rspack/plugin-react-refresh/-/plugin-react-refresh-1.6.1.tgz",+ "integrity": "sha512-eqqW5645VG3CzGzFgNg5HqNdHVXY+567PGjtDhhrM8t67caxmsSzRmT5qfoEIfBcGgFkH9vEg7kzXwmCYQdQDw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "error-stack-parser": "^2.1.4",+ "html-entities": "^2.6.0"+ },+ "peerDependencies": {+ "react-refresh": ">=0.10.0 <1.0.0",+ "webpack-hot-middleware": "2.x"+ },+ "peerDependenciesMeta": {+ "webpack-hot-middleware": {+ "optional": true+ }+ }+ },+ "node_modules/@tanstack/react-virtual": {+ "version": "3.14.9",+ "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.14.9.tgz",+ "integrity": "sha512-qZyr0FZDP8rDC4WBhsryIZmAd9bveJvFGUJJtskWaew6/0dTRS6wZxnR6VQ5bY2KwL3LjerrHqQLk3a0GKcPXQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@tanstack/virtual-core": "3.17.7"+ },+ "funding": {+ "type": "github",+ "url": "https://github.com/sponsors/tannerlinsley"+ },+ "peerDependencies": {+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"+ }+ },+ "node_modules/@tanstack/virtual-core": {+ "version": "3.17.7",+ "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.17.7.tgz",+ "integrity": "sha512-bp+v10y65sp2H7WpWfIMyxTNfl8ZVfxFTLRjPIFRryi6FV/J33z4IS53WO4pTk36KlvJ4iLiQz+oaydDC1xbcA==",+ "license": "MIT",+ "optional": true,+ "funding": {+ "type": "github",+ "url": "https://github.com/sponsors/tannerlinsley"+ }+ },+ "node_modules/@tybys/wasm-util": {+ "version": "0.10.4",+ "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",+ "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "tslib": "^2.4.0"+ }+ },+ "node_modules/@types/dom-mediacapture-transform": {+ "version": "0.1.12",+ "resolved": "https://registry.npmjs.org/@types/dom-mediacapture-transform/-/dom-mediacapture-transform-0.1.12.tgz",+ "integrity": "sha512-d7/QsLRwF864A5mgIM/YrfiglHoYn7zgCcAoJgW404r+2DwnNr7EBbLnCWpmOMgH8y0te73L1AV6H1bmauaWFw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/dom-webcodecs": "*"+ }+ },+ "node_modules/@types/dom-webcodecs": {+ "version": "0.1.13",+ "resolved": "https://registry.npmjs.org/@types/dom-webcodecs/-/dom-webcodecs-0.1.13.tgz",+ "integrity": "sha512-O5hkiFIcjjszPIYyUSyvScyvrBoV3NOEEZx/pMlsu44TKzWNkLVBBxnxJz42in5n3QIolYOcBYFCPZZ0h8SkwQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@types/eslint": {+ "version": "9.6.1",+ "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz",+ "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/estree": "*",+ "@types/json-schema": "*"+ }+ },+ "node_modules/@types/eslint-scope": {+ "version": "3.7.7",+ "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz",+ "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/eslint": "*",+ "@types/estree": "*"+ }+ },+ "node_modules/@types/estree": {+ "version": "1.0.9",+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",+ "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@types/json-schema": {+ "version": "7.0.15",+ "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",+ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@types/node": {+ "version": "26.6.2",+ "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.2.tgz",+ "integrity": "sha512-X1P21scMv4zGKLYqjdGjaKa7COa0RKVYYZZN/NfvLQ1JegxFhdhpZG/Lyn8AXx6CDUavKAd11v6BvfpkDByK8g==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "undici-types": "~8.9.0"+ }+ },+ "node_modules/@webassemblyjs/ast": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.14.1.tgz",+ "integrity": "sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/helper-numbers": "1.13.2",+ "@webassemblyjs/helper-wasm-bytecode": "1.13.2"+ }+ },+ "node_modules/@webassemblyjs/floating-point-hex-parser": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.13.2.tgz",+ "integrity": "sha512-6oXyTOzbKxGH4steLbLNOu71Oj+C8Lg34n6CqRvqfS2O71BxY6ByfMDRhBytzknj9yGUPVJ1qIKhRlAwO1AovA==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@webassemblyjs/helper-api-error": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.13.2.tgz",+ "integrity": "sha512-U56GMYxy4ZQCbDZd6JuvvNV/WFildOjsaWD3Tzzvmw/mas3cXzRJPMjP83JqEsgSbyrmaGjBfDtV7KDXV9UzFQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@webassemblyjs/helper-buffer": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.14.1.tgz",+ "integrity": "sha512-jyH7wtcHiKssDtFPRB+iQdxlDf96m0E39yb0k5uJVhFGleZFoNw1c4aeIcVUPPbXUVJ94wwnMOAqUHyzoEPVMA==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@webassemblyjs/helper-numbers": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.13.2.tgz",+ "integrity": "sha512-FE8aCmS5Q6eQYcV3gI35O4J789wlQA+7JrqTTpJqn5emA4U2hvwJmvFRC0HODS+3Ye6WioDklgd6scJ3+PLnEA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/floating-point-hex-parser": "1.13.2",+ "@webassemblyjs/helper-api-error": "1.13.2",+ "@xtuc/long": "4.2.2"+ }+ },+ "node_modules/@webassemblyjs/helper-wasm-bytecode": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.13.2.tgz",+ "integrity": "sha512-3QbLKy93F0EAIXLh0ogEVR6rOubA9AoZ+WRYhNbFyuB70j3dRdwH9g+qXhLAO0kiYGlg3TxDV+I4rQTr/YNXkA==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@webassemblyjs/helper-wasm-section": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.14.1.tgz",+ "integrity": "sha512-ds5mXEqTJ6oxRoqjhWDU83OgzAYjwsCV8Lo/N+oRsNDmx/ZDpqalmrtgOMkHwxsG0iI//3BwWAErYRHtgn0dZw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@webassemblyjs/helper-buffer": "1.14.1",+ "@webassemblyjs/helper-wasm-bytecode": "1.13.2",+ "@webassemblyjs/wasm-gen": "1.14.1"+ }+ },+ "node_modules/@webassemblyjs/ieee754": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.13.2.tgz",+ "integrity": "sha512-4LtOzh58S/5lX4ITKxnAK2USuNEvpdVV9AlgGQb8rJDHaLeHciwG4zlGr0j/SNWlr7x3vO1lDEsuePvtcDNCkw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@xtuc/ieee754": "^1.2.0"+ }+ },+ "node_modules/@webassemblyjs/leb128": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.13.2.tgz",+ "integrity": "sha512-Lde1oNoIdzVzdkNEAWZ1dZ5orIbff80YPdHx20mrHwHrVNNTjNr8E3xz9BdpcGqRQbAEa+fkrCb+fRFTl/6sQw==",+ "license": "Apache-2.0",+ "optional": true,+ "dependencies": {+ "@xtuc/long": "4.2.2"+ }+ },+ "node_modules/@webassemblyjs/utf8": {+ "version": "1.13.2",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.13.2.tgz",+ "integrity": "sha512-3NQWGjKTASY1xV5m7Hr0iPeXD9+RDobLll3T9d2AO+g3my8xy5peVyjSag4I50mR1bBSN/Ct12lo+R9tJk0NZQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/@webassemblyjs/wasm-edit": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.14.1.tgz",+ "integrity": "sha512-RNJUIQH/J8iA/1NzlE4N7KtyZNHi3w7at7hDjvRNm5rcUXa00z1vRz3glZoULfJ5mpvYhLybmVcwcjGrC1pRrQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@webassemblyjs/helper-buffer": "1.14.1",+ "@webassemblyjs/helper-wasm-bytecode": "1.13.2",+ "@webassemblyjs/helper-wasm-section": "1.14.1",+ "@webassemblyjs/wasm-gen": "1.14.1",+ "@webassemblyjs/wasm-opt": "1.14.1",+ "@webassemblyjs/wasm-parser": "1.14.1",+ "@webassemblyjs/wast-printer": "1.14.1"+ }+ },+ "node_modules/@webassemblyjs/wasm-gen": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.14.1.tgz",+ "integrity": "sha512-AmomSIjP8ZbfGQhumkNvgC33AY7qtMCXnN6bL2u2Js4gVCg8fp735aEiMSBbDR7UQIj90n4wKAFUSEd0QN2Ukg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@webassemblyjs/helper-wasm-bytecode": "1.13.2",+ "@webassemblyjs/ieee754": "1.13.2",+ "@webassemblyjs/leb128": "1.13.2",+ "@webassemblyjs/utf8": "1.13.2"+ }+ },+ "node_modules/@webassemblyjs/wasm-opt": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.14.1.tgz",+ "integrity": "sha512-PTcKLUNvBqnY2U6E5bdOQcSM+oVP/PmrDY9NzowJjislEjwP/C4an2303MCVS2Mg9d3AJpIGdUFIQQWbPds0Sw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@webassemblyjs/helper-buffer": "1.14.1",+ "@webassemblyjs/wasm-gen": "1.14.1",+ "@webassemblyjs/wasm-parser": "1.14.1"+ }+ },+ "node_modules/@webassemblyjs/wasm-parser": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.14.1.tgz",+ "integrity": "sha512-JLBl+KZ0R5qB7mCnud/yyX08jWFw5MsoalJ1pQ4EdFlgj9VdXKGuENGsiCIjegI1W7p91rUlcB/LB5yRJKNTcQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@webassemblyjs/helper-api-error": "1.13.2",+ "@webassemblyjs/helper-wasm-bytecode": "1.13.2",+ "@webassemblyjs/ieee754": "1.13.2",+ "@webassemblyjs/leb128": "1.13.2",+ "@webassemblyjs/utf8": "1.13.2"+ }+ },+ "node_modules/@webassemblyjs/wast-printer": {+ "version": "1.14.1",+ "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.14.1.tgz",+ "integrity": "sha512-kPSSXE6De1XOR820C90RIo2ogvZG+c3KiHzqUoO/F34Y2shGzesfqv7o57xrxovZJH/MetF5UjroJ/R/3isoiw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@webassemblyjs/ast": "1.14.1",+ "@xtuc/long": "4.2.2"+ }+ },+ "node_modules/@xtuc/ieee754": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",+ "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==",+ "license": "BSD-3-Clause",+ "optional": true+ },+ "node_modules/@xtuc/long": {+ "version": "4.2.2",+ "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz",+ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==",+ "license": "Apache-2.0",+ "optional": true+ },+ "node_modules/acorn-import-phases": {+ "version": "1.0.4",+ "resolved": "https://registry.npmjs.org/acorn-import-phases/-/acorn-import-phases-1.0.4.tgz",+ "integrity": "sha512-wKmbr/DDiIXzEOiWrTTUcDm24kQ2vGfZQvM2fwg2vXqR5uW6aapr7ObPtj1th32b9u90/Pf4AItvdTh42fBmVQ==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=10.13.0"+ },+ "peerDependencies": {+ "acorn": "^8.14.0"+ }+ },+ "node_modules/ajv-formats": {+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",+ "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "ajv": "^8.0.0"+ },+ "peerDependencies": {+ "ajv": "^8.0.0"+ },+ "peerDependenciesMeta": {+ "ajv": {+ "optional": true+ }+ }+ },+ "node_modules/ajv-keywords": {+ "version": "5.1.0",+ "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz",+ "integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "fast-deep-equal": "^3.1.3"+ },+ "peerDependencies": {+ "ajv": "^8.8.2"+ }+ },+ "node_modules/ast-types": {+ "version": "0.16.1",+ "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.16.1.tgz",+ "integrity": "sha512-6t10qk83GOG8p0vKmaCr8eiilZwO171AvbROMtvvNiwrTly62t+7XkA8RdIIVbpMhCASAsxgAzdRSwh6nw/5Dg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "tslib": "^2.0.1"+ },+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/baseline-browser-mapping": {+ "version": "2.11.25",+ "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.25.tgz",+ "integrity": "sha512-gMmEShwwq7FJqMwvfRwvCl00v4kN+KOfJqXn+f4nrufak5gNHJOksd/60Dvjuz7sI8Y5WiSFBa8FEYr+zoyqCw==",+ "license": "Apache-2.0",+ "optional": true,+ "bin": {+ "baseline-browser-mapping": "dist/cli.cjs"+ },+ "engines": {+ "node": ">=6.0.0"+ }+ },+ "node_modules/buffer-from": {+ "version": "1.1.2",+ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",+ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/caniuse-lite": {+ "version": "1.0.30001810",+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001810.tgz",+ "integrity": "sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg==",+ "funding": [+ {+ "type": "opencollective",+ "url": "https://opencollective.com/browserslist"+ },+ {+ "type": "tidelift",+ "url": "https://tidelift.com/funding/github/npm/caniuse-lite"+ },+ {+ "type": "github",+ "url": "https://github.com/sponsors/ai"+ }+ ],+ "license": "CC-BY-4.0",+ "optional": true+ },+ "node_modules/chrome-trace-event": {+ "version": "1.0.4",+ "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.4.tgz",+ "integrity": "sha512-rNjApaLzuwaOTjCiT8lSDdGN1APCiqkChLMJxJPWLunPAt5fy8xgU9/jNOchV84wfIxrA0lRQB7oCT8jrn/wrQ==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6.0"+ }+ },+ "node_modules/commander": {+ "version": "2.20.3",+ "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",+ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/cross-spawn": {+ "version": "7.0.6",+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",+ "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "path-key": "^3.1.0",+ "shebang-command": "^2.0.0",+ "which": "^2.0.1"+ },+ "engines": {+ "node": ">= 8"+ }+ },+ "node_modules/css-loader": {+ "version": "7.1.4",+ "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-7.1.4.tgz",+ "integrity": "sha512-vv3J9tlOl04WjiMvHQI/9tmIrCxVrj6PFbHemBB1iihpeRbi/I4h033eoFIhwxBBqLhI0KYFS7yvynBFhIZfTw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "icss-utils": "^5.1.0",+ "postcss": "^8.4.40",+ "postcss-modules-extract-imports": "^3.1.0",+ "postcss-modules-local-by-default": "^4.0.5",+ "postcss-modules-scope": "^3.2.0",+ "postcss-modules-values": "^4.0.0",+ "postcss-value-parser": "^4.2.0",+ "semver": "^7.6.3"+ },+ "engines": {+ "node": ">= 18.12.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ },+ "peerDependencies": {+ "@rspack/core": "0.x || ^1.0.0 || ^2.0.0-0",+ "webpack": "^5.27.0"+ },+ "peerDependenciesMeta": {+ "@rspack/core": {+ "optional": true+ },+ "webpack": {+ "optional": true+ }+ }+ },+ "node_modules/css-loader/node_modules/semver": {+ "version": "7.8.5",+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",+ "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",+ "license": "ISC",+ "optional": true,+ "bin": {+ "semver": "bin/semver.js"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/cssesc": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",+ "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==",+ "license": "MIT",+ "optional": true,+ "bin": {+ "cssesc": "bin/cssesc"+ },+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/define-lazy-prop": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",+ "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/electron-to-chromium": {+ "version": "1.5.433",+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.433.tgz",+ "integrity": "sha512-5lCAbyZBjtmUt/RAGHRqrL2q0oEFRThDAsZHHDn9XHa89Qw7gMYOeSicBTy+AHfvo0r6vwsZvqNJTQIQy1BLzA==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/enhanced-resolve": {+ "version": "5.25.1",+ "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.25.1.tgz",+ "integrity": "sha512-nGXts5znJzmWPu+mIE9izCOzdg63oJca2mDzGWWTth7sr4aCToKcoyFVBQwN75Ij5Pf6p510EwkTqViTRzDV+w==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "graceful-fs": "^4.2.4",+ "tapable": "^2.3.3"+ },+ "engines": {+ "node": ">=10.13.0"+ }+ },+ "node_modules/error-stack-parser": {+ "version": "2.1.4",+ "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz",+ "integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "stackframe": "^1.3.4"+ }+ },+ "node_modules/es-module-lexer": {+ "version": "2.3.2",+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz",+ "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/esbuild": {+ "version": "0.25.12",+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",+ "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",+ "hasInstallScript": true,+ "license": "MIT",+ "bin": {+ "esbuild": "bin/esbuild"+ },+ "engines": {+ "node": ">=18"+ },+ "optionalDependencies": {+ "@esbuild/aix-ppc64": "0.25.12",+ "@esbuild/android-arm": "0.25.12",+ "@esbuild/android-arm64": "0.25.12",+ "@esbuild/android-x64": "0.25.12",+ "@esbuild/darwin-arm64": "0.25.12",+ "@esbuild/darwin-x64": "0.25.12",+ "@esbuild/freebsd-arm64": "0.25.12",+ "@esbuild/freebsd-x64": "0.25.12",+ "@esbuild/linux-arm": "0.25.12",+ "@esbuild/linux-arm64": "0.25.12",+ "@esbuild/linux-ia32": "0.25.12",+ "@esbuild/linux-loong64": "0.25.12",+ "@esbuild/linux-mips64el": "0.25.12",+ "@esbuild/linux-ppc64": "0.25.12",+ "@esbuild/linux-riscv64": "0.25.12",+ "@esbuild/linux-s390x": "0.25.12",+ "@esbuild/linux-x64": "0.25.12",+ "@esbuild/netbsd-arm64": "0.25.12",+ "@esbuild/netbsd-x64": "0.25.12",+ "@esbuild/openbsd-arm64": "0.25.12",+ "@esbuild/openbsd-x64": "0.25.12",+ "@esbuild/openharmony-arm64": "0.25.12",+ "@esbuild/sunos-x64": "0.25.12",+ "@esbuild/win32-arm64": "0.25.12",+ "@esbuild/win32-ia32": "0.25.12",+ "@esbuild/win32-x64": "0.25.12"+ }+ },+ "node_modules/escalade": {+ "version": "3.2.0",+ "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",+ "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6"+ }+ },+ "node_modules/eslint-scope": {+ "version": "5.1.1",+ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",+ "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==",+ "license": "BSD-2-Clause",+ "optional": true,+ "dependencies": {+ "esrecurse": "^4.3.0",+ "estraverse": "^4.1.1"+ },+ "engines": {+ "node": ">=8.0.0"+ }+ },+ "node_modules/esprima": {+ "version": "4.0.1",+ "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",+ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",+ "license": "BSD-2-Clause",+ "optional": true,+ "bin": {+ "esparse": "bin/esparse.js",+ "esvalidate": "bin/esvalidate.js"+ },+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/esrecurse": {+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",+ "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",+ "license": "BSD-2-Clause",+ "optional": true,+ "dependencies": {+ "estraverse": "^5.2.0"+ },+ "engines": {+ "node": ">=4.0"+ }+ },+ "node_modules/esrecurse/node_modules/estraverse": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",+ "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",+ "license": "BSD-2-Clause",+ "optional": true,+ "engines": {+ "node": ">=4.0"+ }+ },+ "node_modules/estraverse": {+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz",+ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==",+ "license": "BSD-2-Clause",+ "optional": true,+ "engines": {+ "node": ">=4.0"+ }+ },+ "node_modules/events": {+ "version": "3.3.0",+ "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",+ "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=0.8.x"+ }+ },+ "node_modules/execa": {+ "version": "5.1.1",+ "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",+ "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "cross-spawn": "^7.0.3",+ "get-stream": "^6.0.0",+ "human-signals": "^2.1.0",+ "is-stream": "^2.0.0",+ "merge-stream": "^2.0.0",+ "npm-run-path": "^4.0.1",+ "onetime": "^5.1.2",+ "signal-exit": "^3.0.3",+ "strip-final-newline": "^2.0.0"+ },+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sindresorhus/execa?sponsor=1"+ }+ },+ "node_modules/fast-deep-equal": {+ "version": "3.1.3",+ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",+ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/fs-monkey": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/fs-monkey/-/fs-monkey-1.0.3.tgz",+ "integrity": "sha512-cybjIfiiE+pTWicSCLFHSrXZ6EilF30oh91FDP9S2B051prEa7QWfrVTQm10/dDpswBDXZugPa1Ogu8Yh+HV0Q==",+ "license": "Unlicense",+ "optional": true+ },+ "node_modules/get-stream": {+ "version": "6.0.1",+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",+ "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/glob-to-regexp": {+ "version": "0.4.1",+ "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",+ "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==",+ "license": "BSD-2-Clause",+ "optional": true+ },+ "node_modules/graceful-fs": {+ "version": "4.2.11",+ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",+ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/has-flag": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",+ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/html-entities": {+ "version": "2.6.0",+ "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.6.0.tgz",+ "integrity": "sha512-kig+rMn/QOVRvr7c86gQ8lWXq+Hkv6CbAH1hLu+RG338StTpE8Z0b44SDVaqVu7HGKf27frdmUYEs9hTUX/cLQ==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/mdevils"+ },+ {+ "type": "patreon",+ "url": "https://patreon.com/mdevils"+ }+ ],+ "license": "MIT",+ "optional": true+ },+ "node_modules/human-signals": {+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",+ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",+ "license": "Apache-2.0",+ "optional": true,+ "engines": {+ "node": ">=10.17.0"+ }+ },+ "node_modules/icss-utils": {+ "version": "5.1.0",+ "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz",+ "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==",+ "license": "ISC",+ "optional": true,+ "engines": {+ "node": "^10 || ^12 || >= 14"+ },+ "peerDependencies": {+ "postcss": "^8.1.0"+ }+ },+ "node_modules/is-docker": {+ "version": "2.2.1",+ "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",+ "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==",+ "license": "MIT",+ "optional": true,+ "bin": {+ "is-docker": "cli.js"+ },+ "engines": {+ "node": ">=8"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/is-stream": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",+ "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=8"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/is-wsl": {+ "version": "2.2.0",+ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",+ "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "is-docker": "^2.0.0"+ },+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/isexe": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",+ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/jest-worker": {+ "version": "27.5.1",+ "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz",+ "integrity": "sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/node": "*",+ "merge-stream": "^2.0.0",+ "supports-color": "^8.0.0"+ },+ "engines": {+ "node": ">= 10.13.0"+ }+ },+ "node_modules/json-parse-even-better-errors": {+ "version": "2.3.1",+ "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",+ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/loader-runner": {+ "version": "4.3.2",+ "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.2.tgz",+ "integrity": "sha512-DFEqQ3ihfS9blba08cLfYf1NRAIEm+dDjic073DRDc3/JspI/8wYmtDsHwd3+4hwvdxSK7PGaElfTmm0awWJ4w==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6.11.5"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ }+ },+ "node_modules/lru-cache": {+ "version": "6.0.0",+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",+ "license": "ISC",+ "optional": true,+ "dependencies": {+ "yallist": "^4.0.0"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/memfs": {+ "version": "3.4.3",+ "resolved": "https://registry.npmjs.org/memfs/-/memfs-3.4.3.tgz",+ "integrity": "sha512-eivjfi7Ahr6eQTn44nvTnR60e4a1Fs1Via2kCR5lHo/kyNoiMWaXCNJ/GpSd0ilXas2JSOl9B5FTIhflXu0hlg==",+ "license": "Unlicense",+ "optional": true,+ "dependencies": {+ "fs-monkey": "1.0.3"+ },+ "engines": {+ "node": ">= 4.0.0"+ }+ },+ "node_modules/merge-stream": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",+ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/mime-db": {+ "version": "1.52.0",+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 0.6"+ }+ },+ "node_modules/mime-types": {+ "version": "2.1.35",+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "mime-db": "1.52.0"+ },+ "engines": {+ "node": ">= 0.6"+ }+ },+ "node_modules/mimic-fn": {+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",+ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6"+ }+ },+ "node_modules/nanoid": {+ "version": "3.3.19",+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.19.tgz",+ "integrity": "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/ai"+ }+ ],+ "license": "MIT",+ "optional": true,+ "bin": {+ "nanoid": "bin/nanoid.cjs"+ },+ "engines": {+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"+ }+ },+ "node_modules/neo-async": {+ "version": "2.6.2",+ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",+ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/node-releases": {+ "version": "2.0.56",+ "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.56.tgz",+ "integrity": "sha512-x0InOIyzgdk+eyaWaRJFH5snEtiImgBgblZ2CyPrLmqqcuMQkEvcDPHbzqbD8eDsSeJbVOjn+crzyzHaM4D+/A==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/npm-run-path": {+ "version": "4.0.1",+ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",+ "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "path-key": "^3.0.0"+ },+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/onetime": {+ "version": "5.1.2",+ "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",+ "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "mimic-fn": "^2.1.0"+ },+ "engines": {+ "node": ">=6"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/open": {+ "version": "8.4.2",+ "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz",+ "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "define-lazy-prop": "^2.0.0",+ "is-docker": "^2.1.1",+ "is-wsl": "^2.2.0"+ },+ "engines": {+ "node": ">=12"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/path-key": {+ "version": "3.1.1",+ "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",+ "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/picocolors": {+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/playwright-core": {+ "version": "1.63.0",+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz",+ "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "playwright-core": "cli.js"+ },+ "engines": {+ "node": ">=20"+ }+ },+ "node_modules/postcss-modules-extract-imports": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.1.0.tgz",+ "integrity": "sha512-k3kNe0aNFQDAZGbin48pL2VNidTF0w4/eASDsxlyspobzU3wZQLOGj7L9gfRe0Jo9/4uud09DsjFNH7winGv8Q==",+ "license": "ISC",+ "optional": true,+ "engines": {+ "node": "^10 || ^12 || >= 14"+ },+ "peerDependencies": {+ "postcss": "^8.1.0"+ }+ },+ "node_modules/postcss-modules-local-by-default": {+ "version": "4.2.0",+ "resolved": "https://registry.npmjs.org/postcss-modules-local-by-default/-/postcss-modules-local-by-default-4.2.0.tgz",+ "integrity": "sha512-5kcJm/zk+GJDSfw+V/42fJ5fhjL5YbFDl8nVdXkJPLLW+Vf9mTD5Xe0wqIaDnLuL2U6cDNpTr+UQ+v2HWIBhzw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "icss-utils": "^5.0.0",+ "postcss-selector-parser": "^7.0.0",+ "postcss-value-parser": "^4.1.0"+ },+ "engines": {+ "node": "^10 || ^12 || >= 14"+ },+ "peerDependencies": {+ "postcss": "^8.1.0"+ }+ },+ "node_modules/postcss-modules-scope": {+ "version": "3.2.1",+ "resolved": "https://registry.npmjs.org/postcss-modules-scope/-/postcss-modules-scope-3.2.1.tgz",+ "integrity": "sha512-m9jZstCVaqGjTAuny8MdgE88scJnCiQSlSrOWcTQgM2t32UBe+MUmFSO5t7VMSfAf/FJKImAxBav8ooCHJXCJA==",+ "license": "ISC",+ "optional": true,+ "dependencies": {+ "postcss-selector-parser": "^7.0.0"+ },+ "engines": {+ "node": "^10 || ^12 || >= 14"+ },+ "peerDependencies": {+ "postcss": "^8.1.0"+ }+ },+ "node_modules/postcss-modules-values": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/postcss-modules-values/-/postcss-modules-values-4.0.0.tgz",+ "integrity": "sha512-RDxHkAiEGI78gS2ofyvCsu7iycRv7oqw5xMWn9iMoR0N/7mf9D50ecQqUo5BZ9Zh2vH4bCUR/ktCqbB9m8vJjQ==",+ "license": "ISC",+ "optional": true,+ "dependencies": {+ "icss-utils": "^5.0.0"+ },+ "engines": {+ "node": "^10 || ^12 || >= 14"+ },+ "peerDependencies": {+ "postcss": "^8.1.0"+ }+ },+ "node_modules/postcss-selector-parser": {+ "version": "7.1.6",+ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.6.tgz",+ "integrity": "sha512-7qASPzhKF2l2KLboRZux8CCTRMdGiV08vWmyKzPz22qZ7ZjQBOeY7rNzNoCLSUiftJ7HUq0GERHmxw/t0dCdMw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "cssesc": "^3.0.0",+ "util-deprecate": "^1.0.2"+ },+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/postcss-value-parser": {+ "version": "4.2.0",+ "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",+ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/recast": {+ "version": "0.23.21",+ "resolved": "https://registry.npmjs.org/recast/-/recast-0.23.21.tgz",+ "integrity": "sha512-mFAyJq9vUbSTARLZUvAEf1z3YxlvAwswbmxMx2mPA/MSm4KmpwvwvhsH/NIrZhyOuwD60Lzyw2qh83uCbgTPYw==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "ast-types": "^0.16.1",+ "esprima": "~4.0.0",+ "source-map": "~0.6.1",+ "tiny-invariant": "^1.3.3",+ "tslib": "^2.0.1"+ },+ "engines": {+ "node": ">= 4"+ }+ },+ "node_modules/recast/node_modules/source-map": {+ "version": "0.6.1",+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",+ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",+ "license": "BSD-3-Clause",+ "optional": true,+ "engines": {+ "node": ">=0.10.0"+ }+ },+ "node_modules/remotion": {+ "version": "4.0.522",+ "resolved": "https://registry.npmjs.org/remotion/-/remotion-4.0.522.tgz",+ "integrity": "sha512-f80OmFU4xUE2iTj/kcFSmb63+p5jbYXJ31qUEy/yQKZYKoVW2gMvAwDSDvUjsJKSRehfe5TG+EvHvZ+UGog1Jg==",+ "license": "SEE LICENSE IN LICENSE.md",+ "optional": true,+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/scheduler": {+ "version": "0.28.0",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.28.0.tgz",+ "integrity": "sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/schema-utils": {+ "version": "4.5.0",+ "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.5.0.tgz",+ "integrity": "sha512-zJlMCZ0cAR5p/Y4oVpRoqioDMJcGxaXRrQ/4rP4WyR84vc5z/DolXdbvXeDpTwbtocDFr2rhPqHPErDCUtz2kA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/json-schema": "^7.0.15",+ "ajv": "^8.20.0",+ "ajv-formats": "^3.0.1",+ "ajv-keywords": "^5.1.0"+ },+ "engines": {+ "node": ">= 10.13.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ }+ },+ "node_modules/semver": {+ "version": "7.5.3",+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz",+ "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==",+ "license": "ISC",+ "optional": true,+ "dependencies": {+ "lru-cache": "^6.0.0"+ },+ "bin": {+ "semver": "bin/semver.js"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/shebang-command": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",+ "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "shebang-regex": "^3.0.0"+ },+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/shebang-regex": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",+ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/signal-exit": {+ "version": "3.0.7",+ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",+ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/source-map": {+ "version": "0.8.0",+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0.tgz",+ "integrity": "sha512-d8EqvL+k/SOXCreS/SUzg2ciyHqBBLcN/yuRjFsbvVhHTE2pgei7oAhmPM7kWFbkX6OSMQfUq4KbkF3au9lhYQ==",+ "license": "BSD-3-Clause",+ "optional": true,+ "engines": {+ "node": ">= 12"+ }+ },+ "node_modules/source-map-js": {+ "version": "1.2.1",+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",+ "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",+ "license": "BSD-3-Clause",+ "optional": true,+ "engines": {+ "node": ">=0.10.0"+ }+ },+ "node_modules/source-map-support": {+ "version": "0.5.21",+ "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",+ "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "buffer-from": "^1.0.0",+ "source-map": "^0.6.0"+ }+ },+ "node_modules/source-map-support/node_modules/source-map": {+ "version": "0.6.1",+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",+ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",+ "license": "BSD-3-Clause",+ "optional": true,+ "engines": {+ "node": ">=0.10.0"+ }+ },+ "node_modules/stackframe": {+ "version": "1.3.4",+ "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz",+ "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/strip-final-newline": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",+ "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6"+ }+ },+ "node_modules/style-loader": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-4.0.0.tgz",+ "integrity": "sha512-1V4WqhhZZgjVAVJyt7TdDPZoPBPNHbekX4fWnCJL1yQukhCeZhJySUL+gL9y6sNdN95uEOS83Y55SqHcP7MzLA==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 18.12.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ },+ "peerDependencies": {+ "webpack": "^5.27.0"+ }+ },+ "node_modules/supports-color": {+ "version": "8.1.1",+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",+ "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "has-flag": "^4.0.0"+ },+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/chalk/supports-color?sponsor=1"+ }+ },+ "node_modules/tapable": {+ "version": "2.3.3",+ "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.3.tgz",+ "integrity": "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=6"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ }+ },+ "node_modules/terser": {+ "version": "5.51.2",+ "resolved": "https://registry.npmjs.org/terser/-/terser-5.51.2.tgz",+ "integrity": "sha512-bWnjSNscmuI+GJze6ZupnHP8G/cTcsJF+bXCeQknk2SHQsgbNJnLrqiH9jZ2W4STPVXH2mDKKRX3iwPhc9Cn/Q==",+ "license": "BSD-2-Clause",+ "optional": true,+ "dependencies": {+ "@jridgewell/source-map": "^0.3.3",+ "acorn": "^8.15.0",+ "commander": "^2.20.0",+ "source-map-support": "~0.5.20"+ },+ "bin": {+ "terser": "bin/terser"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/terser-webpack-plugin": {+ "version": "5.6.1",+ "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.6.1.tgz",+ "integrity": "sha512-201R5j+sJpK8nFWwKVyNfZot8FaJbLZDq5evriVzbV1wDtSXDjRUDRfJzHpAaxFDMEhsZL1QkeqM61wgsS3KaQ==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@jridgewell/trace-mapping": "^0.3.25",+ "jest-worker": "^27.4.5",+ "schema-utils": "^4.3.0",+ "terser": "^5.31.1"+ },+ "engines": {+ "node": ">= 10.13.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/webpack"+ },+ "peerDependencies": {+ "webpack": "^5.1.0"+ },+ "peerDependenciesMeta": {+ "@minify-html/node": {+ "optional": true+ },+ "@swc/core": {+ "optional": true+ },+ "@swc/css": {+ "optional": true+ },+ "@swc/html": {+ "optional": true+ },+ "clean-css": {+ "optional": true+ },+ "cssnano": {+ "optional": true+ },+ "csso": {+ "optional": true+ },+ "esbuild": {+ "optional": true+ },+ "html-minifier-terser": {+ "optional": true+ },+ "lightningcss": {+ "optional": true+ },+ "postcss": {+ "optional": true+ },+ "uglify-js": {+ "optional": true+ }+ }+ },+ "node_modules/tiny-invariant": {+ "version": "1.3.3",+ "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz",+ "integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/to-fast-properties": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",+ "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/tslib": {+ "version": "2.8.1",+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",+ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",+ "license": "0BSD",+ "optional": true+ },+ "node_modules/typescript": {+ "version": "5.9.3",+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",+ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "tsc": "bin/tsc",+ "tsserver": "bin/tsserver"+ },+ "engines": {+ "node": ">=14.17"+ }+ },+ "node_modules/undici-types": {+ "version": "8.9.0",+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz",+ "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/update-browserslist-db": {+ "version": "1.3.3",+ "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.3.tgz",+ "integrity": "sha512-pJ2sYawQS0R/WI928Gj5GlPhTGzbMelq0+4INtSYNDV9ErKJcX6xjGWkoG/VnB3dpUm00zALaqkrUD77pO5TDQ==",+ "funding": [+ {+ "type": "opencollective",+ "url": "https://opencollective.com/browserslist"+ },+ {+ "type": "tidelift",+ "url": "https://tidelift.com/funding/github/npm/browserslist"+ },+ {+ "type": "github",+ "url": "https://github.com/sponsors/ai"+ }+ ],+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "escalade": "^3.2.0",+ "picocolors": "^1.1.1"+ },+ "bin": {+ "update-browserslist-db": "cli.js"+ },+ "peerDependencies": {+ "browserslist": ">= 4.21.0"+ }+ },+ "node_modules/util-deprecate": {+ "version": "1.0.2",+ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",+ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",+ "license": "MIT",+ "optional": true+ },+ "node_modules/watchpack": {+ "version": "2.5.2",+ "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.5.2.tgz",+ "integrity": "sha512-6i/00NBjP4yGPs+caKSyRfpTF/8Torsu0MOW3mMzIbhgISFder8i7xbqgHlLMwJrdiN8ndBV3UA1/AfzPSr+jg==",+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "graceful-fs": "^4.1.2"+ },+ "engines": {+ "node": ">=10.13.0"+ }+ },+ "node_modules/webpack-sources": {+ "version": "3.5.1",+ "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.5.1.tgz",+ "integrity": "sha512-jyuiGJdtvY434z5bUZrjz67v76/ePNvFZTp9Mdz29IlH4+GPsgyGjiv0fKI+M7BdkU6ADjulUcKAd3tUK3WlEw==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=10.13.0"+ }+ },+ "node_modules/which": {+ "version": "2.0.2",+ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",+ "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",+ "license": "ISC",+ "optional": true,+ "dependencies": {+ "isexe": "^2.0.0"+ },+ "bin": {+ "node-which": "bin/node-which"+ },+ "engines": {+ "node": ">= 8"+ }+ },+ "node_modules/ws": {+ "version": "8.21.0",+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",+ "integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=10.0.0"+ },+ "peerDependencies": {+ "bufferutil": "^4.0.1",+ "utf-8-validate": ">=5.0.2"+ },+ "peerDependenciesMeta": {+ "bufferutil": {+ "optional": true+ },+ "utf-8-validate": {+ "optional": true+ }+ }+ },+ "node_modules/yallist": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",+ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",+ "license": "ISC",+ "optional": true+ },+ "node_modules/zod": {+ "version": "4.5.4",+ "resolved": "https://registry.npmjs.org/zod/-/zod-4.5.4.tgz",+ "integrity": "sha512-sC95tT5iHHH9gtpj6A81kh+NEaRAUFN+qlUPDUbRfOMvNf5QCBqsb3WgvnpVtK5Y+4UfA6KqufotuTvMGiTlsA==",+ "license": "MIT",+ "optional": true,+ "funding": {+ "url": "https://github.com/sponsors/colinhacks"+ }+ }+ }+}diff --git a/engine/package.json b/engine/package.jsonnew file mode 100644index 0000000..c442bc5--- /dev/null+++ b/engine/package.json@@ -0,0 +1,26 @@+{+ "name": "anidoodle-engine",+ "version": "1.0.0",+ "private": true,+ "type": "module",+ "description": "Portable art core + backend adapters for a film drawn entirely by code.",+ "scripts": {+ "still": "node tools/still.mjs",+ "gate": "node tools/gate.mjs",+ "emit": "node tools/emit.mjs",+ "render": "node tools/render.mjs"+ },+ "dependencies": {+ "esbuild": "^0.25.0"+ },+ "devDependencies": {+ "playwright-core": "^1.48.0",+ "typescript": "^5.9.0"+ },+ "optionalDependencies": {+ "@remotion/bundler": "4.0.522",+ "@remotion/renderer": "4.0.522",+ "react": "^19.0.0",+ "remotion": "4.0.522"+ }+}diff --git a/engine/src/canvas-core/balloon.ts b/engine/src/canvas-core/balloon.tsnew file mode 100644index 0000000..0f3a72d--- /dev/null+++ b/engine/src/canvas-core/balloon.ts@@ -0,0 +1,207 @@+import { Gfx, fractal, rng, type Ctx, type Env, type Medium, type P } from "./core";+import type { Film } from "./film";+import { blob, bounds, clamp, fillShape, hatchRuns, inside, lerp, lerpP, mix, smooth } from "./gallery";++// HOT-AIR BALLOON · crayon. Wax on toothy paper: every fill is a back-and-forth scribble that+// skips the valleys of the sheet, a second, darker crayon is worked across the shade side, a+// white crayon burnishes the highlight, and the contour is a fat wobbly line gone over twice.+//+// Structure first, though: the envelope is a surface of revolution (round crown, widest just+// above the middle, tapering to the throat), seen a little from below so its latitudes bow. Its+// gores are meridians of that surface, so they crowd together at the limbs and meet at the crown+// ring and the throat. Load tapes on the seams, a skirt, cables to a wicker basket, the burner+// flame roaring up into the throat. Light from the upper left, where the sun is.++const CRAYON_M: Medium = { nib: 2.9, taper: 0.3, pressure: 0.8, retrace: true, wobble: 2.2, rough: 1.3 };+const K = { red: "#e5392d", orange: "#f68b1f", yellow: "#ffd21f", green: "#3dae49", blue: "#2f7de1", sky: "#69c3f2", purple: "#8d4fc7", pink: "#ff78ae", brown: "#8b5a3c", white: "#fffdf4", black: "#262233", leaf: "#2f8a3b" };+const PAPER = "#fdf8ea";+const dark = (c: string) => mix(c, "#2a1d3a", 0.45);++// ---------------------------------------------------------------- the crayon+// A scribble fill: hatch runs joined end to end into one back-and-forth stroke, drawn in short+// passes so the pressure (alpha) wanders the way a child's hand does.+const scribble = (g: Gfx, region: P[], color: string, o: { angle: number; gap: number; w: number; alpha: number; seed: number; keep?: (x: number, y: number) => boolean; over?: number }) => {+ const { angle, gap, w, alpha, seed, keep = () => true, over = 1.035 } = o, r = rng(seed), b = bounds(region);+ const cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, grown = region.map(([x, y]) => [cx + (x - cx) * over, cy + (y - cy) * over] as P);+ const runs = hatchRuns({ x0: b.x0 - 8, y0: b.y0 - 8, x1: b.x1 + 8, y1: b.y1 + 8 }, angle, gap, (x, y) => inside(grown, x, y) && keep(x, y), 5, seed);+ const c = g.cur; g.touch(b.x0 - 14, b.y0 - 14, b.x1 + 14, b.y1 + 14);+ c.save(); c.lineCap = "round"; c.lineJoin = "round"; c.strokeStyle = color; c.lineWidth = w;+ let prev: P | null = null;+ runs.forEach((run, i) => {+ const pts = (i % 2 ? [...run].reverse() : run).filter((_, k, a) => k % 3 === 0 || k === a.length - 1).map(([x, y]) => [x + (r() - 0.5) * 1.6, y + (r() - 0.5) * 1.6] as P);+ const jump = prev ? Math.hypot(pts[0][0] - prev[0], pts[0][1] - prev[1]) : 0;+ c.globalAlpha = alpha * (0.72 + r() * 0.4);+ c.beginPath();+ if (prev && jump < gap * 3.2) { c.moveTo(prev[0], prev[1]); pts.forEach(([x, y]) => c.lineTo(x, y)); } // the turn of the zigzag+ else { pts.forEach(([x, y], k) => (k ? c.lineTo(x, y) : c.moveTo(x, y))); }+ c.stroke(); prev = pts[pts.length - 1];+ });+ c.restore();+};+const line = (g: Gfx, pts: P[], color: string, w: number, seed: number, op = 0.92, wob = 1) => g.pen(pts, { w, color, seed, wobble: wob, boil: 0, opacity: op, retrace: true, taper: 1 });+// wax skips the valleys of the sheet: every crayon layer is punched by the paper's tooth+const wax = (g: Gfx, fn: () => void) => g.group("plain", fn, { textures: ["pencilTooth"] });++// ---------------------------------------------------------------- the envelope+const CX = 540, R = 236, EQ = 352, TILT = 0.11;+const profile = smooth([[0, EQ - R], [R * 0.52, EQ - R * 0.86], [R * 0.87, EQ - R * 0.5], [R, EQ - R * 0.02], [R * 0.95, EQ + R * 0.4], [R * 0.76, EQ + R * 0.86], [R * 0.47, EQ + R * 1.24], [R * 0.2, EQ + R * 1.48]], false, 12);+const merid = (phi: number): P[] => profile.map(([w, y]) => [CX + w * Math.sin(phi), y + w * Math.cos(phi) * TILT]);+const GORES = 12, phiAt = (k: number) => -Math.PI / 2 + (k / GORES) * Math.PI;+const RAINBOW = [K.red, K.orange, K.yellow, K.green, K.blue, K.purple];++const envelope = (g: Gfx) => {+ const outline = [...merid(-Math.PI / 2), ...merid(Math.PI / 2).reverse()];+ g.group("plain", () => fillShape(g, outline, PAPER));+ for (let k = 0; k < GORES; k++) {+ const a = merid(phiAt(k)), b2 = merid(phiAt(k + 1)), gore = [...a, ...[...b2].reverse()], col = RAINBOW[k % 6];+ const phiC = (phiAt(k) + phiAt(k + 1)) / 2, litG = clamp(Math.cos(phiC + 0.62) * 0.9 + 0.1);+ wax(g, () => {+ scribble(g, gore, col, { angle: 1.25 + (k % 3) * 0.12, gap: 5.2, w: 6.2, alpha: 0.9, seed: 100 + k * 7 });+ scribble(g, gore, col, { angle: -0.35 + (k % 2) * 0.2, gap: 9, w: 5, alpha: 0.5, seed: 101 + k * 7 });+ // the shade crayon, worked across the side away from the light and under the belly+ const sh = (x: number, y: number) => { const u = (x - CX) / R, v = (y - EQ) / R; return u * 0.9 + v * 0.8 + (fractal(9, x, y, 0.02, 0.02, 2) - 0.5) * 0.35 > 0.15 + litG * 0.4; };+ scribble(g, gore, dark(col), { angle: 0.55, gap: 6.5, w: 5, alpha: 0.72, seed: 102 + k * 7, keep: sh });+ const deep = (x: number, y: number) => { const u = (x - CX) / R, v = (y - EQ) / R; return u * 0.9 + v * 0.9 > 0.75 + litG * 0.35; };+ scribble(g, gore, mix(dark(col), K.black, 0.3), { angle: -0.6, gap: 7, w: 4.4, alpha: 0.6, seed: 103 + k * 7, keep: deep });+ // burnished highlight: white crayon pressed hard over the colour, upper left+ const hi = (x: number, y: number) => { const u = (x - CX) / R + 0.42, v = (y - EQ) / R + 0.52; return u * u * 1.4 + v * v < 0.1 + (fractal(10, x, y, 0.03, 0.03, 2) - 0.5) * 0.06; };+ scribble(g, gore, K.white, { angle: 1.0, gap: 5, w: 4.5, alpha: 0.75, seed: 104 + k * 7, keep: hi, over: 1 });+ });+ }+ // seams: load tapes down every meridian, a few latitude tapes, the crown ring, the outline twice+ wax(g, () => {+ for (let k = 1; k < GORES; k++) line(g, merid(phiAt(k)).filter((_, i) => i % 4 === 0), mix(K.black, RAINBOW[k % 6], 0.2), 1.1, 200 + k, 0.8, 0.8);+ [0.3, 0.55].forEach((f, j) => { const i = Math.round(f * (profile.length - 1)), [w, y] = profile[i], pts: P[] = []; for (let q = 0; q <= 24; q++) { const ph = -Math.PI / 2 + (q / 24) * Math.PI; pts.push([CX + w * Math.sin(ph), y + w * Math.cos(ph) * TILT]); } line(g, pts, K.black, 1.1, 230 + j, 0.7, 0.9); });+ const top = merid(0)[0]; fillShape(g, blob(top[0], top[1] + 6, 20, 8, 240, 0.1, 10), K.blue); line(g, [...blob(top[0], top[1] + 6, 20, 8, 240, 0.1, 10)], dark(K.blue), 1.5, 241, 0.9, 0.6);+ line(g, merid(-Math.PI / 2).filter((_, i) => i % 3 === 0), K.black, 2.2, 250, 0.92);+ line(g, merid(Math.PI / 2).filter((_, i) => i % 3 === 0), K.black, 2.5, 251, 0.95);+ });+};++// ---------------------------------------------------------------- below the envelope+const rigging = (g: Gfx) => {+ const throatY = EQ + R * 1.48, tw = R * 0.2, skirt: P[] = [[CX - tw, throatY - 4], [CX + tw, throatY - 4], [CX + tw * 0.9, throatY + 34], [CX - tw * 0.9, throatY + 34]];+ const bk = { x0: CX - 62, x1: CX + 62, y0: 812, y1: 880 };+ // cables from the skirt to the basket corners, and the burner frame+ wax(g, () => {+ [[-tw * 0.9, bk.x0 + 4], [-tw * 0.3, bk.x0 + 40], [tw * 0.3, bk.x1 - 40], [tw * 0.9, bk.x1 - 4]].forEach(([a, b2], i) => line(g, [[CX + a, throatY + 30], [lerp(CX + a, b2, 0.5), lerp(throatY + 30, bk.y0, 0.5)], [b2, bk.y0]], "#4a3a36", 0.9, 300 + i, 0.85, 0.6));+ fillShape(g, skirt, PAPER);+ scribble(g, skirt, K.red, { angle: 1.4, gap: 5, w: 5.5, alpha: 0.9, seed: 310 });+ scribble(g, skirt, dark(K.red), { angle: 0.4, gap: 6, w: 4.5, alpha: 0.65, seed: 311, keep: (x) => x > CX });+ line(g, [...skirt, skirt[0]], K.black, 1.8, 312, 0.9, 0.8);+ // the burner, and its flame roaring up into the throat+ const burner: P[] = [[CX - 26, 790], [CX + 26, 790], [CX + 22, 806], [CX - 22, 806]];+ fillShape(g, burner, "#aab4c4"); scribble(g, burner, "#7f8aa0", { angle: 0.3, gap: 4, w: 3.5, alpha: 0.8, seed: 320, keep: (x) => x > CX - 4 });+ line(g, [...burner, burner[0]], K.black, 1.4, 321, 0.9, 0.5);+ const flame = smooth([[CX - 17, 792], [CX - 19, 772], [CX - 8, 754], [CX + 1, 736], [CX + 9, 752], [CX + 19, 770], [CX + 17, 792]], true, 8); // it disappears up into the skirt+ fillShape(g, flame, PAPER);+ scribble(g, flame, K.orange, { angle: 1.5, gap: 4.5, w: 5, alpha: 0.9, seed: 330 });+ scribble(g, flame, K.yellow, { angle: 1.4, gap: 4.5, w: 4.5, alpha: 0.95, seed: 331, keep: (x, y) => Math.abs(x - CX) < 10 - (792 - y) * 0.08 && y > 748 });+ scribble(g, flame, K.red, { angle: 0.2, gap: 6, w: 3.5, alpha: 0.55, seed: 332, keep: (x) => Math.abs(x - CX) > 12 });+ line(g, flame.filter((_, i) => i % 3 === 0), K.red, 1.4, 333, 0.8, 1.2);+ });+ // the basket: wicker weave in two browns, a padded leather rim, two people, one waving+ wax(g, () => {+ const basket: P[] = [[bk.x0, bk.y0], [bk.x1, bk.y0], [bk.x1 - 8, bk.y1], [bk.x0 + 8, bk.y1]];+ // two passengers first, so the basket rim hides their bodies+ [[CX - 40, K.pink, 1], [CX + 40, K.blue, -1]].forEach(([x, c, s], i) => {+ const hx = x as number, hy = bk.y0 - 30;+ fillShape(g, blob(hx, hy + 18, 13, 14, 340 + i, 0.1, 10), PAPER); scribble(g, blob(hx, hy + 18, 13, 14, 340 + i, 0.1, 10), c as string, { angle: 1.2, gap: 4, w: 4, alpha: 0.9, seed: 341 + i });+ fillShape(g, blob(hx, hy, 11, 12, 345 + i, 0.08, 10), "#f6c8a0"); scribble(g, blob(hx, hy, 11, 12, 345 + i, 0.08, 10), "#e8a37c", { angle: 0.4, gap: 5, w: 3.4, alpha: 0.6, seed: 346 + i, keep: (xx) => xx > hx });+ line(g, blob(hx, hy, 11, 12, 345 + i, 0.08, 10), "#6b3e2e", 1.3, 347 + i, 0.85, 0.5);+ fillShape(g, blob(hx - 2, hy - 9, 11, 5, 348 + i, 0.2, 10), i ? K.brown : K.orange);+ if (s === 1) { line(g, [[hx - 9, hy + 16], [hx - 24, hy + 2], [hx - 30, hy - 20]], "#e8a37c", 2.6, 349, 0.95, 0.5); fillShape(g, blob(hx - 31, hy - 24, 5, 5, 356, 0.1, 8), "#f6c8a0"); } // waving+ else { line(g, [[hx + 8, hy + 16], [hx + 22, hy + 6], [hx + 18, hy - 4]], "#e8a37c", 2.4, 357, 0.95, 0.5); } // pointing at the view+ });+ fillShape(g, basket, PAPER);+ scribble(g, basket, "#c98f4e", { angle: 1.4, gap: 4.5, w: 5, alpha: 0.9, seed: 350 });+ for (let yy = bk.y0 + 8; yy < bk.y1 - 3; yy += 8) for (let xx = bk.x0 + 4 + ((yy / 8) % 2) * 6; xx < bk.x1 - 6; xx += 12) line(g, [[xx, yy], [xx + 7, yy + 3]], K.brown, 1.0, 351 + xx * 3 + yy, 0.75, 0.3); // the weave+ scribble(g, basket, K.brown, { angle: 0.35, gap: 6, w: 4, alpha: 0.6, seed: 352, keep: (x) => x > CX + 12 });+ const rim: P[] = [[bk.x0 - 5, bk.y0 - 9], [bk.x1 + 5, bk.y0 - 9], [bk.x1 + 5, bk.y0 + 5], [bk.x0 - 5, bk.y0 + 5]];+ fillShape(g, rim, "#7a4a2c"); scribble(g, rim, "#5a3420", { angle: 0.1, gap: 3, w: 3, alpha: 0.7, seed: 353, keep: (x) => x > CX });+ line(g, [...basket, basket[0]], "#4a2c1c", 1.9, 354, 0.9, 0.7); line(g, [...rim, rim[0]], "#3a2216", 1.6, 355, 0.9, 0.6);+ });+};++// ---------------------------------------------------------------- the world around it+const sky = (g: Gfx) => {+ wax(g, () => {+ const all: P[] = [[0, 0], [1080, 0], [1080, 1080], [0, 1080]];+ scribble(g, all, K.sky, { angle: 0.38, gap: 7, w: 6, alpha: 0.62, seed: 10, over: 1 });+ scribble(g, all, mix(K.sky, K.blue, 0.4), { angle: -0.5, gap: 12, w: 5, alpha: 0.4, seed: 11, over: 1, keep: (x, y) => y < 380 + (fractal(12, x, y, 0.01, 0.01, 2) - 0.5) * 200 });+ });+ // the sun, where the light comes from+ wax(g, () => {+ const sun = blob(150, 140, 62, 60, 20, 0.05, 16);+ fillShape(g, sun, PAPER); scribble(g, sun, K.yellow, { angle: 0.9, gap: 4.5, w: 5.5, alpha: 0.95, seed: 21 }); scribble(g, sun, K.orange, { angle: -0.7, gap: 7, w: 4, alpha: 0.45, seed: 22, keep: (x, y) => (x - 150) + (y - 140) > 20 });+ line(g, sun.filter((_, i) => i % 3 === 0), K.orange, 1.8, 23, 0.9, 1);+ for (let i = 0; i < 12; i++) { const a = (i / 12) * Math.PI * 2 + 0.15, r0 = 80, r1 = 106 + (i % 2) * 16; line(g, [[150 + Math.cos(a) * r0, 140 + Math.sin(a) * r0], [150 + Math.cos(a) * (r0 + r1) / 2, 140 + Math.sin(a) * (r0 + r1) / 2 + 2], [150 + Math.cos(a) * r1, 140 + Math.sin(a) * r1]], K.yellow, 2.4, 24 + i, 0.95, 1.2); }+ });+ // clouds: the paper left bare, a grey-blue crayon under their bellies, a blue outline+ const cloud = (cx: number, cy: number, s: number, seed: number) => {+ const r = rng(seed), puffs: P[][] = [];+ for (let i = 0; i < 6; i++) puffs.push(blob(cx + (i - 2.5) * 32 * s + (r() - 0.5) * 10, cy - Math.sin((i / 5) * Math.PI) * 28 * s + (r() - 0.5) * 8, (34 + r() * 16) * s, (28 + r() * 10) * s, seed + i, 0.08, 12));+ wax(g, () => {+ puffs.forEach((p) => fillShape(g, p, PAPER));+ puffs.forEach((p, i) => scribble(g, p, "#b9cde6", { angle: 0.2, gap: 6, w: 4.5, alpha: 0.55, seed: seed + 10 + i, keep: (x, y) => y > cy + 4 * s }));+ puffs.forEach((p, i) => {+ // walk this puff's edge and keep only the stretches no other puff covers: the silhouette+ let run: P[] = []; const runs: P[][] = [];+ p.forEach((q) => { const hidden = puffs.some((o, j) => j !== i && inside(o, q[0], q[1])); if (!hidden) run.push(q); else if (run.length) { runs.push(run); run = []; } });+ if (run.length) runs.push(run);+ runs.filter((r2) => r2.length > 3).forEach((r2, k) => line(g, r2.filter((_, m) => m % 3 === 0 || m === r2.length - 1), "#7fa9d8", 1.5, seed + 20 + i * 5 + k, 0.8, 0.9));+ });+ });+ };+ cloud(250, 470, 1.0, 40); cloud(870, 150, 0.85, 60); cloud(930, 560, 0.7, 80);+ // a second balloon, far off: fewer gores, softer, smaller+ wax(g, () => {+ const cx = 868, cy = 318, r = 44, env: P[] = [];+ const prof = smooth([[0, cy - r], [r * 0.87, cy - r * 0.5], [r, cy], [r * 0.7, cy + r * 0.85], [r * 0.22, cy + r * 1.35]], false, 8);+ const m = (ph: number) => prof.map(([w, y]) => [cx + w * Math.sin(ph), y] as P);+ for (let k = 0; k < 6; k++) { const a = m(-Math.PI / 2 + (k / 6) * Math.PI), b2 = m(-Math.PI / 2 + ((k + 1) / 6) * Math.PI), gore = [...a, ...[...b2].reverse()]; fillShape(g, gore, PAPER); scribble(g, gore, [K.pink, K.yellow, K.sky][k % 3], { angle: 1.3, gap: 4, w: 3.6, alpha: 0.75, seed: 90 + k }); env.push(...a); }+ line(g, m(-Math.PI / 2).filter((_, i) => i % 3 === 0), "#5a4a6a", 1.1, 97, 0.8, 0.6); line(g, m(Math.PI / 2).filter((_, i) => i % 3 === 0), "#5a4a6a", 1.1, 98, 0.8, 0.6);+ const bx = cx, by = cy + r * 1.35 + 16; fillShape(g, [[bx - 9, by], [bx + 9, by], [bx + 7, by + 11], [bx - 7, by + 11]], K.brown);+ line(g, [[cx - r * 0.2, cy + r * 1.35], [bx - 8, by]], "#5a4a6a", 0.7, 99, 0.7, 0.3); line(g, [[cx + r * 0.2, cy + r * 1.35], [bx + 8, by]], "#5a4a6a", 0.7, 100, 0.7, 0.3);+ });+ // birds+ wax(g, () => [[700, 170, 1], [742, 196, 0.8], [668, 214, 0.7]].forEach(([x, y, s], i) => line(g, [[x - 14 * s, y - 5 * s], [x - 5 * s, y - 2 * s], [x, y + 3 * s], [x + 5 * s, y - 2 * s], [x + 14 * s, y - 6 * s]], "#3a3450", 1.3, 110 + i, 0.9, 0.5)));+};++const land = (g: Gfx) => {+ const back: P[] = smooth([[0, 900], [180, 868], [420, 884], [700, 852], [900, 866], [1080, 846], [1080, 1080], [0, 1080]], true, 10);+ const front: P[] = smooth([[0, 968], [220, 930], [480, 958], [760, 936], [1080, 972], [1080, 1080], [0, 1080]], true, 10);+ wax(g, () => {+ fillShape(g, back, PAPER); scribble(g, back, "#8ccf5a", { angle: 0.15, gap: 5.5, w: 6, alpha: 0.9, seed: 400, over: 1 }); scribble(g, back, K.green, { angle: -0.4, gap: 8, w: 5, alpha: 0.5, seed: 401, over: 1, keep: (x, y) => y > 890 + Math.sin(x * 0.01) * 12 });+ line(g, back.filter((_, i) => i % 4 === 0 && back[i][1] < 1000), "#2f7a33", 1.8, 402, 0.85, 1);+ // trees on the far hill: round crowns on stubby trunks, each shaded on its right+ [[160, 872, 1], [214, 880, 0.8], [760, 858, 0.9], [982, 852, 1.1]].forEach(([x, y, s], i) => {+ line(g, [[x, y + 2], [x + 1, y - 18 * s]], K.brown, 2.2, 410 + i, 0.95, 0.4);+ const c = blob(x, y - 34 * s, 22 * s, 24 * s, 420 + i, 0.12, 12);+ fillShape(g, c, PAPER); scribble(g, c, K.green, { angle: 1.1, gap: 4, w: 4.5, alpha: 0.9, seed: 430 + i }); scribble(g, c, K.leaf, { angle: 0.3, gap: 5, w: 3.6, alpha: 0.7, seed: 440 + i, keep: (xx) => xx > x + 2 });+ line(g, c.filter((_, k) => k % 3 === 0), "#1f5a28", 1.4, 450 + i, 0.85, 0.8);+ });+ fillShape(g, front, PAPER); scribble(g, front, K.green, { angle: -0.12, gap: 5, w: 6.5, alpha: 0.92, seed: 460, over: 1 }); scribble(g, front, K.leaf, { angle: 0.5, gap: 7, w: 5, alpha: 0.55, seed: 461, over: 1, keep: (x, y) => y > 985 });+ // a winding path, and grass flicked up along the hill's edge+ const path = smooth([[610, 1080], [560, 1030], [620, 990], [590, 950]], false, 10);+ const pw: P[] = [...path.map(([x, y], i) => [x - 22 + i * 0.35, y] as P), ...path.map(([x, y], i) => [x + 22 - i * 0.35, y] as P).reverse()];+ scribble(g, pw, "#f3c77a", { angle: 0.2, gap: 4, w: 4.5, alpha: 0.9, seed: 462, over: 1 });+ line(g, front.filter((_, i) => i % 4 === 0 && front[i][1] < 1060), "#1f5a28", 2, 463, 0.9, 1);+ const r = rng(464); for (let i = 0; i < 70; i++) { const x = r() * 1080, y = 940 + r() * 130; line(g, [[x, y], [x + 2, y - 6 - r() * 7]], K.leaf, 1.1, 470 + i, 0.8, 0.3); }+ });+};++export const drawBalloon = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, CRAYON_M);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, 1080, 1080);+ sky(g); land(g); envelope(g); rigging(g);+ g.paper("paper", 0.08);+};++export const balloon: Film = {+ meta: { title: "Hot-air balloon · crayon", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "balloon", start: 0, end: 1, draw: drawBalloon }],+};+void lerpP;diff --git a/engine/src/canvas-core/core.ts b/engine/src/canvas-core/core.tsnew file mode 100644index 0000000..f2e290c--- /dev/null+++ b/engine/src/canvas-core/core.ts@@ -0,0 +1,251 @@+// PORTABLE ART CORE, phase 0. Plain TypeScript: no React, no Remotion, no DOM, no SVG,+// and no ctx.filter of any kind. Everything a host must supply is in `Env`.+//+// Contract: draw(ctx, frame, env) is a pure function of (frame, env). Randomness only+// from rng(seed). Texture = seeded, tileable noise composited per layer. Edge wobble+// and wet-edge displacement are baked into GEOMETRY, never applied as a filter.++export type P = [number, number];+export type Ctx = CanvasRenderingContext2D;+export type Layer = { canvas: CanvasImageSource & { width: number; height: number }; ctx: Ctx };+export type Env = {+ W: number; H: number; scale: number; // logical size, device pixels per logical pixel+ canvas(w: number, h: number): Layer; // the ONLY way the core obtains an offscreen surface+ image?(name: string): CanvasImageSource | undefined; // assets are decoded by the ADAPTER before frame 0+ cache: Map<string, unknown>;+};++// ---------------------------------------------------------------- deterministic randomness+export const rng = (seed: number) => {+ let a = seed >>> 0;+ return () => { a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };+};++// Gradient noise, optionally periodic so a tile repeats without a seam. fractal() mirrors+// the shape of SVG fractalNoise: sum of octaves at halving amplitude, mapped to 0..1.+const noiseCache = new Map<number, { perm: Uint16Array; gx: Float32Array; gy: Float32Array }>();+const table = (seed: number) => {+ let t = noiseCache.get(seed);+ if (!t) { const r = rng(seed * 7919 + 13), perm = new Uint16Array(512), gx = new Float32Array(256), gy = new Float32Array(256); const p = Array.from({ length: 256 }, (_, i) => i); for (let i = 255; i > 0; i--) { const j = Math.floor(r() * (i + 1)); [p[i], p[j]] = [p[j], p[i]]; } for (let i = 0; i < 512; i++) perm[i] = p[i & 255]; for (let i = 0; i < 256; i++) { const a = r() * Math.PI * 2; gx[i] = Math.cos(a); gy[i] = Math.sin(a); } t = { perm, gx, gy }; noiseCache.set(seed, t); }+ return t;+};+const noise2 = (seed: number, x: number, y: number, px = 0, py = 0): number => {+ const { perm, gx, gy } = table(seed);+ const x0 = Math.floor(x), y0 = Math.floor(y), fx = x - x0, fy = y - y0;+ const w = (v: number, p: number) => (p > 0 ? ((v % p) + p) % p : v) & 255;+ const g = (ix: number, iy: number, dx: number, dy: number) => { const h = perm[perm[w(ix, px)] + w(iy, py)]; return gx[h] * dx + gy[h] * dy; };+ const sx = fx * fx * (3 - 2 * fx), sy = fy * fy * (3 - 2 * fy);+ const a = g(x0, y0, fx, fy), b = g(x0 + 1, y0, fx - 1, fy), c = g(x0, y0 + 1, fx, fy - 1), d = g(x0 + 1, y0 + 1, fx - 1, fy - 1);+ return a + sx * (b - a) + sy * (c + sx * (d - c) - (a + sx * (b - a)));+};+export const fractal = (seed: number, x: number, y: number, fx: number, fy: number, oct: number, tile = 0): number => {+ let sum = 0, amp = 1, px = tile ? Math.max(1, Math.round(fx * tile)) : 0, py = tile ? Math.max(1, Math.round(fy * tile)) : 0;+ let kx = tile ? px / tile : fx, ky = tile ? py / tile : fy;+ for (let o = 0; o < oct; o++) { sum += noise2(seed + o * 101, x * kx, y * ky, px, py) * amp; amp *= 0.5; kx *= 2; ky *= 2; px *= 2; py *= 2; }+ return (sum + 1) / 2;+};+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));++// ---------------------------------------------------------------- geometry (ported 1:1 from pencil.tsx)+export const jitter = (pts: P[], amt: number, seed: number): P[] => { if (amt <= 0) return pts; const r = rng(seed); return pts.map(([x, y]) => [x + (r() - 0.5) * 2 * amt, y + (r() - 0.5) * 2 * amt]); };+export const sample = (pts: P[], closed = false, per = 10): P[] => {+ if (pts.length < 2) return pts;+ const n = pts.length, at = (i: number): P => (closed ? pts[((i % n) + n) % n] : pts[Math.max(0, Math.min(n - 1, i))]), out: P[] = [], segs = closed ? n : n - 1;+ for (let i = 0; i < segs; i++) { const [p0, p1, p2, p3] = [at(i - 1), at(i), at(i + 1), at(i + 2)]; for (let k = 0; k < per; k++) { const t = k / per, t2 = t * t, t3 = t2 * t; out.push([0.5 * (2 * p1[0] + (-p0[0] + p2[0]) * t + (2 * p0[0] - 5 * p1[0] + 4 * p2[0] - p3[0]) * t2 + (-p0[0] + 3 * p1[0] - 3 * p2[0] + p3[0]) * t3), 0.5 * (2 * p1[1] + (-p0[1] + p2[1]) * t + (2 * p0[1] - 5 * p1[1] + 4 * p2[1] - p3[1]) * t2 + (-p0[1] + 3 * p1[1] - 3 * p2[1] + p3[1]) * t3)]); } }+ out.push(closed ? out[0] : pts[n - 1]);+ return out;+};+// centreline -> closed ribbon outline. `rough` is the pencil's bite: what the SVG build did with a displacement filter.+// resample a polyline so vertices sit about `step` apart: the edge needs somewhere to be bitten+const densify = (s: P[], step: number): P[] => { const out: P[] = [s[0]]; for (let i = 1; i < s.length; i++) { const a = s[i - 1], b = s[i], n = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1]) / step)); for (let k = 1; k <= n; k++) out.push([a[0] + ((b[0] - a[0]) * k) / n, a[1] + ((b[1] - a[1]) * k) / n]); } return out; };+const ribbon = (s0: P[], width: number, seed: number, taper: number, pressure: number, rough = 0): P[] => {+ const s = rough ? densify(s0, 1.5) : s0;+ const a = (seed % 17) * 0.37, b = (seed % 11) * 0.53, L: P[] = [], R: P[] = [], r = rng(seed * 31 + 7);+ for (let i = 0; i < s.length; i++) {+ const t = i / (s.length - 1), p = s[i], q = s[Math.min(s.length - 1, i + 1)], o = s[Math.max(0, i - 1)], dx = q[0] - o[0], dy = q[1] - o[1], len = Math.hypot(dx, dy) || 1;+ const ends = Math.min(1, t / 0.14, (1 - t) / 0.2), tp = 1 - taper + taper * Math.pow(Math.max(0.04, ends), 0.7);+ const pr = Math.max(0.14, 1 - 0.26 * pressure + pressure * (0.3 * Math.sin(t * 5.5 + a) + 0.14 * Math.sin(t * 17 + b)));+ const w = (width * tp * pr) / 2, j1 = (r() - 0.5) * rough, j2 = (r() - 0.5) * rough;+ L.push([p[0] - (dy / len) * (w + j1), p[1] + (dx / len) * (w + j1)]); R.push([p[0] + (dy / len) * (w + j2), p[1] - (dx / len) * (w + j2)]);+ }+ return [...L, ...R.reverse()];+};+export const oval = (cx: number, cy: number, rx: number, ry = rx, n = 10, a0 = -1.9): P[] => Array.from({ length: n }, (_, i) => { const a = a0 + (i / n) * Math.PI * 2; return [cx + Math.cos(a) * rx, cy + Math.sin(a) * ry] as P; });+export const softBox = (cx: number, cy: number, w: number, h: number, e = 3.2, n = 16): P[] => Array.from({ length: n }, (_, i) => { const a = -2.2 + (i / n) * Math.PI * 2, c = Math.cos(a), s = Math.sin(a), k = 1 / (Math.abs(c) ** e + Math.abs(s) ** e) ** (1 / e); return [cx + (c * k * w) / 2, cy + (s * k * h) / 2] as P; });+export const arc = (cx: number, cy: number, rx: number, ry: number, a0: number, a1: number, n = 6): P[] => Array.from({ length: n }, (_, i) => { const a = a0 + (i / (n - 1)) * (a1 - a0); return [cx + Math.cos(a) * rx, cy + Math.sin(a) * ry] as P; });+export const line = (a: P, b: P, bow = 0): P[] => { const nx = -(b[1] - a[1]), ny = b[0] - a[0], l = Math.hypot(nx, ny) || 1; return [a, [(a[0] + b[0]) / 2 + (nx / l) * bow, (a[1] + b[1]) / 2 + (ny / l) * bow], b]; };+export const turn = (pts: P[], cx: number, cy: number, deg: number): P[] => { const a = (deg * Math.PI) / 180, c = Math.cos(a), s = Math.sin(a); return pts.map(([x, y]) => [cx + (x - cx) * c - (y - cy) * s, cy + (x - cx) * s + (y - cy) * c]); };+export const poly = (corners: P[], per = 3): P[] => corners.flatMap((a, i) => { const b = corners[(i + 1) % corners.length]; return Array.from({ length: per }, (_, k) => [a[0] + ((b[0] - a[0]) * k) / per, a[1] + ((b[1] - a[1]) * k) / per] as P); });+export const heart = (cx: number, cy: number, s: number): P[] => Array.from({ length: 14 }, (_, i) => { const t = (i / 14) * Math.PI * 2; return [cx + s * Math.sin(t) ** 3, cy - (s * (13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t))) / 16] as P; });+export const tube = (centre: P[], r0: number, r1 = r0, cap = true): P[] => {+ const c = sample(centre, false, 5), L: P[] = [], R: P[] = [];+ c.forEach((p, i) => { const q = c[Math.min(c.length - 1, i + 1)], o = c[Math.max(0, i - 1)], dx = q[0] - o[0], dy = q[1] - o[1], len = Math.hypot(dx, dy) || 1, r = r0 + ((r1 - r0) * i) / (c.length - 1); L.push([p[0] - (dy / len) * r, p[1] + (dx / len) * r]); R.push([p[0] + (dy / len) * r, p[1] - (dx / len) * r]); });+ const e = c[c.length - 1], e0 = c[c.length - 2], ex = e[0] - e0[0], ey = e[1] - e0[1], el = Math.hypot(ex, ey) || 1, tip: P[] = cap ? [[e[0] + (ex / el) * r1, e[1] + (ey / el) * r1]] : [], thin = (a: P[]) => a.filter((_, i) => i % 3 === 0 || i === a.length - 1);+ return [...thin(L), ...tip, ...thin(R).reverse()];+};+const bbox = (s: P[]) => { let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; s.forEach(([x, y]) => { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }); return { x0, y0, x1, y1, cx: (x0 + x1) / 2, cy: (y0 + y1) / 2 }; };+const scaled = (s: P[], k: number, dx = 0, dy = 0): P[] => { const b = bbox(s); return s.map(([x, y]) => [b.cx + (x - b.cx) * k + dx, b.cy + (y - b.cy) * k + dy]); };+// Displace geometry by a smooth vector field: the portable stand-in for feDisplacementMap.+export const displace = (pts: P[], amp: number, freq: number, oct: number, seed: number): P[] => pts.map(([x, y]) => [x + (fractal(seed, x, y, freq, freq, oct) - 0.5) * amp, y + (fractal(seed + 50, x, y, freq, freq, oct) - 0.5) * amp]);+export const halftone = (b: { x0: number; y0: number; x1: number; y1: number }, pitch: number, angleDeg: number, tone: (x: number, y: number) => number): [number, number, number][] => {+ const a = (angleDeg * Math.PI) / 180, c = Math.cos(a), sn = Math.sin(a), cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, R = Math.hypot(b.x1 - b.x0, b.y1 - b.y0) / 2 + pitch, out: [number, number, number][] = [];+ for (let u = -R; u <= R; u += pitch) for (let v = -R; v <= R; v += pitch) { const x = cx + u * c - v * sn, y = cy + u * sn + v * c; if (x < b.x0 - pitch || x > b.x1 + pitch || y < b.y0 - pitch || y > b.y1 + pitch) continue; const t = clamp(tone(x, y)); if (t < 0.03) continue; out.push([x, y, pitch * 0.72 * Math.sqrt(t)]); }+ return out;+};++// ---------------------------------------------------------------- texture tiles+const TILE = 512; // logical px; every tile is periodic, so it repeats without a seam+type TileSpec = { fx: number; fy?: number; oct: number; seed: number; k?: number; o?: number; gray?: boolean };+export const TILES: Record<string, TileSpec> = {+ pencilTooth: { fx: 1.3, oct: 1, seed: 8, k: -2.0, o: 2.05 }, // graphite skips the valleys of the sheet+ washGran: { fx: 0.09, oct: 2, seed: 11, k: -0.45, o: 1.2 }, // granulating pigment+ risoSpeck: { fx: 1.15, oct: 2, seed: 18, k: -3.0, o: 2.35 }, // pinholes where soy ink missed+ risoMottle: { fx: 0.012, fy: 0.05, oct: 3, seed: 22, k: -0.9, o: 1.38 }, // the drum never inks evenly+ paper: { fx: 0.75, oct: 3, seed: 21, gray: true },+ coldpress: { fx: 0.16, oct: 4, seed: 23, gray: true },+ draftTooth: { fx: 0.95, oct: 2, seed: 33, k: -1.7, o: 1.95 }, // ruling-pen ink breaking up on the tooth of the sheet+ blueMottle: { fx: 0.0065, oct: 4, seed: 37, gray: true }, // a cyanotype never exposes evenly+};+const tile = (env: Env, kind: string): Layer => {+ const key = `tile:${kind}:${env.scale}`; let L = env.cache.get(key) as Layer | undefined;+ if (L) return L;+ const sp = TILES[kind], n = Math.round(TILE * env.scale); L = env.canvas(n, n);+ const img = L.ctx.createImageData(n, n), d = img.data;+ for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) {+ const lx = x / env.scale, ly = y / env.scale, i = (y * n + x) * 4, v = fractal(sp.seed, lx, ly, sp.fx, sp.fy ?? sp.fx, sp.oct, TILE);+ if (sp.gray) { const lin = clamp((v + fractal(sp.seed + 7, lx, ly, sp.fx, sp.fy ?? sp.fx, sp.oct, TILE)) / 2), g = 255 * (lin <= 0.0031308 ? lin * 12.92 : 1.055 * Math.pow(lin, 1 / 2.4) - 0.055); /* SVG filters work in linearRGB; match that */ d[i] = d[i + 1] = d[i + 2] = g; d[i + 3] = 255; }+ else { d[i] = d[i + 1] = d[i + 2] = 0; d[i + 3] = 255 * clamp(sp.k! * v + sp.o!); }+ }+ L.ctx.putImageData(img, 0, 0); env.cache.set(key, L);+ return L;+};++// ---------------------------------------------------------------- the drawing surface+export type Medium = { nib: number; taper: number; pressure: number; retrace: boolean; wobble: number; rough: number };+export const PENCIL: Medium = { nib: 1.45, taper: 1, pressure: 1, retrace: true, wobble: 1, rough: 1.15 };+export const RISOLINE: Medium = { nib: 1.7, taper: 0.5, pressure: 0.5, retrace: false, wobble: 1.6, rough: 0.9 };+export const GRAPHITE = "#3d3437";+export const TINT = { white: "#fffaf3", blush: "#f2899c", rose: "#e9a3ad", butter: "#f3d577", sky: "#a9c8e6", denim: "#6f93c4", sage: "#a9cfa6", lilac: "#c7b3e0", peach: "#f5b98a", glow: "#ffe9a3" };+type PenOpts = { w?: number; color?: string; seed?: number; closed?: boolean; wobble?: number; boil?: number; taper?: number; opacity?: number; retrace?: boolean; progress?: number };++type Rect = [number, number, number, number]; // device px: x0, y0, x1, y1+type Tracked = Layer & { dirty?: Rect | null };++// PERFORMANCE RULE: nothing here touches a full-size surface unless it has to. Every primitive+// marks the device-pixel box it drew into; blur, texture, compositing and clearing are then+// confined to that box. (Phase 0 cleared and composited whole layers ~150 times per frame.)+export class Gfx {+ cur: Ctx; private pool: Tracked[] = []; private stack: [number, number, number][] = [[0, 0, 1]]; private box: Rect | null = null;+ constructor(public main: Ctx, public env: Env, public frame: number, public medium: Medium) {+ this.cur = main; this.base(main);+ // surfaces outlive the frame: allocating six full-size canvases per frame is pure churn+ const key = `pool:${Math.round(env.W * env.scale)}x${Math.round(env.H * env.scale)}`; let pool = env.cache.get(key) as Tracked[] | undefined; if (!pool) { pool = []; env.cache.set(key, pool); } this.pool = pool;+ }+ private get m() { return this.stack[this.stack.length - 1]; }+ private get DW() { return Math.round(this.env.W * this.env.scale); }+ private get DH() { return Math.round(this.env.H * this.env.scale); }+ private base(c: Ctx) { const [x, y, s] = this.m, k = this.env.scale; c.setTransform(k * s, 0, 0, k * s, k * x, k * y); }+ private dev(c: Ctx) { c.setTransform(1, 0, 0, 1, 0, 0); }+ private clip(r: Rect, pad = 0): Rect { return [Math.max(0, Math.floor(r[0] - pad)), Math.max(0, Math.floor(r[1] - pad)), Math.min(this.DW, Math.ceil(r[2] + pad)), Math.min(this.DH, Math.ceil(r[3] + pad))]; }+ private join(a: Rect | null, b: Rect): Rect { return a ? [Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.max(a[2], b[2]), Math.max(a[3], b[3])] : b; }+ // local points -> device box, with `pad` local units of slack (line weight, displacement, blur)+ private boxOf(pts: P[], pad: number): Rect { const [tx, ty, s] = this.m, k = this.env.scale; let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; for (const [x, y] of pts) { if (x < x0) x0 = x; if (y < y0) y0 = y; if (x > x1) x1 = x; if (y > y1) y1 = y; } return this.clip([k * (tx + (x0 - pad) * s), k * (ty + (y0 - pad) * s), k * (tx + (x1 + pad) * s), k * (ty + (y1 + pad) * s)]); }+ mark(pts: P[], pad = 4) { this.box = this.join(this.box, this.boxOf(pts, pad)); }+ touch(x0: number, y0: number, x1: number, y1: number) { this.mark([[x0, y0], [x1, y1]], 0); } // for raw ctx drawing inside a group+ layer(): Tracked { let L = this.pool.pop(); if (!L) { L = this.env.canvas(this.DW, this.DH) as Tracked; L.dirty = null; } this.dev(L.ctx); L.ctx.globalCompositeOperation = "source-over"; L.ctx.globalAlpha = 1; if (L.dirty) { const d = L.dirty; L.ctx.clearRect(d[0], d[1], d[2] - d[0], d[3] - d[1]); L.dirty = null; } return L; }+ release(L: Tracked, dirty: Rect | null) { L.dirty = dirty ? this.join(L.dirty ?? null, dirty) : L.dirty; this.pool.push(L); }+ push(x: number, y: number, s: number) { const [px, py, ps] = this.m; this.stack.push([px + x * ps, py + y * ps, ps * s]); this.base(this.cur); }+ pop() { this.stack.pop(); this.base(this.cur); }++ path(c: Ctx, pts: P[]) { c.beginPath(); pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); }+ // gaussian-ish blur without ctx.filter (Safari has none): halve the box N times, scale it back up+ soften(L: Tracked, radius: number, r: Rect): Rect {+ const rp = this.clip(r, radius * this.env.scale * 3), steps = Math.max(1, Math.round(Math.log2(Math.max(2, radius * this.env.scale * 1.6)))), T = this.layer(), U = this.layer();+ let w = rp[2] - rp[0], h = rp[3] - rp[1]; if (w < 2 || h < 2) { this.release(T, null); this.release(U, null); return rp; }+ const sizes: [number, number][] = [[w, h]]; let src: Tracked = L, sx = rp[0], sy = rp[1], a = T, b = U;+ for (let i = 0; i < steps; i++) { const nw = Math.max(1, Math.ceil(w / 2)), nh = Math.max(1, Math.ceil(h / 2)); a.ctx.clearRect(0, 0, nw + 1, nh + 1); a.ctx.imageSmoothingEnabled = true; a.ctx.drawImage(src.canvas as CanvasImageSource, sx, sy, w, h, 0, 0, nw, nh); sizes.push([nw, nh]); src = a; sx = 0; sy = 0; w = nw; h = nh; [a, b] = [b, a]; }+ for (let i = steps - 1; i >= 1; i--) { const [dw, dh] = sizes[i]; a.ctx.clearRect(0, 0, dw + 1, dh + 1); a.ctx.drawImage(src.canvas as CanvasImageSource, 0, 0, w, h, 0, 0, dw, dh); src = a; w = dw; h = dh; [a, b] = [b, a]; }+ this.dev(L.ctx); L.ctx.clearRect(rp[0], rp[1], rp[2] - rp[0], rp[3] - rp[1]); L.ctx.imageSmoothingEnabled = true; L.ctx.drawImage(src.canvas as CanvasImageSource, 0, 0, w, h, rp[0], rp[1], rp[2] - rp[0], rp[3] - rp[1]);+ const used: Rect = [0, 0, sizes[1][0] + 1, sizes[1][1] + 1]; this.release(T, used); this.release(U, used);+ return rp;+ }+ // multiply a layer's alpha by a texture tile, inside the box only (texK scales the tooth with the actor)+ tooth(L: Tracked, kind: string, r: Rect, texK = 1) { const c = L.ctx, t = tile(this.env, kind); c.save(); c.setTransform(texK, 0, 0, texK, 0, 0); c.globalCompositeOperation = "destination-in"; c.fillStyle = c.createPattern(t.canvas as CanvasImageSource, "repeat")!; c.beginPath(); c.rect(r[0] / texK, r[1] / texK, (r[2] - r[0]) / texK, (r[3] - r[1]) / texK); c.clip(); c.fillRect(r[0] / texK - 1, r[1] / texK - 1, (r[2] - r[0]) / texK + 2, (r[3] - r[1]) / texK + 2); c.restore(); }+ // draw a group on its own layer, texture it once, composite only what was touched+ group(kind: "ink" | "paint" | "plain", fn: () => void, opts: { blend?: GlobalCompositeOperation; alpha?: number; off?: P; textures?: string[]; blur?: number } = {}) {+ const L = this.layer(), prev = this.cur, outer = this.box; this.cur = L.ctx; this.box = null; this.base(L.ctx); fn(); this.cur = prev; if (prev !== this.main) this.base(prev);+ let r: Rect = this.box ?? [0, 0, this.DW, this.DH]; this.box = outer; const k = this.m[2];+ if (kind === "paint") { r = this.soften(L, 0.9 * k, r); this.tooth(L, "washGran", r, k); }+ if (kind === "ink") this.tooth(L, "pencilTooth", r, k);+ if (opts.blur) r = this.soften(L, opts.blur, r);+ (opts.textures ?? []).forEach((t) => this.tooth(L, t, r));+ const m = this.main, w = r[2] - r[0], h = r[3] - r[1];+ if (w > 0 && h > 0) { m.save(); this.dev(m); m.globalCompositeOperation = opts.blend ?? "source-over"; m.globalAlpha = opts.alpha ?? 1; m.drawImage(L.canvas as CanvasImageSource, r[0], r[1], w, h, r[0] + Math.round((opts.off?.[0] ?? 0) * this.env.scale), r[1] + Math.round((opts.off?.[1] ?? 0) * this.env.scale), w, h); m.restore(); }+ this.release(L, r);+ }++ // INK IN ONE PASS. White ink on a blue ground blooms, so every line wants a soft halo under it.+ // Drawing the group twice (halo, then line) costs the strokes twice; this takes the halo from a+ // blurred COPY of the same ink instead, which is the same picture for half the stroke work.+ inkGroup(fn: () => void, o: { blur?: number; alpha?: number; textures?: string[] } = {}) {+ const L = this.layer(), prev = this.cur, outer = this.box; this.cur = L.ctx; this.box = null; this.base(L.ctx); fn(); this.cur = prev; if (prev !== this.main) this.base(prev);+ const r: Rect = this.box ?? [0, 0, this.DW, this.DH]; this.box = outer;+ const w = r[2] - r[0], h = r[3] - r[1]; if (w <= 0 || h <= 0) { this.release(L, r); return; }+ const H = this.layer(), pad = this.clip(r, (o.blur ?? 1.8) * this.env.scale * 3);+ this.dev(H.ctx); H.ctx.drawImage(L.canvas as CanvasImageSource, r[0], r[1], w, h, r[0], r[1], w, h);+ const rh = this.soften(H, o.blur ?? 1.8, r);+ (o.textures ?? ["draftTooth"]).forEach((t) => this.tooth(L, t, r));+ const m = this.main; m.save(); this.dev(m); m.globalCompositeOperation = "source-over";+ m.globalAlpha = o.alpha ?? 0.28; m.drawImage(H.canvas as CanvasImageSource, rh[0], rh[1], rh[2] - rh[0], rh[3] - rh[1], rh[0], rh[1], rh[2] - rh[0], rh[3] - rh[1]);+ m.globalAlpha = 1; m.drawImage(L.canvas as CanvasImageSource, r[0], r[1], w, h, r[0], r[1], w, h); m.restore(); this.base(m);+ this.release(L, r); this.release(H, pad);+ }++ // progress < 1 draws the first part of the stroke only, cut on the CENTRELINE so the travelling+ // tip keeps the taper of a lifting nib. progress 1 takes the old path, byte for byte.+ private upTo(s: P[], progress: number): P[] {+ if (progress >= 1) return s; const n = (s.length - 1) * progress, i = Math.floor(n), f = n - i;+ const head = s.slice(0, i + 1); if (f > 1e-9 && i + 1 < s.length) head.push([s[i][0] + (s[i + 1][0] - s[i][0]) * f, s[i][1] + (s[i + 1][1] - s[i][1]) * f]);+ return head.length > 1 ? head : s.slice(0, 2);+ }+ pen(pts: P[], o: PenOpts = {}) {+ const { w = 3.4, color = GRAPHITE, seed = 1, closed = false, wobble = 1.1, boil = 0.55, taper = 1, opacity = 0.96, retrace = true, progress = 1 } = o, M = this.medium, b = Math.floor(this.frame / 4), c = this.cur;+ if (progress <= 0) return;+ const ctrl = closed ? [...pts, pts[0], pts[1]] : pts, basePts = jitter(ctrl, wobble * M.wobble, seed), W = w * M.nib;+ const main = ribbon(this.upTo(sample(jitter(basePts, boil, seed * 911 + b)), progress), W, seed, taper * M.taper, M.pressure, M.rough); this.mark(main, 2);+ c.fillStyle = color; c.globalAlpha = opacity; this.path(c, main); c.fill();+ if (retrace && M.retrace) { const re = ribbon(this.upTo(sample(jitter(basePts, boil + 1.3 * M.wobble, seed * 577 + b)), progress), W * 0.5, seed + 5, 1, M.pressure, M.rough); this.mark(re, 2); c.globalAlpha = opacity * 0.4; this.path(c, re); c.fill(); }+ c.globalAlpha = 1;+ }+ hatch(x: number, y: number, w: number, o: { n?: number; len?: number; angle?: number; color?: string; seed?: number; pw?: number; opacity?: number } = {}) {+ const { n = 8, len = 16, angle = -1.05, color = GRAPHITE, seed = 1, pw = 1.9, opacity = 0.55 } = o, r = rng(seed);+ for (let i = 0; i < n; i++) { const px = x + (w * i) / Math.max(1, n - 1) + (r() - 0.5) * 3, l = len * (0.7 + r() * 0.6), a = angle + (r() - 0.5) * 0.18; this.pen([[px, y], [px + Math.cos(a) * l * 0.5, y + Math.sin(a) * l * 0.5], [px + Math.cos(a) * l, y + Math.sin(a) * l]], { w: pw, color, seed: seed + i, wobble: 0.6, opacity, retrace: false }); }+ }+ // a plain filled shape (for media that cut or print rather than paint)+ fill(pts: P[], color: string, alpha = 1) { const c = this.cur; this.mark(pts, 2); c.globalAlpha = alpha; c.fillStyle = color; this.path(c, pts); c.fill(); c.globalAlpha = 1; }+ // watercolour that never quite fills its outline; the wet edge is displaced GEOMETRY+ wash(pts: P[], color: string, o: { alpha?: number; seed?: number; dx?: number; dy?: number; shrink?: number; rim?: boolean } = {}) {+ const { alpha = 0.62, seed = 1, dx = 3, dy = 2, shrink = 0.94, rim = true } = o, c = this.cur;+ const s = displace(scaled(sample(jitter(pts, 2.2, seed), true, 8), shrink, dx, dy), 13, 0.022, 3, 5); this.mark(s, 5);+ c.globalAlpha = alpha; c.fillStyle = color; this.path(c, s); c.fill();+ if (rim) { c.globalAlpha = alpha * 0.55; c.strokeStyle = color; c.lineWidth = 3.5; c.lineJoin = "round"; c.stroke(); } // pigment settles at the edge+ c.globalAlpha = 1;+ }+ // a shaded form: shadow colour underneath, the lit colour shifted toward the light (one soft pass, one crisp), a lifted highlight+ form(pts: P[], color: string, shade: string, o: { seed?: number; light?: P; alpha?: number; hi?: number[] } = {}) {+ const { seed = 1, light = [-8, -9], alpha = 0.98, hi } = o, s = displace(sample(jitter(pts, 1.2, seed), true, 8), 13, 0.022, 3, 5), k = this.m[2];+ const r = this.boxOf(s, 3); this.box = this.join(this.box, r);+ const T = this.layer(); this.base(T.ctx); T.ctx.fillStyle = shade; this.path(T.ctx, s); T.ctx.fill();+ const U = this.layer(); this.base(U.ctx); U.ctx.fillStyle = color; U.ctx.translate(light[0], light[1]); this.path(U.ctx, s); U.ctx.fill(); const ru = this.soften(U, 5 * k, this.boxOf(s.map(([x, y]) => [x + light[0], y + light[1]] as P), 2));+ const w = r[2] - r[0], h = r[3] - r[1];+ T.ctx.save(); this.base(T.ctx); this.path(T.ctx, s); T.ctx.clip(); this.dev(T.ctx); T.ctx.drawImage(U.canvas as CanvasImageSource, r[0], r[1], w, h, r[0], r[1], w, h); this.base(T.ctx); T.ctx.translate(light[0] * 2.2, light[1] * 2.2); T.ctx.fillStyle = color; this.path(T.ctx, s); T.ctx.fill();+ if (hi) { const V = this.layer(); this.base(V.ctx); V.ctx.fillStyle = "#ffffff"; V.ctx.globalAlpha = 0.75; V.ctx.beginPath(); V.ctx.ellipse(hi[0], hi[1], hi[2], hi[3], ((hi[4] ?? -30) * Math.PI) / 180, 0, Math.PI * 2); V.ctx.fill(); const m = Math.max(hi[2], hi[3]); const rv = this.soften(V, 5 * k, this.boxOf([[hi[0] - m, hi[1] - m], [hi[0] + m, hi[1] + m]], 1)); this.dev(T.ctx); T.ctx.drawImage(V.canvas as CanvasImageSource, rv[0], rv[1], rv[2] - rv[0], rv[3] - rv[1], rv[0], rv[1], rv[2] - rv[0], rv[3] - rv[1]); this.release(V, rv); }+ T.ctx.restore();+ const c = this.cur; c.save(); this.dev(c); c.globalAlpha = alpha; c.drawImage(T.canvas as CanvasImageSource, r[0], r[1], w, h, r[0], r[1], w, h); c.restore(); this.base(c);+ this.release(T, r); this.release(U, ru);+ }+ glow(cx: number, cy: number, r: number, color: string, opacity: number) { const c = this.cur, g = c.createRadialGradient(cx, cy, 0, cx, cy, r * 1.7), a = (v: number) => Math.round(255 * clamp(v * opacity)).toString(16).padStart(2, "0"); [[0, 1], [0.35, 0.9], [0.6, 0.55], [0.8, 0.2], [1, 0]].forEach(([t, v]) => g.addColorStop(t, color + a(v))); this.touch(cx - r * 1.8, cy - r * 1.8, cx + r * 1.8, cy + r * 1.8); c.fillStyle = g; c.fillRect(cx - r * 2, cy - r * 2, r * 4, r * 4); }+ // the sheet itself, over everything+ paper(kind: string, opacity: number) { const m = this.main, t = tile(this.env, kind); m.save(); this.dev(m); m.globalCompositeOperation = "multiply"; m.globalAlpha = opacity; m.fillStyle = m.createPattern(t.canvas as CanvasImageSource, "repeat")!; m.fillRect(0, 0, this.DW, this.DH); m.restore(); this.base(m); }+ vignette(edge: string) { const m = this.main, W = this.env.W, H = this.env.H; m.save(); this.base(m); m.translate(W / 2, H * 0.46); m.scale(1, H / W); const g = m.createRadialGradient(0, 0, 0, 0, 0, W * 0.72); g.addColorStop(0, "rgba(255,250,240,0.08)"); g.addColorStop(0.45, "rgba(255,250,240,0)"); g.addColorStop(1, edge); m.fillStyle = g; m.fillRect(-W, -H, W * 2, H * 2); m.restore(); }+}diff --git a/engine/src/canvas-core/drafting.ts b/engine/src/canvas-core/drafting.tsnew file mode 100644index 0000000..9bcb6d3--- /dev/null+++ b/engine/src/canvas-core/drafting.ts@@ -0,0 +1,49 @@+// A DRAFTSMAN'S HAND. Single-stroke inclined gothic capitals, the lettering every engineering+// drawing was titled in before CAD. Drawn as pen strokes, so it needs no font and works under+// every backend. `l` strokes are straight polylines (kept straight, split per segment so the+// pen's smoothing cannot round a vertex); `c` strokes are curves.+import { Gfx, P, rng } from "./core";++type Glyph = { l?: P[][]; c?: P[][]; w?: number };+const O: P[] = [[1.3, 0.1], [0.2, 1.3], [0.2, 4.7], [1.3, 5.9], [2.7, 5.9], [3.8, 4.7], [3.8, 1.3], [2.7, 0.1], [1.3, 0.1]];+const G: Record<string, Glyph> = {+ A: { l: [[[0, 6], [2, 0], [4, 6]], [[0.9, 3.9], [3.1, 3.9]]] }, B: { l: [[[0, 0], [0, 6]]], c: [[[0, 0], [2.6, 0], [3.5, 0.8], [3.5, 2.2], [2.6, 3], [0, 3]], [[2.6, 3], [3.8, 3.8], [3.8, 5.1], [2.8, 6], [0, 6]]] },+ C: { c: [[[3.8, 1.2], [2.8, 0.1], [1.3, 0.1], [0.2, 1.3], [0.2, 4.7], [1.3, 5.9], [2.8, 5.9], [3.8, 4.8]]] }, D: { l: [[[0, 0], [0, 6]]], c: [[[0, 0], [2.3, 0], [3.8, 1.5], [3.8, 4.5], [2.3, 6], [0, 6]]] },+ E: { l: [[[3.6, 0], [0, 0], [0, 6], [3.7, 6]], [[0, 3], [2.8, 3]]] }, F: { l: [[[3.6, 0], [0, 0], [0, 6]], [[0, 3], [2.8, 3]]] },+ G: { c: [[[3.8, 1.2], [2.8, 0.1], [1.3, 0.1], [0.2, 1.3], [0.2, 4.7], [1.3, 5.9], [2.8, 5.9], [3.8, 4.8]]], l: [[[3.8, 4.9], [3.8, 3.2], [2.2, 3.2]]] },+ H: { l: [[[0, 0], [0, 6]], [[4, 0], [4, 6]], [[0, 3], [4, 3]]] }, I: { l: [[[1, 0], [1, 6]]], w: 2 }, J: { c: [[[3.4, 0], [3.4, 4.8], [2.4, 5.9], [1.2, 5.9], [0.2, 4.8]]] },+ K: { l: [[[0, 0], [0, 6]], [[3.8, 0], [0, 3.7]], [[1.4, 2.5], [3.9, 6]]] }, L: { l: [[[0, 0], [0, 6], [3.6, 6]]] }, M: { l: [[[0, 6], [0, 0], [2.3, 3.8], [4.6, 0], [4.6, 6]]], w: 4.6 },+ N: { l: [[[0, 6], [0, 0], [4, 6], [4, 0]]] }, O: { c: [O] }, P: { l: [[[0, 0], [0, 6]]], c: [[[0, 0], [2.7, 0], [3.7, 0.9], [3.7, 2.4], [2.7, 3.3], [0, 3.3]]] },+ Q: { c: [O], l: [[[2.4, 4.2], [4.1, 6.3]]] }, R: { l: [[[0, 0], [0, 6]], [[2, 3.3], [3.9, 6]]], c: [[[0, 0], [2.7, 0], [3.7, 0.9], [3.7, 2.4], [2.7, 3.3], [0, 3.3]]] },+ S: { c: [[[3.7, 1], [2.7, 0.1], [1.2, 0.1], [0.3, 1], [0.3, 2.1], [1.2, 2.9], [2.8, 3.2], [3.7, 4], [3.7, 5], [2.8, 5.9], [1.2, 5.9], [0.2, 5]]] }, T: { l: [[[0, 0], [4, 0]], [[2, 0], [2, 6]]] },+ U: { c: [[[0, 0], [0, 4.7], [1.2, 5.9], [2.8, 5.9], [4, 4.7], [4, 0]]] }, V: { l: [[[0, 0], [2, 6], [4, 0]]] }, W: { l: [[[0, 0], [1.2, 6], [2.5, 2], [3.8, 6], [5, 0]]], w: 5 },+ X: { l: [[[0, 0], [4, 6]], [[4, 0], [0, 6]]] }, Y: { l: [[[0, 0], [2, 3.1], [4, 0]], [[2, 3.1], [2, 6]]] }, Z: { l: [[[0, 0], [4, 0], [0, 6], [4, 6]]] },+ "0": { c: [[[1.3, 0.1], [0.4, 1.2], [0.4, 4.8], [1.3, 5.9], [2.5, 5.9], [3.4, 4.8], [3.4, 1.2], [2.5, 0.1], [1.3, 0.1]]], w: 3.6 }, "1": { l: [[[0.6, 1.2], [1.8, 0], [1.8, 6]]], w: 2.6 },+ "2": { c: [[[0.3, 1.3], [1.1, 0.2], [2.7, 0.2], [3.5, 1.1], [3.5, 2.2], [0.3, 6]]], l: [[[0.3, 6], [3.7, 6]]], w: 3.7 }, "3": { c: [[[0.4, 0.9], [1.3, 0.1], [2.8, 0.1], [3.5, 1], [3.5, 2.1], [2.6, 3], [1.7, 3]], [[2.6, 3], [3.7, 3.8], [3.7, 5.1], [2.8, 5.9], [1.2, 5.9], [0.3, 5.1]]], w: 3.7 },+ "4": { l: [[[2.8, 6], [2.8, 0], [0.1, 4.3], [3.9, 4.3]]], w: 3.9 }, "5": { l: [[[3.5, 0], [0.7, 0], [0.4, 2.8]]], c: [[[0.4, 2.8], [2.5, 2.5], [3.6, 3.6], [3.6, 5], [2.7, 5.9], [1, 5.9], [0.2, 5.1]]], w: 3.7 },+ "6": { c: [[[3.2, 0.4], [1.5, 0.2], [0.4, 1.4], [0.3, 4.7], [1.2, 5.9], [2.6, 5.9], [3.5, 5], [3.5, 3.8], [2.6, 2.9], [1.2, 2.9], [0.3, 3.8]]], w: 3.7 }, "7": { l: [[[0.3, 0], [3.6, 0], [1.5, 6]]], w: 3.6 },+ "8": { c: [[[1.9, 0.1], [3, 0.4], [3.5, 1.3], [3.3, 2.2], [1.9, 3], [0.5, 2.2], [0.3, 1.3], [0.8, 0.4], [1.9, 0.1]], [[1.9, 3], [3.4, 3.7], [3.7, 4.6], [3.3, 5.5], [1.9, 5.9], [0.5, 5.5], [0.1, 4.6], [0.4, 3.7], [1.9, 3]]], w: 3.8 },+ "9": { c: [[[3.5, 2.5], [2.6, 3.2], [1.2, 3.2], [0.3, 2.3], [0.3, 1.1], [1.2, 0.1], [2.6, 0.1], [3.5, 1.1], [3.5, 4.6], [2.5, 5.8], [0.7, 5.8]]], w: 3.7 },+ "-": { l: [[[0.6, 3.2], [3, 3.2]]], w: 3.4 }, ".": { l: [[[0.7, 5.5], [0.9, 5.9]]], w: 1.8 }, ",": { l: [[[0.9, 5.4], [0.5, 6.8]]], w: 1.8 }, ":": { l: [[[0.7, 2], [0.9, 2.4]], [[0.7, 5.4], [0.9, 5.8]]], w: 1.8 }, "/": { l: [[[0.2, 6.4], [3.2, -0.2]]], w: 3.4 },+ "(": { c: [[[2, -0.4], [0.8, 1.6], [0.8, 4.6], [2, 6.6]]], w: 2.4 }, ")": { c: [[[0.4, -0.4], [1.6, 1.6], [1.6, 4.6], [0.4, 6.6]]], w: 2.4 }, "&": { c: [[[3.8, 6], [0.9, 1.9], [1, 0.7], [2, 0.1], [2.9, 0.8], [2.7, 1.9], [0.5, 3.8], [0.4, 5], [1.4, 5.9], [2.6, 5.7], [3.9, 3.6]]], w: 4 },+ x: { l: [[[0.5, 1.8], [3.1, 4.8]], [[3.1, 1.8], [0.5, 4.8]]], w: 3.6 }, o: { c: [[[1.2, -0.2], [0.4, 0.5], [0.5, 1.5], [1.3, 2], [2.1, 1.4], [2.1, 0.4], [1.2, -0.2]]], w: 2.8 }, // x = times, o = degree+ "@": { c: [O], l: [[[0, 6.6], [4, -0.6]]] }, // diameter+ " ": { w: 2.6 },+};+export type LetterOpts = { cap?: number; color?: string; seed?: number; align?: "left" | "center" | "right"; w?: number; opacity?: number; track?: number; progress?: number };+const strokes = (ch: string): number => { const g = G[ch] ?? G[ch.toUpperCase()] ?? G["-"]; return (g.l ?? []).reduce((a, st) => a + st.length - 1, 0) + (g.c ?? []).length; };+export const strokeCount = (text: string): number => [...text].reduce((a, ch) => a + strokes(ch), 0);+export const width = (text: string, cap = 12, track = 1.25) => { const s = cap / 6; return [...text].reduce((a, ch) => a + ((G[ch] ?? G[ch.toUpperCase()] ?? G["-"]).w ?? 4) * s + track * s, 0) - track * s; };+// progress writes the line stroke by stroke, in the order a hand makes them: never a fade.+export const letter = (g: Gfx, text: string, x: number, y: number, o: LetterOpts = {}) => {+ const { cap = 12, color = "#eef6fb", seed = 1, align = "left", opacity = 0.95, track = 1.25, progress = 1 } = o, s = cap / 6, r = rng(seed * 131 + 7), W = width(text, cap, track);+ if (progress <= 0) return;+ let cx = align === "center" ? x - W / 2 : align === "right" ? x - W : x, written = progress >= 1 ? Infinity : progress * strokeCount(text);+ [...text].forEach((ch0, i) => {+ const gl = G[ch0] ?? G[ch0.toUpperCase()] ?? G["-"], dy = (r() - 0.5) * cap * 0.07, k = 1 + (r() - 0.5) * 0.06;+ const T = ([px, py]: P): P => [cx + (px + (6 - py) * 0.2) * s * k, y + dy + py * s * k]; // 0.2 = the 68 degree slant of inclined lettering+ const pen = (pts: P[], j: number) => { const p = written === Infinity ? 1 : Math.max(0, Math.min(1, written)); written === Infinity || (written -= 1); if (p > 0) g.pen(pts.map(T), { w: o.w ?? Math.max(1.1, cap * 0.115), color, seed: seed + i * 37 + j * 11, wobble: 0.25, boil: 0, taper: 0.35, opacity, progress: p }); };+ let j = 0; (gl.l ?? []).forEach((st) => { for (let q = 1; q < st.length; q++) pen([st[q - 1], st[q]], j++); }); (gl.c ?? []).forEach((st) => pen(st, j++));+ cx += ((gl.w ?? 4) + track) * s;+ });+};diff --git a/engine/src/canvas-core/film.ts b/engine/src/canvas-core/film.tsnew file mode 100644index 0000000..37c6847--- /dev/null+++ b/engine/src/canvas-core/film.ts@@ -0,0 +1,32 @@+// FILM RUNTIME. A film is data: meta, an asset manifest, and shots that tile [0, duration).+// renderFrame(film, ctx, frame, env) is the whole contract between the art and any backend.+import type { Ctx, Env } from "./core";++export type Shot = { id: string; start: number; end: number; draw: (ctx: Ctx, local: number, env: Env) => void }; // frames, end exclusive+export type Assets = { images: Record<string, string>; fonts?: Record<string, string> }; // name -> url (the page build inlines them)+export type Film = { meta: { title: string; W: number; H: number; fps: number; bpm: number; durationFrames: number }; assets: Assets; shots: Shot[]; audio?: (sampleRate: number) => [Float32Array, Float32Array] };++// Cheap structural checks every adapter runs before frame 0. (The full gate is Phase 2.)+export const validate = (film: Film): string[] => {+ const p: string[] = [], { fps, bpm, durationFrames } = film.meta, beat = (60 / bpm) * fps, ids = new Set<string>();+ if (!Number.isInteger(beat)) p.push(`bpm ${bpm} at ${fps} fps gives a ${beat}-frame beat: cuts cannot sit on whole frames`);+ let t = 0;+ [...film.shots].sort((a, b) => a.start - b.start).forEach((s) => {+ if (ids.has(s.id)) p.push(`duplicate shot id '${s.id}'`); ids.add(s.id);+ if (s.start !== t) p.push(`shot '${s.id}' starts at ${s.start}, expected ${t} (gap or overlap)`);+ if (s.end <= s.start) p.push(`shot '${s.id}' has no length`);+ if (Number.isInteger(beat) && s.start % beat) p.push(`shot '${s.id}' cuts off the beat grid (frame ${s.start}, beat = ${beat} frames)`);+ t = s.end;+ });+ if (t !== durationFrames) p.push(`shots end at frame ${t}, film is ${durationFrames}`);+ return p;+};++export const shotAt = (film: Film, frame: number): Shot | undefined => film.shots.find((s) => frame >= s.start && frame < s.end);+export const renderFrame = (film: Film, ctx: Ctx, frame: number, env: Env): string | null => {+ const s = shotAt(film, Math.max(0, Math.min(film.meta.durationFrames - 1, Math.round(frame))));+ if (!s) return null;+ ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = 1; ctx.globalCompositeOperation = "source-over"; ctx.clearRect(0, 0, env.W * env.scale, env.H * env.scale);+ s.draw(ctx, frame - s.start, env);+ return s.id;+};diff --git a/engine/src/canvas-core/fox.ts b/engine/src/canvas-core/fox.tsnew file mode 100644index 0000000..f658f4c--- /dev/null+++ b/engine/src/canvas-core/fox.ts@@ -0,0 +1,155 @@+import { Gfx, PENCIL, fractal, rng, type Ctx, type Env, type P } from "./core";+import type { Film } from "./film";+import { blob, bounds, clipped, fillShape, inside, lerpP, mix, resample, smooth } from "./gallery";++// FOX AT DUSK · cut-paper collage. There is not one drawn line in this picture. Every form is a+// piece of coloured paper: TORN pieces show the white fibrous core of the sheet along their edge,+// SCISSOR-cut pieces are crisp; every piece lifts a little off whatever is under it and throws a+// soft shadow; every paper has its own fibres and its own uneven dye. Form is made the way a+// collage artist makes it, by laying a darker paper into the shade and a lighter one where the+// light lands, and fur is made by the torn edge itself.+//+// A red fox sits in a meadow at dusk with its brush curled round its feet: black stockings,+// a cream bib and cheek ruff, black-backed ears, an amber eye with a slit pupil. Pines on the+// hill, the moon rising to the upper left where the light comes from.++const PAPER_CORE = "#fbf5e6", SHADOW = "#3c2814";+type Piece = { shape: P[]; color: string; torn?: number; seed: number; fibre?: number; lift?: number };++// ---------------------------------------------------------------- paper+const normals = (s: P[]): P[] => s.map((_, i) => { const a = s[(i - 1 + s.length) % s.length], b = s[(i + 1) % s.length], dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1; return [dy / l, -dx / l]; });+const ringLen = (s: P[]) => s.reduce((a, p, i) => a + Math.hypot(p[0] - s[(i + 1) % s.length][0], p[1] - s[(i + 1) % s.length][1]), 0);+// a torn edge: the outline resampled finely and bitten in and out by high-frequency noise.+// `grow` pushes it outward: the white core of a torn sheet sticks out past its dyed face.+const tear = (shape: P[], amp: number, seed: number, grow = 0): P[] => {+ const closed = [...shape, shape[0]], n = Math.max(24, Math.round(ringLen(shape) / 2.6)), s = resample(closed, n).slice(0, -1), nr = normals(s), r = rng(seed);+ return s.map(([x, y], i) => { const d = (fractal(seed, x, y, 0.09, 0.09, 3) - 0.5) * amp * 2.2 + (r() - 0.5) * amp * 0.6 + grow; return [x + nr[i][0] * d, y + nr[i][1] * d]; });+};+const cut = (shape: P[], seed: number): P[] => { const s = resample([...shape, shape[0]], Math.max(24, Math.round(ringLen(shape) / 4))).slice(0, -1), r = rng(seed); return s.map(([x, y]) => [x + (r() - 0.5) * 0.7, y + (r() - 0.5) * 0.7]); };++// fibres and uneven dye, clipped to the piece+const fibres = (g: Gfx, shape: P[], color: string, seed: number, density: number) => {+ const b = bounds(shape), r = rng(seed), area = (b.x1 - b.x0) * (b.y1 - b.y0), c = g.cur;+ clipped(g, shape, () => {+ for (let i = 0; i < 5; i++) fillShape(g, blob(b.x0 + r() * (b.x1 - b.x0), b.y0 + r() * (b.y1 - b.y0), 30 + r() * 90, 20 + r() * 60, seed + i, 0.4, 12, r() * 3), r() < 0.5 ? mix(color, "#ffffff", 0.18) : mix(color, "#000000", 0.12), 0.25);+ c.lineCap = "round";+ const n = Math.round((area / 900) * density);+ for (let i = 0; i < n; i++) { const x = b.x0 + r() * (b.x1 - b.x0), y = b.y0 + r() * (b.y1 - b.y0), a = r() * Math.PI, l = 3 + r() * 9; c.strokeStyle = r() < 0.55 ? mix(color, "#fff8e8", 0.45) : mix(color, "#1a0e06", 0.3); c.globalAlpha = 0.25 + r() * 0.3; c.lineWidth = 0.6 + r() * 0.7; c.beginPath(); c.moveTo(x, y); c.quadraticCurveTo(x + Math.cos(a) * l * 0.5 + (r() - 0.5) * 3, y + Math.sin(a) * l * 0.5 + (r() - 0.5) * 3, x + Math.cos(a) * l, y + Math.sin(a) * l); c.stroke(); }+ c.globalAlpha = 1;+ });+};++// one layer of paper: every piece's shadow first (soft, down and right), then the pieces+const layer = (g: Gfx, pieces: Piece[]) => {+ const shapes = pieces.map((p) => (p.torn ? tear(p.shape, p.torn, p.seed) : cut(p.shape, p.seed)));+ g.group("plain", () => pieces.forEach((p, i) => { const l = p.lift ?? 1; fillShape(g, shapes[i].map(([x, y]) => [x + 3 * l, y + 5 * l] as P), SHADOW, 0.5); }), { blur: 4, alpha: 0.55 });+ g.group("plain", () => pieces.forEach((p, i) => {+ if (p.torn) fillShape(g, tear(p.shape, p.torn * 0.8, p.seed + 1, p.torn * 0.7), PAPER_CORE); // the white core where the sheet tore+ fillShape(g, shapes[i], p.color);+ fibres(g, shapes[i], p.color, p.seed + 2, p.fibre ?? 1);+ }));+};+const P0 = (pts: P[], per = 6) => smooth(pts, true, per);++// ---------------------------------------------------------------- the dusk+const sky = (g: Gfx) => {+ layer(g, [{ shape: [[-20, -20], [1100, -20], [1100, 1100], [-20, 1100]], color: "#23485a", seed: 1, fibre: 0.6 }]);+ layer(g, [+ { shape: P0([[-30, 300], [300, 280], [700, 300], [1110, 270], [1110, 1100], [-30, 1100]]), color: "#3d6b74", torn: 3, seed: 2, fibre: 0.5 },+ ]);+ layer(g, [{ shape: P0([[-30, 440], [260, 420], [620, 446], [1110, 418], [1110, 1100], [-30, 1100]]), color: "#b98276", torn: 3.2, seed: 3, fibre: 0.5 }]);+ layer(g, [{ shape: P0([[-30, 520], [400, 506], [800, 526], [1110, 508], [1110, 1100], [-30, 1100]]), color: "#eab58e", torn: 3, seed: 4, fibre: 0.5 }]);+ // the moon, scissor-cut, with two paler scraps laid on it for the seas+ layer(g, [{ shape: Array.from({ length: 40 }, (_, i) => [214 + Math.cos((i / 40) * Math.PI * 2) * 84, 206 + Math.sin((i / 40) * Math.PI * 2) * 84] as P), color: "#f3e3bd", seed: 5, lift: 0.6 }]);+ layer(g, [{ shape: blob(190, 190, 26, 18, 6, 0.2, 10, 0.4), color: "#e2cfa3", torn: 1.2, seed: 6, lift: 0.3 }, { shape: blob(238, 232, 20, 14, 7, 0.25, 10, -0.3), color: "#e2cfa3", torn: 1.2, seed: 7, lift: 0.3 }]);+ // three small stars punched out of gold paper+ layer(g, [[420, 120], [860, 180], [700, 90], [980, 330], [560, 210]].map(([x, y], i) => ({ shape: Array.from({ length: 10 }, (_, k) => { const a = -Math.PI / 2 + (k / 10) * Math.PI * 2, rr = k % 2 ? 4.5 : 11; return [x + Math.cos(a) * rr, y + Math.sin(a) * rr] as P; }), color: "#f2cf6e", seed: 20 + i, lift: 0.3 })));+};++const hills = (g: Gfx) => {+ layer(g, [{ shape: P0([[-30, 600], [170, 548], [380, 574], [600, 540], [820, 566], [1110, 530], [1110, 1100], [-30, 1100]]), color: "#5f7f76", torn: 3.4, seed: 30 }]);+ // pines along the ridge: tiers of torn dark-green paper, each tier its own scrap+ const pine = (x: number, base: number, h: number, seed: number): Piece[] => {+ const out: Piece[] = [{ shape: [[x - 3, base], [x + 3, base], [x + 3, base - h * 0.25], [x - 3, base - h * 0.25]], color: "#3b2a1f", seed: seed + 9 }];+ for (let t = 0; t < 4; t++) { const y0 = base - h * (0.18 + t * 0.2), w = h * (0.34 - t * 0.07); out.push({ shape: [[x - w, y0], [x + w, y0 - 3], [x + w * 0.1, y0 - h * 0.34], [x - w * 0.15, y0 - h * 0.33]], color: t % 2 ? "#23473f" : "#1d3d37", torn: 1.6, seed: seed + t, lift: 0.5 }); }+ return out;+ };+ layer(g, [...pine(96, 580, 150, 40), ...pine(160, 566, 118, 50), ...pine(880, 560, 160, 60), ...pine(950, 548, 128, 70), ...pine(1024, 550, 176, 80)]);+ layer(g, [{ shape: P0([[-30, 700], [240, 670], [520, 690], [800, 664], [1110, 684], [1110, 1100], [-30, 1100]]), color: "#8b8d58", torn: 3.4, seed: 90 }]);+ layer(g, [{ shape: P0([[-30, 820], [300, 800], [620, 816], [900, 796], [1110, 812], [1110, 1100], [-30, 1100]]), color: "#c89140", torn: 3.6, seed: 91, fibre: 1.4 }]);+ layer(g, [{ shape: P0([[-30, 930], [260, 910], [560, 928], [860, 906], [1110, 922], [1110, 1100], [-30, 1100]]), color: "#a8652c", torn: 3.6, seed: 92, fibre: 1.4 }]);+};++// ---------------------------------------------------------------- the fox+const RUST = "#cf5a22", RUST_D = "#9c3c17", RUST_L = "#ec8d45", CREAM = "#f2e2c0", BLACK = "#231813", AMBER = "#e3a53a";+const figure = (g: Gfx) => {+ // the brush in two parts: the far sweep behind the haunch, and the near sweep that lies IN+ // FRONT of the paws, curling round them to its white tip, as a sitting fox wraps its feet+ const tailBack: P[] = P0([[700, 650], [794, 712], [822, 812], [780, 886], [700, 910], [640, 880], [700, 846], [742, 790], [728, 706]]);+ const tailFront: P[] = P0([[770, 872], [690, 918], [580, 934], [470, 926], [392, 904], [360, 880], [382, 864], [470, 886], [580, 894], [680, 880], [744, 846]]);+ const tailTip: P[] = P0([[470, 926], [408, 910], [366, 888], [356, 870], [380, 860], [430, 878], [482, 888], [490, 908]]);+ const tailShade: P[] = P0([[746, 852], [690, 902], [600, 924], [520, 922], [610, 906], [700, 878]]);+ const haunch: P[] = blob(664, 772, 100, 110, 200, 0.05, 18, -0.4);+ const haunchShade: P[] = P0([[742, 730], [760, 800], [726, 864], [660, 884], [700, 850], [732, 790]]);+ const body: P[] = P0([[500, 570], [578, 560], [652, 592], [716, 664], [738, 770], [690, 862], [576, 872], [520, 846], [490, 740], [486, 640]]);+ const shoulder: P[] = P0([[560, 596], [630, 612], [668, 660], [612, 650], [572, 628]]); // light across the shoulder+ // slender forelegs with black stockings only below the wrist, and neat paws+ const leg = (x0: number, y0: number, x1: number, y1: number, w0: number, w1: number): P[] => P0([[x0 - w0, y0], [x0 + w0, y0], [(x0 + x1) / 2 + w0 * 0.8, (y0 + y1) / 2], [x1 + w1, y1], [x1 - w1, y1], [(x0 + x1) / 2 - w0 * 0.85, (y0 + y1) / 2]], 4);+ const legN = leg(512, 700, 516, 896, 15, 11), legF = leg(566, 716, 570, 892, 13, 10);+ const stock = (x1: number, y1: number, w: number, top: number): P[] => P0([[x1 - w - 2, top], [x1 + w + 2, top + 3], [x1 + w + 1, y1 + 2], [x1 - w - 1, y1 + 2]], 4);+ // the white of a fox runs from the lower jaw down the throat to a point between the forelegs+ const bib: P[] = P0([[452, 556], [520, 566], [556, 598], [558, 672], [540, 740], [522, 790], [502, 746], [480, 670], [462, 604]]);+ const head: P[] = P0([[452, 430], [506, 412], [556, 414], [590, 448], [600, 506], [580, 546], [534, 562], [486, 560], [440, 540], [396, 516], [364, 500], [370, 488], [404, 470]]);+ const jaw: P[] = P0([[368, 502], [410, 510], [458, 530], [520, 546], [566, 540], [590, 528], [614, 556], [598, 562], [574, 578], [530, 582], [470, 568], [416, 542], [378, 516]]); // the white of the jaw flares back into a pointed cheek tuft+ const brow: P[] = P0([[420, 452], [470, 422], [530, 416], [560, 432], [500, 438], [452, 456]]);+ const earN: P[] = [[462, 432], [516, 418], [488, 318]], earNin: P[] = [[474, 424], [506, 416], [489, 346]];+ const earF: P[] = [[528, 420], [572, 440], [566, 322]];+ const eye: P[] = P0([[430, 470], [446, 462], [464, 464], [472, 472], [456, 476], [440, 476]], 5);++ layer(g, [{ shape: tailBack, color: RUST, torn: 2.6, seed: 300, fibre: 1.2, lift: 1.4 }]);+ layer(g, [{ shape: body, color: RUST, torn: 2.2, seed: 310, fibre: 1.2, lift: 1.3 }, { shape: legF, color: RUST_D, torn: 1.4, seed: 311, lift: 0.9 }]);+ layer(g, [{ shape: haunch, color: RUST, torn: 2.4, seed: 320, lift: 1.2 }, { shape: stock(570, 892, 10, 820), color: "#2e211a", torn: 1.1, seed: 322, lift: 0.4 }]);+ layer(g, [{ shape: haunchShade, color: RUST_D, torn: 2.2, seed: 321, lift: 0.4 }, { shape: shoulder, color: RUST_L, torn: 2, seed: 323, lift: 0.4 }]);+ layer(g, [{ shape: bib, color: CREAM, torn: 3.4, seed: 331, lift: 0.9 }]);+ layer(g, [{ shape: legN, color: RUST, torn: 1.4, seed: 330, lift: 1.1 }]);+ layer(g, [{ shape: stock(516, 896, 11, 816), color: BLACK, torn: 1.2, seed: 332, lift: 0.5 }]);+ layer(g, [{ shape: blob(517, 898, 17, 8, 390, 0.12, 12), color: BLACK, torn: 1, seed: 390, lift: 0.4 }, { shape: blob(572, 896, 15, 7, 391, 0.12, 12), color: "#2e211a", torn: 1, seed: 391, lift: 0.4 }]);+ layer(g, [{ shape: tailFront, color: RUST, torn: 2.6, seed: 303, fibre: 1.2, lift: 1.3 }]);+ layer(g, [{ shape: tailShade, color: RUST_D, torn: 2.2, seed: 301, lift: 0.5 }, { shape: tailTip, color: CREAM, torn: 3.2, seed: 302, lift: 0.7 }]);+ layer(g, [{ shape: earF, color: BLACK, torn: 1.6, seed: 340, lift: 0.8 }, { shape: [[534, 420], [566, 432], [562, 360]], color: RUST_D, torn: 1.2, seed: 341, lift: 0.3 }]);+ layer(g, [{ shape: head, color: RUST, torn: 2, seed: 351, fibre: 1.1, lift: 1.2 }]);+ layer(g, [{ shape: jaw, color: CREAM, torn: 3, seed: 361, lift: 0.6 }, { shape: brow, color: RUST_L, torn: 1.8, seed: 360, lift: 0.4 }, { shape: earN, color: RUST, torn: 1.6, seed: 362, lift: 0.9 }]);+ layer(g, [{ shape: earNin, color: CREAM, torn: 1.8, seed: 370, lift: 0.4 }, { shape: [[480, 350], [498, 350], [489, 318]], color: BLACK, torn: 1, seed: 371, lift: 0.3 }]);+ // the face: a black nose, a fine mouth slip, the amber eye with its slit, one white glint+ layer(g, [{ shape: blob(372, 494, 13, 10, 380, 0.1, 10, 0.3), color: BLACK, seed: 380, lift: 0.4 }, { shape: P0([[382, 508], [412, 512], [440, 520], [438, 523], [410, 516], [383, 512]], 4), color: "#4a2a1e", seed: 381, lift: 0.15 }]);+ layer(g, [{ shape: eye, color: AMBER, seed: 382, lift: 0.3 }]);+ layer(g, [{ shape: P0([[452, 464], [457, 463], [458, 476], [453, 476]], 3), color: BLACK, seed: 383, lift: 0.1 }, { shape: blob(447, 467, 2.4, 2, 384, 0.1, 8), color: "#ffffff", seed: 384, lift: 0.1 }]);+};++// ---------------------------------------------------------------- the foreground+const foreground = (g: Gfx) => {+ // fallen leaves cut from three papers, and torn grass blades across the fox's feet+ const leaf = (cx: number, cy: number, s: number, a: number, color: string, seed: number): Piece => {+ const pts: P[] = [[0, -1], [0.26, -0.64], [0.6, -0.72], [0.44, -0.32], [0.9, -0.12], [0.46, 0.12], [0.62, 0.52], [0.18, 0.34], [0, 0.9], [-0.18, 0.34], [-0.62, 0.52], [-0.46, 0.12], [-0.9, -0.12], [-0.44, -0.32], [-0.6, -0.72], [-0.26, -0.64]];+ return { shape: pts.map(([x, y]) => [cx + (x * Math.cos(a) - y * Math.sin(a)) * s, cy + (x * Math.sin(a) + y * Math.cos(a)) * s] as P), color, seed, lift: 0.6 };+ };+ const r = rng(700);+ layer(g, [leaf(250, 960, 34, 0.4, "#b6352a", 701), leaf(760, 972, 28, -0.8, "#e0962f", 702), leaf(890, 1010, 38, 1.2, "#8f2e1f", 703), leaf(140, 1030, 30, -0.3, "#e0962f", 704), leaf(640, 1040, 24, 2.2, "#b6352a", 705), leaf(990, 900, 22, 0.9, "#c96a2a", 706)]);+ const blades: Piece[] = [];+ for (let i = 0; i < 26; i++) { const x = 300 + r() * 560, h = 26 + r() * 46, lean = (r() - 0.5) * 24, y = 900 + r() * 26; if (x > 340 && x < 800) continue; blades.push({ shape: [[x - 4, y], [x + 4, y], [x + lean + 1, y - h]], color: r() < 0.5 ? "#6f7a3a" : "#8c8f48", torn: 0.8, seed: 720 + i, lift: 0.4 }); }+ layer(g, blades);+ void inside; void lerpP;+};++export const drawFox = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, PENCIL);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ sky(g); hills(g); figure(g); foreground(g);+ g.paper("paper", 0.1);+};++export const fox: Film = {+ meta: { title: "Fox at dusk · cut-paper collage", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "fox", start: 0, end: 1, draw: drawFox }],+};diff --git a/engine/src/canvas-core/gallery.ts b/engine/src/canvas-core/gallery.tsnew file mode 100644index 0000000..141abbe--- /dev/null+++ b/engine/src/canvas-core/gallery.ts@@ -0,0 +1,111 @@+// GALLERY KIT. The shared drawing helpers the style-gallery subjects are built from. Everything+// here is geometry or raw canvas on the CURRENT group surface (g.cur), so it composes with the+// core's groups, textures and papers. No randomness except rng(seed); no filters; no assets.+import { Gfx, type Ctx, type P, rng, sample, fractal } from "./core";++export const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+export const lerp = (a: number, b: number, t: number) => a + (b - a) * t;+export const lerpP = (a: P, b: P, t: number): P => [lerp(a[0], b[0], t), lerp(a[1], b[1], t)];+export const smooth = (pts: P[], closed = false, per = 12): P[] => sample(pts, closed, per);++// ---------------------------------------------------------------- colour+const hex = (h: string): [number, number, number] => { const s = h.replace("#", ""); return [0, 2, 4].map((i) => parseInt(s.slice(i, i + 2), 16)) as [number, number, number]; };+export const mix = (a: string, b: string, t: number): string => { const x = hex(a), y = hex(b); return "#" + x.map((v, i) => Math.round(lerp(v, y[i], t)).toString(16).padStart(2, "0")).join(""); };++// ---------------------------------------------------------------- polylines+export const polyLen = (s: P[]) => s.reduce((a, p, i) => (i ? a + Math.hypot(p[0] - s[i - 1][0], p[1] - s[i - 1][1]) : 0), 0);+// n points evenly spaced by arc length: the only honest way to hang a width profile on a curve+export const resample = (s: P[], n: number): P[] => {+ const cum = [0]; for (let i = 1; i < s.length; i++) cum.push(cum[i - 1] + Math.hypot(s[i][0] - s[i - 1][0], s[i][1] - s[i - 1][1]));+ const L = cum[cum.length - 1], out: P[] = []; let j = 1;+ for (let k = 0; k < n; k++) { const d = (L * k) / (n - 1); while (j < s.length - 1 && cum[j] < d) j++; const f = (d - cum[j - 1]) / (cum[j] - cum[j - 1] || 1); out.push(lerpP(s[j - 1], s[j], clamp(f))); }+ return out;+};+const normals = (s: P[], closed = false): P[] => s.map((_, i) => {+ const n = s.length, a = closed ? s[(i - 1 + n) % n] : s[Math.max(0, i - 1)], b = closed ? s[(i + 1) % n] : s[Math.min(n - 1, i + 1)];+ const dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1; return [-dy / l, dx / l];+});+export const area = (s: P[]) => s.reduce((a, p, i) => { const q = s[(i + 1) % s.length]; return a + p[0] * q[1] - q[0] * p[1]; }, 0) / 2;++// piecewise-linear profile through [t, value] knots, smoothed with a cosine ease between knots+export const profile = (knots: [number, number][]) => (t: number) => {+ if (t <= knots[0][0]) return knots[0][1];+ for (let i = 1; i < knots.length; i++) if (t <= knots[i][0]) { const [t0, v0] = knots[i - 1], [t1, v1] = knots[i], f = (t - t0) / (t1 - t0); return lerp(v0, v1, (1 - Math.cos(f * Math.PI)) / 2); }+ return knots[knots.length - 1][1];+};++// ---------------------------------------------------------------- a body hung on a spine+// A creature seen from above is a spine plus a half-width at every point along it. `at(t, s)` is+// the body's own coordinate frame: t runs nose (0) to tail (1), s runs -1 (left edge) to +1 (right+// edge). Anything placed in (t, s) bends with the body, which is what makes markings and fins sit+// ON the animal instead of floating over it.+export type Body = { spine: P[]; nrm: P[]; hw: (t: number) => number; outline: P[]; at: (t: number, s: number) => P; tan: (t: number) => P };+export const body = (ctrl: P[], hw: (t: number) => number, n = 120): Body => {+ const spine = resample(smooth(ctrl, false, 16), n), nrm = normals(spine);+ const idx = (t: number) => clamp(t) * (n - 1);+ const pick = (arr: P[], t: number): P => { const f = idx(t), i = Math.floor(f), k = Math.min(n - 1, i + 1); return lerpP(arr[i], arr[k], f - i); };+ const at = (t: number, s: number): P => { const p = pick(spine, t), q = pick(nrm, t), w = hw(t); return [p[0] + q[0] * w * s, p[1] + q[1] * w * s]; };+ const tan = (t: number): P => { const q = pick(nrm, t); return [q[1], -q[0]]; };+ const L: P[] = [], R: P[] = [];+ for (let i = 0; i < n; i++) { const t = i / (n - 1); L.push(at(t, -1)); R.push(at(t, 1)); }+ return { spine, nrm, hw, outline: [...L, ...R.reverse()], at, tan };+};++// ---------------------------------------------------------------- raw drawing on the current surface+export const trace = (c: Ctx, pts: P[], closed = true) => { c.beginPath(); pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); if (closed) c.closePath(); };+const boxOf = (pts: P[]) => { let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; for (const [x, y] of pts) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); } return { x0, y0, x1, y1 }; };+export const bounds = boxOf;+export const fillShape = (g: Gfx, pts: P[], color: string, alpha = 1) => { const b = boxOf(pts); g.touch(b.x0 - 2, b.y0 - 2, b.x1 + 2, b.y1 + 2); const c = g.cur; c.globalAlpha = alpha; c.fillStyle = color; trace(c, pts); c.fill(); c.globalAlpha = 1; };+// draw `fn` only inside `pts`. Marks the clip box so the group composites the right region.+export const clipped = (g: Gfx, pts: P[], fn: () => void) => { const b = boxOf(pts); g.touch(b.x0 - 2, b.y0 - 2, b.x1 + 2, b.y1 + 2); const c = g.cur; c.save(); trace(c, pts); c.clip(); fn(); c.restore(); };++// ---------------------------------------------------------------- the inker's line+// A brush-marker contour: tapered ends, and HEAVIER on the side turned away from the light (the+// comic inker's rule). `light` is a unit vector pointing TO the light. For a closed contour the+// outward normal is found from the winding; for an open stroke `side` picks which normal is "out".+export type InkOpts = { w: number; light?: P; shadow?: number; taper?: [number, number]; seed?: number; rough?: number; closed?: boolean; side?: 1 | -1; min?: number; swell?: number };+export const inkRibbon = (center: P[], o: InkOpts): P[] => {+ const { w, light = [-0.6, -0.8], shadow = 0.8, taper = [0.12, 0.18], seed = 1, rough = 0.25, closed = false, side = 1, min = 0.18, swell = 0.12 } = o;+ const s = closed ? center : center, n = s.length, nr = normals(s, closed), out = closed ? (area(s) > 0 ? -1 : 1) : side, r = rng(seed);+ const ph = (seed % 13) * 0.7, L: P[] = [], R: P[] = [];+ for (let i = 0; i < n; i++) {+ const t = i / (n - 1), q = nr[i], ox = q[0] * out, oy = q[1] * out;+ const away = clamp(-(ox * light[0] + oy * light[1])); // 1 where the edge faces away from the light+ const ends = closed ? 1 : Math.min(1, t / taper[0], (1 - t) / taper[1]);+ const tp = min + (1 - min) * Math.pow(clamp(ends), 0.8);+ const wv = w * tp * (1 + shadow * away * 1.1 - shadow * 0.35) * (1 + swell * Math.sin(t * 9 + ph)) / 2;+ const j1 = (r() - 0.5) * rough, j2 = (r() - 0.5) * rough;+ L.push([s[i][0] - q[0] * (wv + j1), s[i][1] - q[1] * (wv + j1)]); R.push([s[i][0] + q[0] * (wv + j2), s[i][1] + q[1] * (wv + j2)]);+ }+ return closed ? [...L, L[0], ...[...R, R[0]].reverse()] : [...L, ...R.reverse()];+};+// fill a ribbon; a closed ribbon is two loops, filled even-odd so the middle stays open+export const ink = (g: Gfx, center: P[], color: string, o: InkOpts, alpha = 1) => {+ const pts = inkRibbon(center, o), b = boxOf(pts); g.touch(b.x0 - 3, b.y0 - 3, b.x1 + 3, b.y1 + 3);+ const c = g.cur; c.globalAlpha = alpha; c.fillStyle = color;+ if (o.closed) { const n = center.length + 1; c.beginPath(); pts.slice(0, n).forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); pts.slice(n).forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); c.fill("evenodd"); }+ else { trace(c, pts); c.fill(); }+ c.globalAlpha = 1;+};++// ---------------------------------------------------------------- organic blobs+// a closed wobbly blob: markings, pads, patches. `k` is how far the edge wanders (0..1 of r).+export const blob = (cx: number, cy: number, rx: number, ry: number, seed: number, k = 0.18, n = 14, rot = 0): P[] => {+ const r = rng(seed), ph = r() * 6.28, out: P[] = [];+ for (let i = 0; i < n; i++) { const a = (i / n) * Math.PI * 2, f = 1 + (fractal(seed, Math.cos(a) * 3 + 10, Math.sin(a) * 3 + 10, 0.6, 0.6, 2) - 0.5) * 2 * k + Math.sin(a * 3 + ph) * k * 0.3; const x = Math.cos(a) * rx * f, y = Math.sin(a) * ry * f; out.push([cx + x * Math.cos(rot) - y * Math.sin(rot), cy + x * Math.sin(rot) + y * Math.cos(rot)]); }+ return smooth(out, true, 6);+};++// ---------------------------------------------------------------- hatching+// parallel strokes across a region at `angle`, spaced `gap`, kept only where `keep(x, y)` says so.+// Each stroke is broken into runs so tone can come from WHERE lines are, not from their opacity.+export const hatchRuns = (b: { x0: number; y0: number; x1: number; y1: number }, angle: number, gap: number, keep: (x: number, y: number) => boolean, step = 3, seed = 1): P[][] => {+ const c = Math.cos(angle), s = Math.sin(angle), cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, R = Math.hypot(b.x1 - b.x0, b.y1 - b.y0) / 2 + gap, r = rng(seed), runs: P[][] = [];+ for (let v = -R; v <= R; v += gap) {+ const off = (r() - 0.5) * gap * 0.35; let cur: P[] = [];+ for (let u = -R; u <= R; u += step) { const x = cx + u * c - (v + off) * s, y = cy + u * s + (v + off) * c; if (keep(x, y)) cur.push([x, y]); else if (cur.length) { if (cur.length > 1) runs.push(cur); cur = []; } }+ if (cur.length > 1) runs.push(cur);+ }+ return runs;+};+export const inside = (pts: P[], x: number, y: number) => { let k = false; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const a = pts[i], b = pts[j]; if (a[1] > y !== b[1] > y && x < ((b[0] - a[0]) * (y - a[1])) / (b[1] - a[1]) + a[0]) k = !k; } return k; };diff --git a/engine/src/canvas-core/koi.ts b/engine/src/canvas-core/koi.tsnew file mode 100644index 0000000..fa12547--- /dev/null+++ b/engine/src/canvas-core/koi.ts@@ -0,0 +1,221 @@+import { Gfx, PENCIL, rng, type Ctx, type Env, type P } from "./core";+import type { Film } from "./film";+import { blob, body, clipped, fillShape, ink, lerpP, mix, profile, smooth, type Body } from "./gallery";++// KOI · marker comic. Bold cel fills with a hard shadow edge, one heavy confident contour that+// thickens away from the light, and a single dramatic C-curve for the whole fish.+//+// Anatomy, seen from above: a blunt snout with two pairs of barbels, eyes set on the sides of the+// head, gill covers, the body widest just behind the pectorals and tapering to a narrow caudal+// peduncle; big paddle pectorals (black at the base, "motoguro"), small pelvics mid-body, a+// dorsal fin running down the spine, and a long flowing caudal fin. Markings are Sanke-style:+// red "hi" patches on white with a few black "sumi" spots, placed in the body's own (t, s) frame+// so they bend with it. Light from the upper left.++const INK = "#15122a", LIGHT: P = [-0.62, -0.78];+const WATER = "#137582", WATER_D = "#0c5360", WATER_L = "#3aa6ad";+const WHITE = "#fdf8ee", WHITE_S = "#c9d6e0", HI = "#ec4a22", HI_S = "#b72c1a", SUMI = "#1b1830";+const FIN = "#f7efe4", FIN_S = "#d5dde2";++const koiBody = (): Body => body(+ [[300, 222], [404, 292], [502, 408], [556, 556], [534, 694], [468, 792]],+ profile([[0, 0], [0.012, 27], [0.035, 46], [0.08, 64], [0.16, 80], [0.27, 90], [0.4, 88], [0.55, 78], [0.7, 60], [0.82, 40], [0.92, 26], [1, 22]]),+);++// a fin in the body's frame: rays fan from a root between two edge points out to a rounded paddle+const fin = (root0: P, root1: P, tip: P, spread: number, bulge: number, seed: number, rays = 8): { shape: P[]; rays: P[][] } => {+ const r = rng(seed), mid = lerpP(root0, root1, 0.5), dx = tip[0] - mid[0], dy = tip[1] - mid[1], len = Math.hypot(dx, dy), ux = dx / len, uy = dy / len, nx = -uy, ny = ux;+ const tipAt = (a: number): P => { const k = len * (1 - a * a * 0.34) * (0.985 + r() * 0.03); return [mid[0] + ux * k + nx * (a * spread + bulge * (1 - a * a)), mid[1] + uy * k + ny * (a * spread + bulge * (1 - a * a))]; };+ const tips = Array.from({ length: rays }, (_, i) => tipAt(-1 + (2 * i) / (rays - 1)));+ const edge: P[] = [];+ tips.forEach((t, i) => { edge.push(t); if (i < tips.length - 1) { const m = lerpP(t, tips[i + 1], 0.5); edge.push(lerpP(mid, m, 0.992)); } }); // the membrane sags only a touch between rays+ const shape = smooth([root0, ...edge, root1], true, 6);+ const out = tips.map((t, i) => { const base = lerpP(root0, root1, i / (rays - 1)); return smooth([base, lerpP(lerpP(base, t, 0.5), mid, -0.04), t], false, 6); });+ return { shape, rays: out };+};++// the caudal fin: a centreline that keeps turning at the body's own curvature, two long lobes+// either side of it that open out, wave, and part at a notch+const tail = (b: Body): { shape: P[]; rays: P[][] } => {+ const t1 = b.tan(1), t0 = b.tan(0.9), th0 = Math.atan2(t1[1], t1[0]), dTh = Math.atan2(t0[1] * t1[0] - t0[0] * t1[1], t0[0] * t1[0] + t0[1] * t1[1]);+ const kappa = (-dTh / 60) * 2.6, root = b.at(0.955, 0), line: P[] = [root], heads: number[] = [th0];+ for (let i = 1; i <= 26; i++) { const th = th0 + kappa * i * 10; heads.push(th); const q = line[i - 1]; line.push([q[0] + Math.cos(th) * 10, q[1] + Math.sin(th) * 10]); }+ const off = (i: number, w: number): P => { const th = heads[i]; return [line[i][0] - Math.sin(th) * w, line[i][1] + Math.cos(th) * w]; };+ const up = (i: number) => 22 + Math.pow(i / 26, 0.85) * 124 + Math.sin(i * 0.42) * 11, lo = (i: number) => 22 + Math.pow(i / 26, 1.0) * 104 + Math.sin(i * 0.47 + 2) * 10;+ const upper: P[] = [], lower: P[] = [];+ for (let i = 0; i <= 24; i++) { upper.push(off(i, up(i))); lower.push(off(Math.min(26, i + 2), -lo(Math.min(26, i + 2)))); }+ const notch = off(19, 14), edge = smooth([upper[24], lerpP(lerpP(upper[24], notch, 0.5), off(23, 60), 0.35), notch, lerpP(lerpP(lower[24], notch, 0.5), off(24, -44), 0.3), lower[24]], false, 8);+ const shape = [...upper, ...edge, ...[...lower].reverse()];+ const rays: P[][] = [];+ for (let k = 0; k <= 14; k++) { const f = k / 14, e = edge[Math.round(f * (edge.length - 1))], s0 = lerpP(off(0, 16), off(0, -16), f); rays.push(smooth([s0, lerpP(lerpP(s0, e, 0.5), line[12], 0.12), e], false, 8)); }+ return { shape, rays };+};++const water = (g: Gfx) => {+ g.group("plain", () => {+ fillShape(g, [[0, 0], [1080, 0], [1080, 1080], [0, 1080]], WATER_D);+ // the colourist's flats: a lit body of water through the middle, deep water in the corners+ fillShape(g, blob(560, 540, 610, 470, 401, 0.1, 20, -0.75), WATER);+ fillShape(g, blob(520, 520, 400, 290, 402, 0.12, 18, -0.9), mix(WATER, WATER_L, 0.22));+ const r = rng(311);+ for (let i = 0; i < 12; i++) { const x = 60 + r() * 960, y = 60 + r() * 960, l = 70 + r() * 150, a = -0.42 + (r() - 0.5) * 0.12; ink(g, smooth([[x, y], [x + Math.cos(a) * l * 0.5, y + Math.sin(a) * l * 0.5 + 3], [x + Math.cos(a) * l, y + Math.sin(a) * l]], false, 6), WATER_L, { w: 5 + r() * 5, shadow: 0, taper: [0.4, 0.4], seed: 500 + i }, 0.45); }+ });+};++const lilyPad = (g: Gfx, cx: number, cy: number, rr: number, notch: number, seed: number) => {+ const r = rng(seed), rim: P[] = [];+ for (let i = 0; i <= 40; i++) { const a = notch + 0.2 + (i / 40) * (Math.PI * 2 - 0.4); rim.push([cx + Math.cos(a) * rr * (1 + (r() - 0.5) * 0.03), cy + Math.sin(a) * rr * 0.93 * (1 + (r() - 0.5) * 0.03)]); }+ const pad: P[] = [[cx, cy], ...rim];+ g.group("plain", () => {+ fillShape(g, pad.map(([x, y]) => [x + 16, y + 22] as P), "#0a3f49", 0.55); // its shadow on the water+ fillShape(g, pad, "#2f9a4f");+ clipped(g, pad, () => { fillShape(g, pad.map(([x, y]) => [x - 20, y - 18] as P), "#56bb5c"); fillShape(g, blob(cx - rr * 0.35, cy - rr * 0.35, rr * 0.35, rr * 0.16, seed + 3, 0.2, 12, -0.6), "#9ee07f", 0.8); });+ for (let i = 0; i < 11; i++) { const a = notch + 0.35 + (i / 10) * (Math.PI * 2 - 0.7); ink(g, smooth([[cx, cy], [cx + Math.cos(a) * rr * 0.5, cy + Math.sin(a) * rr * 0.46], [cx + Math.cos(a + 0.05) * rr * 0.9, cy + Math.sin(a + 0.05) * rr * 0.84]], false, 6), "#1c6a3a", { w: 2.4, seed: seed + i, shadow: 0, taper: [0.1, 0.5] }, 0.7); }+ ink(g, pad.slice(1), INK, { w: 5.5, light: LIGHT, shadow: 0.9, seed: seed + 20, taper: [0.02, 0.02] });+ ink(g, [rim[rim.length - 1], [cx, cy], rim[0]], INK, { w: 4.5, light: LIGHT, shadow: 0.9, seed: seed + 21, taper: [0.08, 0.08] });+ });+};++const waterLily = (g: Gfx, cx: number, cy: number, s: number, seed: number) => {+ const r = rng(seed);+ const petal = (a: number, len: number, wid: number, col: string, sh: string, k: number) => {+ const tip: P = [cx + Math.cos(a) * len, cy + Math.sin(a) * len], nx = -Math.sin(a), ny = Math.cos(a);+ const shape = smooth([[cx + nx * 3, cy + ny * 3], [cx + Math.cos(a) * len * 0.45 + nx * wid, cy + Math.sin(a) * len * 0.45 + ny * wid], tip, [cx + Math.cos(a) * len * 0.45 - nx * wid, cy + Math.sin(a) * len * 0.45 - ny * wid], [cx - nx * 3, cy - ny * 3]], true, 6);+ fillShape(g, shape, sh);+ clipped(g, shape, () => fillShape(g, shape.map(([x, y]) => [x - 5 - nx * 4 * k, y - 6 - ny * 4 * k] as P), col));+ ink(g, shape, INK, { w: 3.2, closed: true, light: LIGHT, shadow: 0.8, seed: seed + Math.round(a * 100) });+ };+ g.group("plain", () => {+ for (let i = 0; i < 8; i++) petal(i * 0.785 + 0.2 + (r() - 0.5) * 0.1, 70 * s, 22 * s, "#ffc3d6", "#e886a6", 1);+ for (let i = 0; i < 7; i++) petal(i * 0.9 + 0.55 + (r() - 0.5) * 0.1, 54 * s, 18 * s, "#ffe0ea", "#f2a2bd", -1);+ for (let i = 0; i < 5; i++) petal(i * 1.26 + 0.1, 34 * s, 13 * s, "#fff1f5", "#f6bfd0", 1);+ fillShape(g, blob(cx, cy, 15 * s, 13 * s, seed + 9, 0.15, 12), "#ffcc2e");+ ink(g, blob(cx, cy, 15 * s, 13 * s, seed + 9, 0.15, 12), INK, { w: 2.6, closed: true, seed: seed + 10 });+ for (let i = 0; i < 14; i++) { const a = i * 0.45, d = 6 + (i % 3) * 3; fillShape(g, blob(cx + Math.cos(a) * d * s, cy + Math.sin(a) * d * s, 2.2, 2.2, seed + 30 + i, 0.1, 8), "#c98a00"); }+ });+};++const ripples = (g: Gfx, cx: number, cy: number, seed: number) => {+ // surface rings, broken where the light catches them: the one place the water shows its skin+ const r = rng(seed);+ g.group("plain", () => {+ [58, 104, 156].forEach((rad, k) => {+ let a = r() * 6;+ for (let s = 0; s < 5; s++) { const span = 0.55 + r() * 0.6, pts: P[] = []; for (let i = 0; i <= 12; i++) { const t = a + (i / 12) * span; pts.push([cx + Math.cos(t) * rad * 1.35, cy + Math.sin(t) * rad * 0.62]); } ink(g, pts, "#d9fbf6", { w: 4.4 - k * 1.1, shadow: 0, taper: [0.3, 0.3], seed: seed + k * 10 + s }, 0.85 - k * 0.18); a += span + 0.35 + r() * 0.5; }+ });+ });+};++export const drawKoi = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, PENCIL);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ water(g);++ const b = koiBody();+ // pectorals on the outside of the curve spread wide; the inside one is tucked and foreshortened+ const pecR = fin(b.at(0.17, 0.9), b.at(0.285, 0.9), b.at(0.33, 2.85), 70, 16, 71, 9);+ const pecL = fin(b.at(0.18, -0.9), b.at(0.27, -0.9), b.at(0.35, -2.25), 44, -10, 72, 8);+ const pelR = fin(b.at(0.53, 0.9), b.at(0.6, 0.9), b.at(0.66, 1.95), 30, 6, 73, 6);+ const pelL = fin(b.at(0.54, -0.9), b.at(0.6, -0.9), b.at(0.67, -1.8), 26, -5, 74, 6);+ const cau = tail(b);+ const fins = [pecR, pecL, pelR, pelL];++ // the fish's shadow on the pond floor, flat and hard, down-right away from the light+ g.group("plain", () => [b.outline, cau.shape, ...fins.map((f) => f.shape)].forEach((s) => fillShape(g, s.map(([x, y]) => [x + 30, y + 40] as P), "#083b45", 0.5)));++ // fins under the body: translucent, cel-shaded, a black base on the pectorals+ g.group("plain", () => {+ fins.forEach((f, i) => {+ fillShape(g, f.shape, FIN_S, 0.88);+ clipped(g, f.shape, () => {+ fillShape(g, f.shape.map(([x, y]) => [x - 9, y - 11] as P), FIN, 0.92);+ if (i < 2) fillShape(g, blob(...(i === 0 ? b.at(0.25, 1.35) : b.at(0.245, -1.25)), i === 0 ? 46 : 32, i === 0 ? 30 : 22, 80 + i, 0.2, 12, i === 0 ? 1.0 : -0.8), SUMI, 0.95); // motoguro: black at the base of the pectorals+ });+ f.rays.forEach((ray, k) => ink(g, ray, mix(INK, FIN_S, 0.35), { w: 1.7, shadow: 0, taper: [0.05, 0.5], seed: 900 + i * 40 + k }, 0.75));+ ink(g, f.shape, INK, { w: 4.2, closed: true, light: LIGHT, shadow: 0.85, seed: 700 + i * 7 });+ });+ });++ // the body: shade cel underneath, the lit white pushed toward the light, then the markings+ const bs = b.outline;+ g.group("plain", () => {+ fillShape(g, bs, WHITE_S);+ clipped(g, bs, () => {+ fillShape(g, bs.map(([x, y]) => [x + LIGHT[0] * 22, y + LIGHT[1] * 22] as P), WHITE);+ // red hi: head crown, a saddle across the back, a patch toward the tail. Crisp back edges.+ const patches: [number, number, number, number, number][] = [[0.105, -0.05, 0.075, 0.95, 11], [0.36, -0.25, 0.1, 1.2, 12], [0.47, 0.35, 0.07, 0.9, 13], [0.66, -0.1, 0.085, 1.15, 14], [0.82, 0.3, 0.05, 0.9, 15]];+ patches.forEach(([t, s, dt, ds, seed]) => {+ const r = rng(seed * 17), pts: P[] = [];+ for (let i = 0; i < 16; i++) { const a = (i / 16) * Math.PI * 2, k = 0.8 + r() * 0.35; pts.push(b.at(t + Math.cos(a) * dt * k, s + Math.sin(a) * ds * k)); }+ const sh = smooth(pts, true, 6);+ fillShape(g, sh, HI_S);+ clipped(g, sh, () => fillShape(g, bs.map(([x, y]) => [x + LIGHT[0] * 22, y + LIGHT[1] * 22] as P), HI));+ });+ // sumi: a few black spots, never on the head+ [[0.3, 0.55, 0.028, 0.32, 31], [0.55, -0.55, 0.03, 0.3, 32], [0.61, 0.42, 0.018, 0.22, 33], [0.78, -0.2, 0.026, 0.4, 34], [0.43, 0.02, 0.016, 0.18, 35]].forEach(([t, s, dt, ds, seed]) => {+ const r = rng(seed), pts: P[] = []; for (let i = 0; i < 12; i++) { const a = (i / 12) * Math.PI * 2, k = 0.8 + r() * 0.4; pts.push(b.at(t + Math.cos(a) * dt * k, s + Math.sin(a) * ds * k)); }+ fillShape(g, smooth(pts, true, 5), SUMI);+ });+ // scales: a loose lattice of arcs, strongest on the lit back, gone into the shade+ const r = rng(55);+ for (let t = 0.2; t < 0.93; t += 0.034) for (let s = -0.75; s <= 0.8; s += 0.3) {+ const tt = t + (Math.round(s / 0.3) % 2 ? 0.017 : 0), ss = s + (r() - 0.5) * 0.06, p = b.at(tt, ss), q = b.at(tt + 0.014, ss - 0.13), u = b.at(tt + 0.014, ss + 0.13), m = b.at(tt + 0.022, ss);+ const lit = ss < 0.35 && !(r() < 0.3);+ if (lit) ink(g, smooth([q, m, u], false, 5), "#2a1f3a", { w: 1.5, shadow: 0, taper: [0.3, 0.3], seed: 2000 + Math.round(t * 1000 + s * 50) }, 0.28);+ void p;+ }+ // the wet highlight along the back, and a glint on the head+ [[0.2, 0.3, -0.6, 7], [0.335, 0.42, -0.64, 6], [0.46, 0.5, -0.66, 4.5], [0.58, 0.6, -0.66, 3]].forEach(([t0, t1, sv, w], k) => { const pts: P[] = []; for (let i = 0; i <= 8; i++) pts.push(b.at(t0 + ((t1 - t0) * i) / 8, sv)); ink(g, pts, "#ffffff", { w, shadow: 0, taper: [0.35, 0.45], seed: 1800 + k }, 0.9); });+ fillShape(g, blob(...b.at(0.075, -0.35), 22, 9, 91, 0.1, 10, -0.7), "#ffffff", 0.85);+ });+ // dorsal fin down the spine: a narrow flutter of translucent fin with ray ticks+ const df: P[] = [], dfr: P[] = [];+ for (let i = 0; i <= 16; i++) { const f = i / 16, t = 0.36 + f * 0.3, h = Math.pow(Math.sin(Math.min(1, f * 2.6) * Math.PI / 2), 1.2) * (1 - f * 0.78); df.push(b.at(t, 0.0)); dfr.push(b.at(t + 0.04 * h, h * 0.72 + Math.sin(i * 1.4) * 0.02 * h)); }+ const dorsal = [...smooth(df, false, 3), ...smooth(dfr, false, 3).reverse()];+ fillShape(g, dorsal.map(([x, y]) => [x + 6, y + 8] as P), "#2a1f3a", 0.18); // the fin's own shadow on the back+ fillShape(g, dorsal, FIN_S, 0.95);+ clipped(g, dorsal, () => fillShape(g, dorsal.map(([x, y]) => [x - 6, y - 7] as P), FIN, 0.95));+ for (let i = 1; i < 16; i += 2) ink(g, [df[i], lerpP(df[i], dfr[i], 0.5), dfr[i]], mix(INK, FIN_S, 0.4), { w: 1.4, shadow: 0, taper: [0.1, 0.5], seed: 1300 + i }, 0.7);+ ink(g, dorsal, INK, { w: 3.4, closed: true, light: LIGHT, shadow: 0.8, seed: 1400 });++ // head: gill covers, eyes set into the sides, nostrils, barbels+ [-1, 1].forEach((sd) => {+ const gill: P[] = []; for (let i = 0; i <= 6; i++) gill.push(b.at(0.155 - Math.sin((i / 6) * Math.PI) * 0.03, sd * (0.98 - i * 0.1)));+ ink(g, gill, INK, { w: 3.4, shadow: 0, taper: [0.08, 0.7], seed: 1500 + sd });+ const e = b.at(0.085, sd * 0.8), ew = sd > 0 ? 12 : 10;+ fillShape(g, blob(e[0], e[1], ew + 3, ew, 1600 + sd, 0.05, 12), "#e6cf8c");+ fillShape(g, blob(e[0] + 1, e[1] + 1, ew * 0.78, ew * 0.74, 1610 + sd, 0.05, 12), "#1a1427");+ fillShape(g, blob(e[0] - 3, e[1] - 4, 3.2, 2.6, 1620 + sd, 0.05, 8), "#ffffff");+ ink(g, blob(e[0], e[1], ew + 3, ew, 1600 + sd, 0.05, 12), INK, { w: 3, closed: true, light: LIGHT, shadow: 0.7, seed: 1630 + sd });+ fillShape(g, blob(...b.at(0.03, sd * 0.36), 4, 3, 1640 + sd, 0.1, 8), "#3a1e22");+ const m = b.at(0.006, sd * 0.5), m2 = b.at(-0.02, sd * 1.2), m3 = b.at(-0.035, sd * 1.9);+ ink(g, smooth([m, lerpP(m2, b.at(-0.01, sd * 1.1), 0.5), m3], false, 8), INK, { w: 3, shadow: 0, taper: [0.02, 0.9], seed: 1650 + sd });+ const k0 = b.at(0.02, sd * 0.78), k1 = b.at(0.0, sd * 1.25);+ ink(g, smooth([k0, lerpP(k0, k1, 0.5), k1], false, 6), INK, { w: 2.4, shadow: 0, taper: [0.02, 0.9], seed: 1660 + sd });+ });+ });+ // the tail goes on over the body's end, so fin and peduncle are one continuous piece+ g.group("plain", () => {+ fillShape(g, cau.shape, FIN_S, 0.9);+ clipped(g, cau.shape, () => fillShape(g, cau.shape.map(([x, y]) => [x - 10, y - 12] as P), FIN, 0.93));+ cau.rays.forEach((ray, k) => ink(g, ray, mix(INK, FIN_S, 0.35), { w: 1.7, shadow: 0, taper: [0.05, 0.5], seed: 1100 + k }, 0.72));+ const n = b.outline.length / 2, L = b.outline.slice(0, n), R = b.outline.slice(n).reverse(), cut = Math.round(n * 0.965);+ const open = [...L.slice(0, cut).reverse(), ...R.slice(0, cut)];+ ink(g, open, INK, { w: 6.4, light: LIGHT, shadow: 0.95, seed: 1700, side: -1, taper: [0.06, 0.06], min: 0.3 });+ const tailEdge = cau.shape.slice(3, cau.shape.length - 3);+ ink(g, tailEdge, INK, { w: 4.4, light: LIGHT, shadow: 0.85, seed: 1710, side: -1, taper: [0.04, 0.04], min: 0.3 });+ });++ ripples(g, 300, 196, 2100);+ lilyPad(g, 905, 205, 168, 2.3, 3100);+ waterLily(g, 880, 195, 1.15, 3200);+ lilyPad(g, 890, 905, 120, 3.6, 3300);+ lilyPad(g, 120, 640, 88, 0.2, 3400);+ g.paper("paper", 0.05);+};++export const koi: Film = {+ meta: { title: "Koi · marker comic", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "koi", start: 0, end: 1, draw: drawKoi }],+};diff --git a/engine/src/canvas-core/lettering.ts b/engine/src/canvas-core/lettering.tsnew file mode 100644index 0000000..cad597f--- /dev/null+++ b/engine/src/canvas-core/lettering.ts@@ -0,0 +1,73 @@+import { sample, type P } from "./core";+import { clamp, resample } from "./gallery";++// POINTED-PEN SCRIPT. The word is authored as a few continuous centrelines in em units, UPRIGHT+// (baseline y = 0, x-height 1, ascenders ~1.9, y pointing UP), the way a letterer pencils the+// skeleton before inking. The pen does the rest: a flexible pointed nib only spreads when it is+// pulled TOWARD the writer, so the width at every point comes from how much that stretch of the+// line travels downward. Ovals come out heavy on the left and hair-thin on the right, stems are+// shaded, every upstroke and join is a hairline. Then the whole word is slanted as a hand slants.++export type Stroke = P[];+// "anidoodle". LEGIBILITY FIRST: every o is its own clean closed oval (the pen lifts, as a real+// letterer's does), and the joins are hairlines that only TOUCH a bowl, never run through it. An+// o closed with a knotted turn and entered through its own bowl reads as an e or a c, and made+// the first "doo" read "dce".+const oval = (cx: number, a0 = 50, a1 = 420): P[] => { const out: P[] = []; for (let a = a0; a <= a1; a += 22) { const r = (a * Math.PI) / 180; out.push([cx + 0.29 * Math.cos(r), 0.5 + 0.5 * Math.sin(r)]); } return out; };+const on = (cx: number, deg: number): P => [cx + 0.29 * Math.cos((deg * Math.PI) / 180), 0.5 + 0.5 * Math.sin((deg * Math.PI) / 180)];+// a d: oval pulled counter-clockwise from its top right, a hairline up the back to the ascender,+// a rounded head where the nib turns, then the shaded stem down and out+const d = (x: number): P[] => [[x + 0.66, 0.84], [x + 0.44, 1.0], [x + 0.18, 0.94], [x, 0.64], [x - 0.03, 0.28], [x + 0.12, 0.02], [x + 0.34, 0.02], [x + 0.54, 0.3], [x + 0.66, 0.8],+ [x + 0.76, 1.45], [x + 0.84, 1.86], [x + 0.9, 1.95], [x + 0.84, 1.86], [x + 0.76, 1.3], [x + 0.7, 0.6], [x + 0.67, 0.12], [x + 0.75, 0.0], [x + 0.91, 0.08]];+const D1 = 2.5, O1 = 3.78, O2 = 4.52, X2 = 5.04;+const ANI: Stroke = [+ [0.8, 0.84], [0.58, 1.0], [0.3, 0.94], [0.08, 0.64], [0.04, 0.28], [0.2, 0.02], [0.44, 0.02], [0.66, 0.3], [0.8, 0.7], [0.86, 1.0],+ [0.83, 0.6], [0.79, 0.2], [0.84, 0.02], [0.98, 0.04], [1.12, 0.4], [1.2, 0.8], [1.24, 1.0],+ [1.22, 0.55], [1.19, 0.0], [1.23, 0.5], [1.36, 0.88], [1.54, 1.0], [1.7, 0.86], [1.72, 0.5], [1.68, 0.14], [1.76, 0.0], [1.9, 0.06], [2.02, 0.4], [2.1, 0.84], [2.13, 1.0],+ [2.1, 0.55], [2.06, 0.14], [2.12, 0.0], [2.28, 0.06], [D1 - 0.04, 0.3], // the i's exit just touches the d's bowl+];+const D1S: Stroke = [...d(D1), [D1 + 1.06, 0.14], on(O1, 208)]; // out of the d and up to kiss the first o+const OO: Stroke = oval(O1), BRIDGE: Stroke = [on(O1, 22), [(O1 + O2) / 2, 0.86], on(O2, 158)], OO2: Stroke = oval(O2);+const TO_D: Stroke = [on(O2, 20), [(O2 + X2) / 2 + 0.06, 0.84], [X2 + 0.02, 0.72]];+const at = (pts: P[]): P[] => pts.map(([x, y]) => [X2 + x, y]); // d-l-e is laid out from the second d+const DLE: Stroke = [+ ...d(X2), ...at([[1.11, 0.5], [1.31, 1.1], [1.47, 1.62], [1.49, 1.92], [1.37, 1.94], [1.27, 1.6], [1.21, 1.0], [1.17, 0.4], [1.21, 0.06], [1.35, 0.0], [1.51, 0.12],+ [1.67, 0.4], [1.87, 0.64], [1.95, 0.86], [1.87, 1.0], [1.71, 0.92], [1.63, 0.56], [1.65, 0.18], [1.81, 0.0], [2.07, 0.06], [2.37, 0.26],+ // the swash: up over a curl, a shaded fall, then one long hairline sweeping back under the word+ [2.72, 0.54], [3.06, 0.7], [3.28, 0.6], [3.3, 0.3], [3.16, -0.04], [2.86, -0.26], [2.26, -0.38], [1.26, -0.4], [0.16, -0.34], [-1.0, -0.24], [-1.8, -0.12]]),+];+// in writing order; the last one carries the swash, whose hairline tail runs long+export const WORD: Stroke[] = [ANI, D1S, OO, BRIDGE, OO2, TO_D, DLE];+export const TAIL = [0, 0, 0, 0, 0, 0, 0.3];+export const DOT: P = [2.2, 1.42];++export type Nib = { em: number; slant: number; origin: P; hair: number; shade: number };+export type Inked = { spine: P[]; w: number[]; len: number[] }; // screen centreline, half-width, cumulative length++// upright em -> screen: scale, slant (forward, as a hand slants), y flipped+export const place = (n: Nib, [x, y]: P): P => [n.origin[0] + (x + y * Math.tan(n.slant)) * n.em, n.origin[1] - y * n.em];++export const inkStroke = (n: Nib, s: Stroke, tail = 0): Inked => {+ const up = sample(s, false, 18), L = up.reduce((a, p, i) => (i ? a + Math.hypot(p[0] - up[i - 1][0], p[1] - up[i - 1][1]) : 0), 0);+ const u = resample(up, Math.max(24, Math.round(L * 90)));+ // raw pressure: the downward share of the direction, sharpened so only true downstrokes swell+ const raw = u.map((_, i) => { const a = u[Math.max(0, i - 1)], b = u[Math.min(u.length - 1, i + 1)], dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1; return Math.pow(clamp(-dy / l), 1.7); });+ // the nib's tines open and close over a short distance, never instantly+ const K = 5, sm = raw.map((_, i) => { let t = 0, c = 0; for (let j = -K; j <= K; j++) { const v = raw[i + j]; if (v !== undefined) { const wgt = K + 1 - Math.abs(j); t += v * wgt; c += wgt; } } return t / c; });+ const N = u.length;+ const w = sm.map((v, i) => { const t = i / (N - 1), taper = Math.min(1, t / 0.03, (1 - t) / (0.08 + tail)); return (n.hair + (n.shade - n.hair) * v) * (0.35 + 0.65 * clamp(taper)); });+ const spine = u.map((p) => place(n, p)), len = [0];+ for (let i = 1; i < N; i++) len.push(len[i - 1] + Math.hypot(spine[i][0] - spine[i - 1][0], spine[i][1] - spine[i - 1][1]));+ return { spine, w, len };+};++// the filled outline of the first `upto` px of an inked stroke (Infinity = all of it)+export const outlineOf = (k: Inked, upto = Infinity): P[] => {+ const s = k.spine, n = s.length, Lft: P[] = [], Rgt: P[] = [];+ for (let i = 0; i < n; i++) {+ if (k.len[i] > upto) break;+ const a = s[Math.max(0, i - 1)], b = s[Math.min(n - 1, i + 1)], dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1, nx = -dy / l, ny = dx / l;+ Lft.push([s[i][0] + nx * k.w[i], s[i][1] + ny * k.w[i]]); Rgt.push([s[i][0] - nx * k.w[i], s[i][1] - ny * k.w[i]]);+ }+ return [...Lft, ...Rgt.reverse()];+};diff --git a/engine/src/canvas-core/lighthouse.ts b/engine/src/canvas-core/lighthouse.tsnew file mode 100644index 0000000..069cba8--- /dev/null+++ b/engine/src/canvas-core/lighthouse.ts@@ -0,0 +1,129 @@+import { Gfx, fractal, rng, type Ctx, type Env, type P } from "./core";+import type { Film } from "./film";+import { INK, LITHO, PAPER, REG, across, drum, nearField, plateMarks, screen } from "./riso";+import { blob, clamp, fillShape, inside, smooth } from "./gallery";++// LIGHTHOUSE AT SUNSET · risograph. Printed the way a riso prints: one drum per ink, three+// passes. The YELLOW plate, the PINK plate and the BLUE plate are drawn separately below, each+// as its own layer that multiplies onto the paper through its own slightly-off registration.+// Every colour in the picture that is not one of those three is an OVERPRINT: blue over pink is+// the dusk violet, pink over yellow the sunset orange, yellow over blue the green of the turf.+// Tone is a halftone screen whose dots grow with a tone function, each ink on its own screen+// angle so they rosette instead of moiré. The paper is left bare wherever white is wanted: the+// tower's white bands, the foam where the swell hits the rocks, the light itself.+//+// The scene: a banded lighthouse on a grassy headland, a keeper's cottage beside it, the sun+// going down into the sea on the right and lighting everything from that side, the lamp just+// lit and throwing its beam out over the water, gulls, foam, sun-glitter on the swell.++const W = 1080, HY = 604, SUN: P = [790, 590], SR = 112, PITCH = 7.4;+const ANG = { yellow: 0, pink: 75, blue: 15 };++// ---------------------------------------------------------------- the geometry+const LAND: P[] = smooth([[-20, 498], [80, 486], [176, 552], [250, 572], [420, 578], [468, 598], [506, 636], [532, 684], [548, 728], [512, 752], [420, 762], [300, 754], [170, 746], [50, 742], [-20, 740]], true, 10);+const ROCKS: P[][] = [blob(872, 910, 74, 36, 81, 0.25, 16, -0.1), blob(150, 972, 92, 44, 82, 0.22, 16, 0.08), blob(600, 800, 34, 18, 83, 0.25, 12)];+const TOWER: P[] = [[278, 580], [382, 580], [364, 252], [296, 252]];+const GALLERY: P[] = [[280, 238], [380, 238], [380, 254], [280, 254]];+const LANTERN: P[] = [[302, 176], [358, 176], [358, 214], [302, 214]];+const DOME: P[] = Array.from({ length: 25 }, (_, i) => { const a = Math.PI + (i / 24) * Math.PI; return [330 + Math.cos(a) * 32, 178 + Math.sin(a) * 28] as P; });+const COTTAGE: P[] = [[132, 516], [252, 516], [252, 578], [132, 578]];+const ROOF: P[] = [[120, 520], [192, 470], [264, 520]];+const LAMP: P = [330, 195];+const occluders = [LAND, TOWER, GALLERY, LANTERN, DOME, COTTAGE, ROOF];+const rock = (x: number, y: number) => ROCKS.some((r) => inside(r, x, y));+const occluded = (x: number, y: number) => occluders.some((o) => inside(o, x, y));+const topOf = (() => { const t: number[] = []; for (let x = 0; x <= W; x++) { let m = 1e9; for (let i = 0, j = LAND.length - 1; i < LAND.length; j = i++) { const a = LAND[i], b = LAND[j]; if ((a[0] > x) !== (b[0] > x)) m = Math.min(m, a[1] + ((x - a[0]) * (b[1] - a[1])) / (b[0] - a[0])); } t.push(m); } return (x: number) => t[Math.max(0, Math.min(W, Math.round(x)))]; })();+const shore = nearField([LAND.filter(([, y]) => y > HY - 10), ...ROCKS.map((r) => [...r, r[0]])], 24);+// turf only where the top of the land is nearly flat; where it drops away it is the cliff face+const turf = (x: number, y: number) => inside(LAND, x, y) && y - topOf(x) < 46 && Math.abs(topOf(x + 6) - topOf(x - 6)) < 9;+const cliff = (x: number, y: number) => inside(LAND, x, y) && !turf(x, y);+const towerX = across(TOWER, "x");+// the beam: a narrow wedge from the lamp out over the water to the left, fading with distance+const beam = (x: number, y: number) => { const dx = x - LAMP[0], dy = y - LAMP[1], d = Math.hypot(dx, dy); if (d < 30 || dx > 0) return 0; const a = Math.atan2(dy, dx), c = -2.94, spread = 0.07 + d * 0.0001; return Math.pow(clamp(1 - Math.abs(a - c) / spread), 0.7) * clamp(1.25 - d / 820); };+const sunD = (x: number, y: number) => Math.hypot(x - SUN[0], y - SUN[1]);+const inSun = (x: number, y: number) => sunD(x, y) < SR && y < HY;+const sea = (x: number, y: number) => y > HY && !inside(LAND, x, y) && !rock(x, y);+const glitter = (x: number, y: number) => { const col = clamp(1 - Math.abs(x - SUN[0]) / (70 + (y - HY) * 0.35)); return col * clamp((fractal(51, x * 0.5, y * 3, 0.06, 0.06, 2) - 0.46) * 5); };+const foam = (x: number, y: number) => sea(x, y) && shore(x, y) < Math.max(0, fractal(61, x, y, 0.035, 0.05, 3) - 0.38) * 70 + (fractal(62, x, y, 0.2, 0.2, 2) > 0.62 ? 5 : 0); // broken, bunched where the swell breaks++// ---------------------------------------------------------------- the three plates+const yellowPlate = (g: Gfx) => drum(g, REG.yellow, () => {+ const all = { x0: 0, y0: 0, x1: W, y1: W };+ // sky: warmer toward the horizon and the sun, the beam laid in as light+ screen(g, all, PITCH, ANG.yellow, (x, y) => { if (y >= HY || occluded(x, y) || inSun(x, y)) return 0; return 0.12 + 0.62 * Math.pow(y / HY, 1.6) + 0.5 * Math.exp(-Math.pow(sunD(x, y) / 260, 2)) + 0.45 * beam(x, y); }, INK.yellow);+ fillShape(g, Array.from({ length: 48 }, (_, i) => [SUN[0] + Math.cos((i / 48) * Math.PI * 2) * SR, Math.min(HY, SUN[1] + Math.sin((i / 48) * Math.PI * 2) * SR)] as P), INK.yellow);+ // sea: the sun's path, and a warm cast on the near swell+ screen(g, all, PITCH, ANG.yellow, (x, y) => (sea(x, y) && !foam(x, y) ? 0.7 * glitter(x, y) + 0.1 : 0), INK.yellow);+ // turf: yellow under the blue makes the green, heavier where the sun rakes across it+ screen(g, all, PITCH, ANG.yellow, (x, y) => (turf(x, y) ? 0.74 + 0.25 * (x / 540) : cliff(x, y) || rock(x, y) ? 0.2 : 0), INK.yellow);+ // the warm side of the tower and cottage, the lit lantern, the cottage windows+ screen(g, all, PITCH, ANG.yellow, (x, y) => (inside(TOWER, x, y) ? 0.26 * Math.pow(towerX(x, y), 1.8) : 0), INK.yellow, TOWER);+ fillShape(g, LANTERN, INK.yellow); fillShape(g, blob(LAMP[0], LAMP[1], 40, 34, 7, 0.1, 16), INK.yellow, 0.5);+ [[150, 532, 26, 22], [212, 532, 26, 22]].forEach(([x, y, w, h]) => fillShape(g, [[x, y], [x + w, y], [x + w, y + h], [x, y + h]], INK.yellow));+});++const pinkPlate = (g: Gfx) => drum(g, REG.pink, () => {+ const all = { x0: 0, y0: 0, x1: W, y1: W };+ // sky: a band of pink across the middle of the dusk, deeper round the sun+ screen(g, all, PITCH, ANG.pink, (x, y) => { if (y >= HY || occluded(x, y)) return 0; if (inSun(x, y)) return 0.18 + 0.7 * clamp((y - (SUN[1] - SR * 0.3)) / (SR * 0.9)); return 0.3 * (1 - y / HY) + 0.6 * Math.exp(-Math.pow((y - 430) / 170, 2)) + 0.35 * Math.exp(-Math.pow(sunD(x, y) / 220, 2)) + 0.08; }, INK.pink);+ // sea: the sky's pink caught near the horizon, and the glitter+ screen(g, all, PITCH, ANG.pink, (x, y) => (sea(x, y) && !foam(x, y) ? 0.42 * clamp(1 - (y - HY) / 230) + 0.55 * glitter(x, y) : 0), INK.pink);+ // the tower's four red bands, the dome, the cottage roof+ const band = (y0: number, y1: number): P[] => { const hw = (y: number) => 52 - ((580 - y) / 328) * 18; return [[330 - hw(y1), y1], [330 + hw(y1), y1], [330 + hw(y0), y0], [330 - hw(y0), y0]]; };+ [[292, 334], [376, 418], [460, 502], [540, 580]].forEach(([a, b]) => fillShape(g, band(b, a), INK.pink));+ fillShape(g, DOME, INK.pink); fillShape(g, GALLERY, INK.pink, 0.6);+ fillShape(g, ROOF, INK.pink);+ // rock faces on the seaward cliff catching the last of the sun+ const r = rng(80);+ screen(g, all, PITCH, ANG.pink, (x, y) => (cliff(x, y) ? 0.2 + 0.55 * clamp((x - 220) / 320) * (0.6 + 0.6 * fractal(84, x, y, 0.04, 0.02, 2)) : 0), INK.pink); // the cliff face warms toward the sun+ ROCKS.forEach((rk) => screen(g, all, PITCH, ANG.pink, (x) => { const b = rk.reduce((m, p) => Math.max(m, p[0]), -1e9), a = rk.reduce((m, p) => Math.min(m, p[0]), 1e9); return 0.15 + 0.6 * clamp((x - a) / (b - a)); }, INK.pink, rk));+});++const bluePlate = (g: Gfx) => drum(g, REG.blue, () => {+ const all = { x0: 0, y0: 0, x1: W, y1: W };+ // sky: night coming down from the top, pulled back where the beam cuts through+ screen(g, all, PITCH, ANG.blue, (x, y) => { if (y >= HY || occluded(x, y) || inSun(x, y)) return 0; return (0.05 + 0.66 * Math.pow(1 - y / HY, 1.4)) * (1 - 0.8 * beam(x, y)); }, INK.blue);+ // sea: deepening toward us, rolled into swells, left bare as foam against the rocks+ screen(g, all, PITCH, ANG.blue, (x, y) => { if (!sea(x, y) || foam(x, y)) return 0; const k = (y - HY) / (W - HY), swell = 0.5 + 0.5 * Math.sin(y * 0.09 + fractal(71, x, y, 0.004, 0.02, 2) * 6); return (0.34 + 0.34 * k) * (0.75 + 0.35 * swell) * (1 - 0.6 * glitter(x, y)); }, INK.blue);+ // land: the turf takes a light blue (for the green), the cliff below goes deep into shadow+ screen(g, all, PITCH, ANG.blue, (x, y) => (turf(x, y) ? 0.44 - 0.2 * (x / 540) : cliff(x, y) ? 0.5 + 0.25 * clamp((y - topOf(x)) / 160) - 0.25 * clamp((x - 300) / 260) : rock(x, y) ? 0.62 : 0), INK.blue);+ // the tower and cottage turned away from the sun: shadow on the left of every form+ screen(g, all, PITCH, ANG.blue, (x, y) => (inside(TOWER, x, y) ? 0.08 + 0.62 * Math.pow(1 - towerX(x, y), 1.8) : 0), INK.blue, TOWER);+ screen(g, all, PITCH, ANG.blue, (x) => 0.55 - 0.004 * (x - 132), INK.blue, COTTAGE);+ screen(g, all, PITCH, ANG.blue, (x) => (x < 192 ? 0.55 : 0.1), INK.blue, ROOF);+ screen(g, all, PITCH, ANG.blue, (x) => 0.1 + 0.6 * clamp((330 - x) / 32), INK.blue, DOME);+ // the key plate's solids: door, windows, gallery rail, mullions, chimney, finial+ const solid = (pts: P[]) => fillShape(g, pts, INK.blue);+ solid(smooth([[314, 580], [314, 548], [322, 538], [338, 538], [346, 548], [346, 580]], false, 4).concat([[314, 580]]));+ [[322, 460], [330, 380], [336, 300]].forEach(([x, y]) => solid([[x - 4, y - 12], [x + 4, y - 12], [x + 4, y + 10], [x - 4, y + 10]]));+ solid([[278, 250], [382, 250], [382, 256], [278, 256]]); solid([[282, 212], [378, 212], [378, 216], [282, 216]]);+ for (let x = 284; x <= 376; x += 9) solid([[x - 1, 214], [x + 1, 214], [x + 1, 240], [x - 1, 240]]);+ [308, 322, 338, 352].forEach((x) => solid([[x - 1.2, 176], [x + 1.2, 176], [x + 1.2, 214], [x - 1.2, 214]]));+ solid([[300, 174], [360, 174], [360, 178], [300, 178]]);+ solid(Array.from({ length: 12 }, (_, i) => [330 + Math.cos((i / 12) * Math.PI * 2) * 6, 146 + Math.sin((i / 12) * Math.PI * 2) * 6] as P)); solid([[329, 126], [331, 126], [331, 146], [329, 146]]);+ solid([[222, 474], [236, 474], [236, 500], [222, 500]]); // chimney+ solid([[178, 546], [198, 546], [198, 578], [178, 578]]); // cottage door+ [[150, 532], [212, 532]].forEach(([x, y]) => { solid([[x, y], [x + 26, y], [x + 26, y + 2.4], [x, y + 2.4]]); solid([[x + 12, y], [x + 14, y], [x + 14, y + 22], [x + 12, y + 22]]); solid([[x, y + 20], [x + 26, y + 20], [x + 26, y + 23], [x, y + 23]]); });+ // key lines in litho crayon: the tower's edges, the cliff's cracks, the swell, the gulls+ const pen = (pts: P[], w: number, seed: number, op = 0.9) => { g.pen(pts, { w, color: INK.blue, seed, wobble: 0.6, boil: 0, opacity: op, retrace: false }); };+ pen([[278, 580], [288, 420], [296, 252]], 1.6, 900); pen([[382, 580], [372, 420], [364, 252]], 1.2, 901, 0.7);+ const r = rng(910);+ for (let i = 0; i < 18; i++) { const x = 200 + r() * 340, y = 640 + r() * 110; if (!cliff(x, y)) continue; pen([[x, y], [x - 10 - r() * 20, y + 16 + r() * 20], [x - 4 - r() * 26, y + 40 + r() * 30]], 1.2, 920 + i, 0.75); }+ ROCKS.forEach((rk, i) => pen([...rk.slice(0, Math.round(rk.length * 0.6))], 1.6, 940 + i, 0.85));+ for (let i = 0; i < 38; i++) { const y = HY + 14 + Math.pow(r(), 1.3) * 460, x = 560 + r() * 520, l = 18 + (y - HY) * 0.12 + r() * 20; if (!sea(x, y) || foam(x, y) || Math.abs(x - SUN[0]) < 60) continue; pen([[x, y], [x + l * 0.5, y - 3], [x + l, y]], 1.1 + (y - HY) / 300, 960 + i, 0.8); }+ [[560, 300, 1], [612, 272, 0.8], [640, 330, 0.7], [180, 200, 0.9]].forEach(([x, y, s], i) => pen([[x - 16 * s, y - 2 * s], [x - 7 * s, y - 8 * s], [x, y], [x + 7 * s, y - 8 * s], [x + 16 * s, y - 2 * s]], 1.6, 1000 + i));+});++export const drawLighthouse = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, LITHO);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, W, W);+ yellowPlate(g); pinkPlate(g); bluePlate(g);+ plateMarks(g, W, W, [INK.yellow, INK.pink, INK.blue]);+};++export const lighthouse: Film = {+ meta: { title: "Lighthouse at sunset · risograph", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "lighthouse", start: 0, end: 1, draw: drawLighthouse }],+};diff --git a/engine/src/canvas-core/mellan.ts b/engine/src/canvas-core/mellan.tsnew file mode 100644index 0000000..e35d6e1--- /dev/null+++ b/engine/src/canvas-core/mellan.ts@@ -0,0 +1,140 @@+import { fractal, rng, type Ctx, type Env, type P } from "./core";+import type { Film } from "./film";+import { clamp } from "./gallery";++// MELLAN SPIRAL · a lit moon. Claude Mellan's 1649 "Sudarium of Saint Veronica" is one unbroken+// engraved line, a spiral starting at the tip of the nose, whose weight alone makes the picture:+// the burin swells where the plate should print dark and runs to a hair where it should be light.+//+// This is that technique, asset-free. There is no source image: `tone(x, y)` is a procedural+// field (a sphere lit from the upper left, seeded maria, craters with a lit rim and a shadowed+// floor, earthshine on the night side, a dark engraved sky), and ONE Archimedean spiral is walked+// out from the centre, its width set at every step from the local tone. The whole picture is a+// single filled ribbon: one continuous stroke, never lifted.++const W = 1080, C: P = [540, 540], PLATE = 46; // the copper plate's edge; nothing outside it prints+const PITCH = 6.2; // distance between neighbouring turns, px+const MOON_R = 380, MOON_C: P = [548, 526];+const LIGHT = (() => { const v = [-0.66, -0.52, 0.54]; const l = Math.hypot(...v); return v.map((x) => x / l); })();+const L2 = (() => { const l = Math.hypot(LIGHT[0], LIGHT[1]); return [LIGHT[0] / l, LIGHT[1] / l]; })();+const INKC = "#17130f", PAPER = "#f2ead8";+const smoothstep = (a: number, b: number, x: number) => { const t = clamp((x - a) / (b - a)); return t * t * (3 - 2 * t); };++type Crater = { u: number; v: number; r: number; depth: number; rays: boolean };+const craters: Crater[] = (() => {+ const r = rng(4411), out: Crater[] = [];+ for (let i = 0; i < 30; i++) out.push({ u: (r() - 0.5) * 2.2, v: (r() - 0.5) * 1.9, r: 0.065 + Math.pow(r(), 2) * 0.2, depth: 0.6 + r() * 0.4, rays: false });+ out.push({ u: -0.28, v: 0.52, r: 0.075, depth: 1, rays: true }); // one young crater throwing bright rays, the way Tycho does+ return out;+})();++// brightness of the plate at (x, y): 0 = print black, 1 = paper+export const tone = (x: number, y: number): number => {+ const dx = (x - MOON_C[0]) / MOON_R, dy = (y - MOON_C[1]) / MOON_R, d2 = dx * dx + dy * dy;+ const sky = 0.09 + 0.05 * fractal(91, x, y, 0.004, 0.004, 3);+ if (d2 >= 1) {+ const dd = Math.sqrt(d2), lit = clamp(-(dx * L2[0] + dy * L2[1]) / dd + 0.35);+ return clamp(sky + Math.exp(-(dd - 1) * 7) * 0.2 * lit); // the moon lightens the sky a little at its lit limb+ }+ const z = Math.sqrt(1 - d2), u = Math.atan2(dx, z), v = Math.asin(clamp(dy, -1, 1));+ // albedo: dark maria are big soft-edged basins, the highlands bright+ const m = fractal(207, u * 60 + 200, v * 60 + 200, 0.016, 0.016, 4);+ let alb = 0.96 - 0.4 * smoothstep(0.44, 0.66, m) - 0.08 * fractal(208, u * 60, v * 60, 0.09, 0.09, 2);+ const lam = Math.max(0, dx * LIGHT[0] + dy * LIGHT[1] + z * LIGHT[2]);+ let shade = Math.pow(lam, 0.72);+ // craters: a shadow crescent inside the rim on the side FACING the light (the near wall hides+ // the floor), the far wall lit, a bright rim toward the light. Strongest near the terminator,+ // where the low sun throws the longest shadows.+ const low = 0.7 + 0.3 * (1 - smoothstep(0.15, 0.85, lam)); // craters read everywhere, longest shadows near the terminator+ for (const c of craters) {+ const du = (u - c.u) / c.r, dv = (v - c.v) / c.r, q = Math.sqrt(du * du + dv * dv);+ if (c.rays && q < 9) { const ang = Math.atan2(dv, du), ray = Math.pow(Math.abs(Math.sin(ang * 5.5 + 0.7)), 18) + Math.pow(Math.abs(Math.sin(ang * 3.2 + 2)), 30); alb += 0.22 * ray * Math.exp(-q * 0.28) * (q > 1.3 ? 1 : 0); }+ if (q > 1.4) continue;+ const toward = q > 1e-6 ? (du * L2[0] + dv * L2[1]) / q : 0; // +1 on the side of the crater nearest the light+ if (q < 1) { const crescent = smoothstep(-0.2, 0.5, toward) * smoothstep(0.2, 0.9, q + 0.25); shade *= 1 - 0.85 * c.depth * low * crescent; shade *= 1 + 0.3 * c.depth * smoothstep(0.1, 0.7, -toward) * low; alb -= (c.r > 0.15 ? 0.14 : 0.05) * c.depth; }+ else { const rim = 1 - smoothstep(1, 1.4, q); alb += 0.12 * c.depth * rim * smoothstep(-0.2, 0.6, toward); shade *= 1 - 0.45 * c.depth * rim * smoothstep(0, 0.7, -toward) * low; }+ }+ const limb = Math.pow(1 - z, 3) * 0.3 * clamp(-(dx * L2[0] + dy * L2[1]) * 2);+ const earthshine = 0.24 + 0.06 * alb;+ return clamp(earthshine + (1 - earthshine) * clamp(shade) * clamp(alb) + limb);+};++// Walk ONE Archimedean spiral r = a*theta outward from the centre in near-constant arc steps,+// and turn it into a single ribbon whose half-width comes from the tone underneath. The walk is+// a pure function of nothing but the constants above, so it is done ONCE and cached; a frame of+// the unspooling film takes a prefix of it. (Re-walking and re-shading 70,000 steps every frame+// put the animation over its draw budget on half its frames.)+export type Ribbon = { L: P[]; R: P[]; ink: number[]; th: number[]; base: number[] }; // ink[k]: how much ink the line has laid by step k; th[k]: its spiral angle; base: the indices of the still's own samples+// maxStep caps the angle per step. The still never needs it (Infinity); the unspooling film opens+// at ~60x on the first turns, where 1.4 px chords around a 3 px circle show as polygon corners.+// It SUBDIVIDES between the still's own samples rather than re-walking, so every vertex past the+// first turns is the still's exact vertex, and the finished film frame can be the still itself.+const walk = (maxStep = Infinity): Ribbon => {+ const a = PITCH / (Math.PI * 2), rMax = Math.hypot(W / 2, W / 2) + PITCH, thMax = rMax / a;+ const L: P[] = [], R: P[] = [], ink: number[] = [], ths: number[] = [], base: number[] = [];+ let laid = 0;+ let th = 0.6;+ while (th < thMax) {+ const step = 1.4 / Math.max(a * th, 1.4), m = Math.max(1, Math.ceil(step / maxStep)); // ~1.4 px of line per step+ for (let j = 0; j < m; j++) {+ if (!j) base.push(L.length);+ const t = j ? th + (step * j) / m : th;+ const r = a * t, x = C[0] + Math.cos(t) * r, y = C[1] + Math.sin(t) * r;+ // outward normal of the spiral ~ radial; its weight is the engraver's only variable+ const dark = 1 - tone(x, y), grow = Math.min(1, r / 40); // the first turns open gently from a point+ const w = PITCH * (0.05 + 0.86 * dark) * grow / 2;+ const tx = -Math.sin(t) * r + Math.cos(t) * a, ty = Math.cos(t) * r + Math.sin(t) * a, tl = Math.hypot(tx, ty), nx = ty / tl, ny = -tx / tl;+ L.push([x + nx * w, y + ny * w]); R.push([x - nx * w, y - ny * w]);+ const onPlate = x > PLATE && x < W - PLATE && y > PLATE && y < W - PLATE;+ laid += onPlate ? (2 * w * 1.4) / m : 0; ink.push(laid); ths.push(t); // ink that lands OFF the plate is cut away by the clip: it must not cost the film any time+ }+ th += step;+ }+ return { L, R, ink, th: ths, base };+};+export const SPIRAL_A = PITCH / (Math.PI * 2); // r = SPIRAL_A * theta+export const ribbon = (cache?: Map<string, unknown>, maxStep = Infinity): Ribbon => {+ const key = `mellan:ribbon:${PITCH}:${MOON_R}:${maxStep}`; // everything the ribbon depends on is a constant of this module+ let rb = cache?.get(key) as Ribbon | undefined;+ if (!rb) { rb = walk(maxStep); cache?.set(key, rb); }+ return rb;+};+// the closed outline of the first k steps: out along one edge, back along the other+export const outline = (rb: Ribbon, k: number): P[] => [...rb.L.slice(0, k), ...rb.R.slice(0, k).reverse()];+// the still's finished outline, taken from a subdivided ribbon without walking again+export const stillOutline = (rb: Ribbon): P[] => [...rb.base.map((i) => rb.L[i]), ...rb.base.map((i) => rb.R[i]).reverse()];+export const spiral = (progress = 1, cache?: Map<string, unknown>): P[] => {+ const rb = ribbon(cache);+ // progress is a fraction of the INK, not of the length: a hairline across the bright face adds+ // almost nothing to look at, so equal length per frame would be dead air. Equal ink per frame+ // means the burin races through the light and slows where it cuts deep, as a real one does.+ const n = rb.ink.length, want = rb.ink[n - 1] * clamp(progress);+ let k = n; if (progress < 1) { let lo = 0, hi = n - 1; while (lo < hi) { const m = (lo + hi) >> 1; if (rb.ink[m] < want) lo = m + 1; else hi = m; } k = Math.max(2, lo + 1); }+ return outline(rb, k);+};++// Print a ribbon outline (null = the clean, uninked plate) through a camera that looks at the+// spiral's centre with magnification `zoom` (1 = the whole plate, exactly the still's framing).+export const printPlate = (ctx: Ctx, env: Env, rib: P[] | null, zoom = 1) => {+ const s = env.scale * zoom, o = (1 - zoom) * C[0] * env.scale;+ ctx.setTransform(s, 0, 0, s, o, o);+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, W, W);+ ctx.save();+ ctx.beginPath(); ctx.rect(PLATE, PLATE, W - 2 * PLATE, W - 2 * PLATE); ctx.clip(); // the plate: the spiral prints only inside it+ if (rib) {+ ctx.fillStyle = INKC; ctx.beginPath();+ rib.forEach(([x, y], i) => (i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)));+ ctx.closePath(); ctx.fill();+ }+ ctx.restore();+ // the plate mark: the copper's bevelled edge pressed into damp paper, a hair of shadow on two sides+ ctx.strokeStyle = "rgba(60,45,30,0.28)"; ctx.lineWidth = 2; ctx.strokeRect(40, 40, W - 80, W - 80);+ ctx.strokeStyle = "rgba(255,252,240,0.7)"; ctx.lineWidth = 1.2; ctx.strokeRect(38.5, 38.5, W - 80, W - 80);+};+export const drawMellan = (ctx: Ctx, frame: number, env: Env, progress = 1) => { void frame; printPlate(ctx, env, spiral(progress, env.cache)); };++export const mellan: Film = {+ meta: { title: "Mellan spiral · a lit moon", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "moon", start: 0, end: 1, draw: (ctx, f, env) => drawMellan(ctx, f, env, 1) }],+};diff --git a/engine/src/canvas-core/mellanUnspool.ts b/engine/src/canvas-core/mellanUnspool.tsnew file mode 100644index 0000000..0d5e8ad--- /dev/null+++ b/engine/src/canvas-core/mellanUnspool.ts@@ -0,0 +1,52 @@+import type { Film } from "./film";+import { outline, printPlate, ribbon, SPIRAL_A, stillOutline } from "./mellan";++// MELLAN SPIRAL · unspooling. The still's single line, engraved from nothing, watched through a+// camera that is carried out by the burin.+//+// Frame 0 is the clean plate: paper, no ink. From frame 1 the line leaves the exact centre and+// winds outward, and the camera, which opens at ~60x on that point, pulls back in step with it,+// so the tip always sits at the same place on screen while the moon assembles around it. The+// pull-back eases to rest on the whole plate as the line passes the moon's limb; the last turns+// fill the sky's corners under a still camera, and the last frame is the still, exactly.+//+// Everything is paced by the spiral's ANGLE, not its length or ink: on a spiral the camera must+// follow the radius, and radius is angle (r = a * theta), so one clock drives both.+const N = 240; // 8 s at 30 fps+const FINE = 0.02; // max radians per ribbon step, for the close-up opening+const V0 = 9, K = 1.3; // view half-width = V0 + K * tip radius (world px)+const HALF = 540, KNEE = 130; // the whole plate, and how softly the camera lands on it+const R_LAST = 700; // past this radius the spiral is clipped away entirely (plate corner = 494 * sqrt 2)++// angular speed over the film, in relative units: a readable curl at the start, rising as the+// turns get longer. It does NOT ease out: the camera does the settling, and the last turns are+// short corner slivers, so a slowing line there left the final half second measurably dead.+const speed = (u: number) => 0.12 + u ** 1.7;+const clock = (() => { // theta at the tip for each frame, frame 0 = nothing+ const th0 = 0.6, th1 = R_LAST / SPIRAL_A, out = [0];+ let acc = 0; const inc: number[] = [];+ for (let f = 1; f < N; f++) { acc += speed((f - 1) / (N - 2)); inc.push(acc); }+ inc.forEach((a) => out.push(th0 + ((th1 - th0) * a) / acc));+ return out;+})();+// view half-width for a tip at radius r: proportional, then a C1 quadratic landing on the plate+const view = (r: number) => {+ const raw = V0 + K * r;+ if (raw <= HALF - KNEE) return raw;+ if (raw >= HALF + KNEE) return HALF;+ const d = raw - (HALF - KNEE); return raw - (d * d) / (4 * KNEE);+};++export const mellanUnspool: Film = {+ meta: { title: "Mellan spiral · unspooling", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: N },+ assets: { images: {} },+ shots: [{+ id: "unspool", start: 0, end: N, draw: (ctx, f, env) => {+ const rb = ribbon(env.cache, FINE), th = clock[f], n = rb.th.length;+ if (f === 0) return printPlate(ctx, env, null, HALF / V0); // the clean slate, already framed on the centre+ if (f === N - 1) return printPlate(ctx, env, stillOutline(rb), 1); // the finished plate: the still, pixel for pixel+ let lo = 0, hi = n - 1; while (lo < hi) { const m = (lo + hi) >> 1; if (rb.th[m] < th) lo = m + 1; else hi = m; }+ printPlate(ctx, env, outline(rb, Math.max(2, lo + 1)), HALF / view(SPIRAL_A * th));+ },+ }],+};diff --git a/engine/src/canvas-core/moonPhases.ts b/engine/src/canvas-core/moonPhases.tsnew file mode 100644index 0000000..7fb867f--- /dev/null+++ b/engine/src/canvas-core/moonPhases.ts@@ -0,0 +1,154 @@+import { Gfx, fractal, rng, type Ctx, type Env, type Medium, type P } from "./core";+import type { Film } from "./film";+import { letter } from "./drafting";+import { blob, clamp, fillShape, hatchRuns, inside, lerpP, smooth } from "./gallery";++// MOON PHASES · chalkboard. A teacher's board after a good lesson: the phases arc across the+// slate the way the moon crosses the sky, each one scumbled in with the side of the chalk and+// the lit limb worked over a second time, the terminator where the lit side and earthshine+// meet, maria left thin where the chalk skipped, a finger-smudged glow round the full moon.+// Chalk never makes a clean line: every stroke is broken by the board's tooth and sheds a haze+// of dust either side of itself. Behind it all, the ghosts of lessons not quite erased. A wooden+// frame, a ledge with a stub of chalk and a felt eraser.++const CHALK_M: Medium = { nib: 2.1, taper: 0.55, pressure: 0.95, retrace: true, wobble: 1.4, rough: 1.2 };+const CHALK = "#f4f0e6", YEL = "#f6e6a4", BLUE = "#a9d3e8", PINK = "#f3c1cf";+const B0 = 34, B1 = 1046, LEDGE = 958; // the board's inner edges++// chalk: one pass of dust (wide, soft, faint), then the stroke itself broken by the board's tooth+const chalk = (g: Gfx, draw: (dust: boolean) => void, dustAlpha = 0.2) => {+ g.group("plain", () => draw(true), { blur: 3.2, alpha: dustAlpha });+ g.group("plain", () => draw(false), { textures: ["pencilTooth", "risoSpeck"] });+};+const line = (g: Gfx, dust: boolean, pts: P[], w: number, color: string, seed: number, op = 0.92, wob = 1) =>+ g.pen(pts, { w: dust ? w * 2.6 : w, color, seed, wobble: wob, boil: 0, opacity: op, retrace: !dust, taper: 1 });+// the side of the chalk dragged back and forth: a scumble, clipped to a shape, thinning where `keep` says so+const scumble = (g: Gfx, dust: boolean, region: P[], color: string, o: { angle: number; gap: number; w: number; alpha: number; seed: number; keep?: (x: number, y: number) => boolean }) => {+ const { angle, gap, w, alpha, seed, keep = () => true } = o, r = rng(seed);+ let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; region.forEach(([x, y]) => { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); });+ const c = g.cur; g.touch(x0 - 12, y0 - 12, x1 + 12, y1 + 12);+ c.save(); c.lineCap = "round"; c.lineJoin = "round"; c.strokeStyle = color; c.lineWidth = dust ? w * 2.2 : w;+ hatchRuns({ x0, y0, x1, y1 }, angle, gap, (x, y) => inside(region, x, y) && keep(x, y), 4, seed).forEach((run) => {+ c.globalAlpha = alpha * (0.86 + r() * 0.2); c.beginPath(); // a steady hand: grain comes from the board, not from stripes of pressure+ run.filter((_, k, a) => k % 2 === 0 || k === a.length - 1).forEach(([x, y], k) => (k ? c.lineTo(x + (r() - 0.5) * 1.5, y + (r() - 0.5) * 1.5) : c.moveTo(x, y)));+ c.stroke();+ });+ c.restore();+};++// ---------------------------------------------------------------- one moon+// `lit` is the illuminated fraction. The terminator is half an ellipse whose width is+// r * (1 - 2 * lit): a crescent's bulges toward the lit limb, a gibbous moon's away from it.+const moon = (g: Gfx, cx: number, cy: number, r: number, lit: number, waxing: boolean, seed: number) => {+ const s = waxing ? 1 : -1, tx = r * (1 - 2 * lit), N = 40;+ const disk: P[] = Array.from({ length: 72 }, (_, i) => [cx + Math.cos((i / 72) * Math.PI * 2) * r, cy + Math.sin((i / 72) * Math.PI * 2) * r]);+ const limb: P[] = [], term: P[] = [];+ for (let i = 0; i <= N; i++) { const a = -Math.PI / 2 + (i / N) * Math.PI; limb.push([cx + s * Math.cos(a) * r, cy + Math.sin(a) * r]); }+ for (let i = 0; i <= N; i++) { const a = Math.PI / 2 - (i / N) * Math.PI; term.push([cx + s * Math.cos(a) * tx, cy + Math.sin(a) * r]); }+ const litShape = [...limb, ...term];+ const mare = (x: number, y: number) => fractal(seed, (x - cx) * 60 / r, (y - cy) * 60 / r, 0.03, 0.03, 3) + (fractal(seed + 3, x, y, 0.45, 0.45, 2) - 0.5) * 0.16 < 0.52 + (lit > 0.95 ? 0.06 : 0); // where the chalk skipped: the dark seas, their edges crumbling+ if (lit > 0.9) g.group("plain", () => g.glow(cx, cy, r * 1.1, "#fff6e0", 0.2)); // the full moon, smudged out with a finger+ chalk(g, (dust) => {+ if (dust) scumble(g, dust, disk, CHALK, { angle: 0.7, gap: 5, w: 5, alpha: 0.32, seed: seed + 1 }); // earthshine: chalk rubbed into the board with a finger+ const lc = lit > 0.9 ? "#f8f0d6" : CHALK;+ scumble(g, dust, litShape, lc, { angle: -0.9 + (seed % 5) * 0.12, gap: 3, w: 4.4, alpha: 0.4, seed: seed + 2 }); // the whole lit face, evenly+ scumble(g, dust, litShape, lc, { angle: 0.75 + (seed % 3) * 0.1, gap: 3.2, w: 4.2, alpha: 0.42, seed: seed + 8, keep: (x, y) => !mare(x, y) }); // the highlands built up across it: the seas are just less chalk+ scumble(g, dust, litShape, CHALK, { angle: 0.5, gap: 5, w: 3.6, alpha: 0.45, seed: seed + 3, keep: (x, y) => Math.hypot(x - cx, y - cy) > r * 0.62 && (x - cx) * s > -r * 0.2 }); // the limb, gone over again+ if (!dust) {+ const cr = rng(seed + 4);+ for (let k = 0; k < 5; k++) { const a = cr() * Math.PI * 2, d = cr() * r * 0.75, px = cx + Math.cos(a) * d, py = cy + Math.sin(a) * d; if (!inside(litShape, px, py)) continue; const rr = 3 + cr() * r * 0.09; line(g, dust, Array.from({ length: 9 }, (_, i) => [px + Math.cos((i / 8) * Math.PI * 2) * rr, py + Math.sin((i / 8) * Math.PI * 2) * rr * 0.9] as P), 0.9, CHALK, seed + 10 + k, 0.55, 0.3); }+ }+ line(g, dust, limb.filter((_, i) => i % 3 === 0 || i === N), 2.3, CHALK, seed + 5, 0.95); // the lit limb, firm+ const back: P[] = []; for (let i = 0; i <= N; i++) { const a = Math.PI / 2 + (i / N) * Math.PI; back.push([cx + s * Math.cos(a) * r, cy + Math.sin(a) * r]); }+ line(g, dust, back.filter((_, i) => i % 3 === 0 || i === N), 1.3, CHALK, seed + 6, 0.45); // the dark limb, barely+ if (lit < 0.97) line(g, dust, term.filter((_, i) => i % 4 === 0 || i === N), 1.1, CHALK, seed + 7, 0.5, 0.5);+ });+};++// ---------------------------------------------------------------- the board+const board = (g: Gfx, ctx: Ctx) => {+ const gr = ctx.createRadialGradient(540, 470, 60, 540, 470, 720);+ gr.addColorStop(0, "#35493f"); gr.addColorStop(0.62, "#27352f"); gr.addColorStop(1, "#1b2622");+ ctx.fillStyle = gr; ctx.fillRect(0, 0, 1080, 1080);+ g.paper("coldpress", 0.3);+ // the ghosts of erased lessons: wide swipes of haze, and old writing not quite gone+ g.group("plain", () => {+ const r = rng(5);+ for (let i = 0; i < 9; i++) { const cx = 120 + r() * 840, cy = 120 + r() * 760, rr = 120 + r() * 160, a0 = r() * 6; const pts: P[] = []; for (let k = 0; k <= 12; k++) { const a = a0 + (k / 12) * 2.2; pts.push([cx + Math.cos(a) * rr, cy + Math.sin(a) * rr * 0.55]); } g.pen(pts, { w: 40 + r() * 30, color: CHALK, seed: 6 + i, wobble: 3, boil: 0, opacity: 0.05, retrace: false, taper: 0.4 }); }+ }, { blur: 9 });+ g.group("plain", () => { letter(g, "HOMEWORK P 42", 140, 780, { cap: 28, color: CHALK, seed: 40, opacity: 0.12 }); letter(g, "NEWTON", 700, 796, { cap: 26, color: CHALK, seed: 41, opacity: 0.1 }); }, { blur: 2.4 });+};++const frame = (g: Gfx) => {+ g.group("plain", () => {+ const wood = "#7b5231", dark = "#553620", r = rng(70);+ fillShape(g, [[0, 0], [1080, 0], [1080, B0], [0, B0]], wood); fillShape(g, [[0, 0], [B0, 0], [B0, 1080], [0, 1080]], wood); fillShape(g, [[B1, 0], [1080, 0], [1080, 1080], [B1, 1080]], wood);+ fillShape(g, [[0, LEDGE], [1080, LEDGE], [1080, 1080], [0, 1080]], "#6a4526");+ fillShape(g, [[B0 - 8, LEDGE - 4], [B1 + 8, LEDGE - 4], [B1 + 20, LEDGE + 24], [B0 - 20, LEDGE + 24]], "#8c6139"); // the ledge's top face, catching the light+ for (let i = 0; i < 26; i++) { const y = r() * 1080, x = r() < 0.5 ? r() * B0 : B1 + r() * B0; g.pen([[x, y], [x + (r() - 0.5) * 3, y + 40 + r() * 60]], { w: 0.9, color: dark, seed: 71 + i, wobble: 0.6, boil: 0, opacity: 0.45, retrace: false }); } // grain on the sides+ for (let i = 0; i < 16; i++) { const x = r() * 1080, y = r() < 0.5 ? r() * B0 : LEDGE + 30 + r() * 80; g.pen([[x, y], [x + 60 + r() * 90, y + (r() - 0.5) * 3]], { w: 0.9, color: dark, seed: 100 + i, wobble: 0.6, boil: 0, opacity: 0.45, retrace: false }); }+ // the inner bevel: a shadow along the top and left where the frame stands proud of the slate+ fillShape(g, [[B0, B0], [B1, B0], [B1 - 6, B0 + 8], [B0 + 8, B0 + 8], [B0 + 8, LEDGE - 4], [B0, LEDGE - 4]], "#0e1512", 0.55);+ // chalk dust fallen on the ledge, a worn stub of chalk, the felt eraser+ for (let i = 0; i < 140; i++) { const x = B0 + r() * (B1 - B0), y = LEDGE + 2 + r() * 20; fillShape(g, blob(x, y, 0.8 + r() * 1.8, 0.6 + r(), 110 + i, 0.3, 6), CHALK, 0.25 + r() * 0.45); }+ const st: P[] = [[690, LEDGE + 2], [790, LEDGE - 6], [794, LEDGE + 10], [694, LEDGE + 18]];+ fillShape(g, [[696, LEDGE + 20], [796, LEDGE + 12], [800, LEDGE + 20], [700, LEDGE + 26]], "#3a2616", 0.6);+ fillShape(g, st, CHALK); fillShape(g, [[690, LEDGE + 11], [794, LEDGE + 3], [794, LEDGE + 10], [694, LEDGE + 18]], "#d9d3c6");+ fillShape(g, blob(691, LEDGE + 10, 5, 8, 260, 0.2, 10), "#e9e4d8");+ const er: P[] = [[250, LEDGE - 16], [390, LEDGE - 22], [396, LEDGE + 14], [256, LEDGE + 20]];+ fillShape(g, [[256, LEDGE + 20], [396, LEDGE + 14], [404, LEDGE + 24], [262, LEDGE + 28]], "#2a1a0e", 0.6);+ fillShape(g, er, "#a0714a"); fillShape(g, [[252, LEDGE + 4], [394, LEDGE - 2], [396, LEDGE + 14], [256, LEDGE + 20]], "#8e8a86");+ for (let i = 0; i < 40; i++) { const x = 260 + r() * 130, y = LEDGE + 6 + r() * 12; fillShape(g, blob(x, y, 1.2 + r() * 2, 1, 300 + i, 0.3, 6), CHALK, 0.35); }+ });+};++// ---------------------------------------------------------------- the lesson+const lesson = (g: Gfx) => {+ const phases: { lit: number; waxing: boolean; label: [string, string] }[] = [+ { lit: 0.22, waxing: true, label: ["WAXING", "CRESCENT"] }, { lit: 0.5, waxing: true, label: ["FIRST", "QUARTER"] }, { lit: 0.8, waxing: true, label: ["WAXING", "GIBBOUS"] },+ { lit: 1, waxing: true, label: ["FULL", ""] },+ { lit: 0.8, waxing: false, label: ["WANING", "GIBBOUS"] }, { lit: 0.5, waxing: false, label: ["LAST", "QUARTER"] }, { lit: 0.22, waxing: false, label: ["WANING", "CRESCENT"] },+ ];+ const at = (i: number): [number, number, number] => { const f = i / 6, s = Math.sin(f * Math.PI); return [128 + i * 137, 612 - s * 222, 42 + s * 28]; };+ // stars first, so the moons sit over them+ chalk(g, (dust) => {+ const r = rng(500);+ for (let i = 0; i < 70; i++) { const x = 60 + r() * 960, y = 60 + r() * 860, ok = [0, 1, 2, 3, 4, 5, 6].every((k) => { const [mx, my, mr] = at(k); return Math.hypot(x - mx, y - my) > mr + 34 && Math.abs(y - (my + mr + 48)) > 32 || Math.abs(x - mx) > 70; }) && !(y < 180 && x > 170 && x < 910); if (!ok) continue; const big = r() < 0.12; if (big) { const s = 7 + r() * 5; line(g, dust, [[x - s, y], [x + s, y]], 1.4, CHALK, 501 + i, 0.85, 0.2); line(g, dust, [[x, y - s], [x, y + s]], 1.4, CHALK, 601 + i, 0.85, 0.2); } else fillShape(g, blob(x, y, 1 + r() * 1.6, 1 + r() * 1.4, 700 + i, 0.2, 6), CHALK, 0.5 + r() * 0.4); }+ // the Plough, low on the left, dotted and joined in blue chalk+ const dip: P[] = [[112, 846], [168, 822], [220, 830], [266, 858], [278, 910], [352, 916], [360, 862]];+ dip.slice(0, 7).forEach(([x, y], i) => fillShape(g, blob(x, y, 3.4, 3.4, 800 + i, 0.15, 8), CHALK, 0.95));+ line(g, dust, [...dip.slice(0, 5)], 1, BLUE, 810, 0.6, 0.4); line(g, dust, [dip[4], dip[5], dip[6], dip[3]], 1, BLUE, 811, 0.6, 0.4);+ }, 0.18);+ phases.forEach((p, i) => { const [x, y, r] = at(i); moon(g, x, y, r, p.lit, p.waxing, 1000 + i * 37); });+ chalk(g, (dust) => {+ // the title, underlined twice in yellow the way a teacher does when it matters+ letter(g, "PHASES OF THE MOON", 540, 86, { cap: 44, color: CHALK, seed: 20, align: "center", w: 2.6, opacity: 0.95 });+ line(g, dust, [[300, 152], [540, 148], [782, 154]], 2.4, YEL, 21, 0.9, 1.2); line(g, dust, [[330, 164], [560, 161], [760, 166]], 1.8, YEL, 22, 0.75, 1.4);+ // the arrow of the month over the moons+ const arc: P[] = []; for (let k = 0; k <= 16; k++) { const f = k / 16, s = Math.sin(f * Math.PI); arc.push([150 + f * 780, 470 - s * 196]); }+ line(g, dust, smooth(arc.filter((_, k) => k % 2 === 0), false, 3), 1.6, BLUE, 30, 0.85, 1);+ const tip = arc[16], pre = arc[15], a = Math.atan2(tip[1] - pre[1], tip[0] - pre[0]);+ line(g, dust, [[tip[0] - Math.cos(a - 0.5) * 20, tip[1] - Math.sin(a - 0.5) * 20], tip, [tip[0] - Math.cos(a + 0.5) * 20, tip[1] - Math.sin(a + 0.5) * 20]], 1.8, BLUE, 31, 0.9, 0.3);+ letter(g, "29.5 DAYS", 540, 230, { cap: 17, color: BLUE, seed: 32, align: "center", w: 1.7, opacity: 0.85 });+ // the labels under each moon, and a note about the far side, circled in pink+ phases.forEach((p, i) => { const [x, y, r] = at(i); letter(g, p.label[0], x, y + r + 26, { cap: 13, color: CHALK, seed: 40 + i * 3, align: "center", w: 1.35, opacity: 0.85 }); if (p.label[1]) letter(g, p.label[1], x, y + r + 48, { cap: 13, color: CHALK, seed: 41 + i * 3, align: "center", w: 1.35, opacity: 0.85 }); });+ letter(g, "SAME FACE", 870, 842, { cap: 16, color: PINK, seed: 70, align: "center", w: 1.6, opacity: 0.9 });+ letter(g, "ALWAYS", 870, 868, { cap: 16, color: PINK, seed: 71, align: "center", w: 1.6, opacity: 0.9 });+ line(g, dust, Array.from({ length: 11 }, (_, k) => { const a2 = -0.3 + (k / 10) * Math.PI * 2.1; return [870 + Math.cos(a2) * 92, 858 + Math.sin(a2) * 42] as P; }), 1.4, PINK, 72, 0.8, 1.5);+ }, 0.22);+ void lerpP; void clamp;+};++export const drawMoonPhases = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, CHALK_M);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ board(g, ctx);+ lesson(g);+ frame(g);+};++export const moonPhases: Film = {+ meta: { title: "Moon phases · chalkboard", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "moonPhases", start: 0, end: 1, draw: drawMoonPhases }],+};diff --git a/engine/src/canvas-core/pocketWatch.ts b/engine/src/canvas-core/pocketWatch.tsnew file mode 100644index 0000000..467c68d--- /dev/null+++ b/engine/src/canvas-core/pocketWatch.ts@@ -0,0 +1,222 @@+import { Gfx, fractal, rng, type Ctx, type Env, type Medium, type P } from "./core";+import type { Film } from "./film";+import { bounds, clamp, fillShape, hatchRuns, inside, lerp, lerpP, smooth } from "./gallery";++// POCKET WATCH · ballpoint sketch. One blue biro, near-constant line weight, tone built only from+// WHERE the hatch strokes are (single hatch, then cross, then a third direction in the darkest+// places), and the little ink blob a ballpoint leaves where a firm stroke stops.+//+// The watch lies on a table, tipped a little, showing a sliver of its case side. Open face with a+// reeded bezel, a minute track, radial Roman numerals (the watchmaker's IIII, not IV), Breguet+// "moon" hands at ten past ten, a sunk sub-seconds dial at six, the crown, pendant and bow, and a+// curb chain trailing off the page. Light from the upper left; the crystal keeps one clean glare.++const BIRO = "#23379f", PAPER = "#f6f2e6";+const BIRO_M: Medium = { nib: 0.98, taper: 0.12, pressure: 0.1, retrace: true, wobble: 1.15, rough: 0.3 };+const C: P = [468, 590], ROT = -0.2, SQ = 0.93, TH: P = [15, 19], LIGHT: P = [-0.72, -0.69];+const R_CASE = 292, R_BEZ = 256, R_TRACK = 238, R_TRACK2 = 224, R_NUM = 190, SUB: P = [0, 112], R_SUB = 50;++// dial frame -> page: the round watch tipped a little and turned+const W = ([x, y]: P): P => { const yy = y * SQ, c = Math.cos(ROT), s = Math.sin(ROT); return [C[0] + x * c - yy * s, C[1] + x * s + yy * c]; };+const polar = (r: number, a: number): P => [Math.sin(a) * r, -Math.cos(a) * r]; // a = 0 at twelve, clockwise+const ring = (r: number, n = 90, c: P = [0, 0]): P[] => Array.from({ length: n }, (_, i) => W([c[0] + polar(r, (i / n) * Math.PI * 2)[0], c[1] + polar(r, (i / n) * Math.PI * 2)[1]]));++// ---------------------------------------------------------------- the biro+const stroke = (g: Gfx, pts: P[], o: { w?: number; op?: number; seed: number; wob?: number; blob?: boolean; retrace?: boolean }) => {+ const { w = 1.1, op = 0.86, seed, wob = 0.35, blob = false, retrace = false } = o;+ g.pen(pts, { w, color: BIRO, seed, wobble: wob, boil: 0, taper: 1, opacity: op, retrace });+ if (blob) { // a firm stroke leaves a bead of ink where the ball stops, a smaller one where it started+ const e = pts[pts.length - 1], s0 = pts[0], c = g.cur, r = rng(seed * 7);+ g.touch(e[0] - 4, e[1] - 4, e[0] + 4, e[1] + 4); g.touch(s0[0] - 3, s0[1] - 3, s0[0] + 3, s0[1] + 3);+ c.fillStyle = BIRO; c.globalAlpha = 0.8; c.beginPath(); c.arc(e[0] + (r() - 0.5), e[1] + (r() - 0.5), 1.2 + r() * 0.8, 0, Math.PI * 2); c.fill();+ c.globalAlpha = 0.5; c.beginPath(); c.arc(s0[0], s0[1], 0.8 + r() * 0.5, 0, Math.PI * 2); c.fill(); c.globalAlpha = 1;+ }+};+// hatching: tone lives in where strokes are. Runs are cut into hand-length strokes with a flick.+const hatch = (g: Gfx, region: P[], angle: number, gap: number, keep: (x: number, y: number) => boolean, seed: number, op = 0.62) => {+ const b = bounds(region), r = rng(seed);+ hatchRuns(b, angle, gap, (x, y) => inside(region, x, y) && keep(x, y), 2.5, seed).forEach((run, k) => {+ let i = 0;+ while (i < run.length - 1) {+ const n = Math.min(run.length - 1 - i, 8 + Math.floor(r() * 22)), seg = run.slice(i, i + n + 1);+ if (seg.length > 1) { const a = seg[0], z = seg[seg.length - 1], m = lerpP(a, z, 0.5), bow = (r() - 0.5) * 1.6; stroke(g, [a, [m[0] + bow, m[1] - bow], z], { w: 0.82, op: op * (0.75 + r() * 0.35), seed: seed * 1000 + k * 37 + i, wob: 0.25 }); }+ i += n + (r() < 0.25 ? 1 : 0);+ }+ });+};++// ---------------------------------------------------------------- tone (0 = dark, 1 = paper)+const lit = (nx: number, ny: number) => clamp((nx * LIGHT[0] + ny * LIGHT[1]) * 0.5 + 0.5);+const ragged = (x: number, y: number, k: number) => (fractal(5, x, y, 0.035, 0.035, 2) - 0.5) * k; // a hand stops its hatching at a slightly different place every stroke+const bezelTone = (x: number, y: number) => { const dx = x - C[0], dy = y - C[1], l = Math.hypot(dx, dy) || 1; return 0.18 + 0.82 * Math.pow(lit(dx / l, dy / l), 1.6) + ragged(x, y, 0.16); };+const dialTone = (x: number, y: number) => {+ const dx = x - C[0], dy = y - C[1], l = Math.hypot(dx, dy) || 1, edge = clamp((l - R_BEZ * 0.72) / (R_BEZ * 0.26));+ const bezelShadow = edge * clamp(-(dx / l) * LIGHT[0] * -1 - (dy / l) * LIGHT[1] * -1) * 0.55; // the bezel shades the dial on the side toward the light+ const glassBand = clamp(((dx + dy) / Math.SQRT2 + 40) / 260) * 0.2; // the crystal darkens a touch away from the light+ const glare = Math.exp(-Math.pow((dx + 110) / 60, 2) - Math.pow((dy + 120) / 34, 2));+ return clamp(0.98 - bezelShadow - glassBand + glare + ragged(x, y, 0.14));+};++// ---------------------------------------------------------------- dial furniture+const numeral = (g: Gfx, txt: string, a: number, h: number, seed: number) => {+ // Roman numerals built from strokes, oriented radially (feet toward the centre), with serifs;+ // the thick stroke of each letter is laid down twice, the way a biro builds weight+ const glyphs: Record<string, { w: number; strokes: [P, P, boolean][] }> = {+ I: { w: 0.22, strokes: [[[0, -0.5], [0, 0.5], true]] },+ V: { w: 0.62, strokes: [[[-0.31, -0.5], [0, 0.5], true], [[0.31, -0.5], [0, 0.5], false]] },+ X: { w: 0.62, strokes: [[[-0.31, -0.5], [0.31, 0.5], true], [[0.31, -0.5], [-0.31, 0.5], false]] },+ };+ const gap = 0.1, total = [...txt].reduce((a2, ch) => a2 + glyphs[ch].w, 0) + gap * (txt.length - 1);+ const base = polar(R_NUM, a), up: P = [Math.sin(a), -Math.cos(a)], side: P = [Math.cos(a), Math.sin(a)];+ const at = (u: number, v: number): P => W([base[0] + side[0] * u * h - up[0] * v * h, base[1] + side[1] * u * h - up[1] * v * h]);+ let x = -total / 2, k = 0;+ for (const ch of txt) {+ const gl = glyphs[ch], cx = x + gl.w / 2;+ gl.strokes.forEach(([p, q, thick]) => {+ const A = at(cx + p[0], p[1]), B = at(cx + q[0], q[1]);+ stroke(g, [A, lerpP(A, B, 0.5), B], { w: 1.05, op: 0.92, seed: seed + k++, wob: 0.15 });+ if (thick) { const o = 0.035; stroke(g, [at(cx + p[0] + o, p[1]), at(cx + (p[0] + q[0]) / 2 + o, 0), at(cx + q[0] + o, q[1])], { w: 1.05, op: 0.9, seed: seed + k++, wob: 0.15 }); }+ });+ [-0.5, 0.5].forEach((v) => { const sx = gl.w / 2 + 0.07; stroke(g, [at(cx - sx, v), at(cx + sx, v)], { w: 0.9, op: 0.85, seed: seed + k++, wob: 0.1 }); });+ x += gl.w + gap;+ }+};++const breguet = (g: Gfx, a: number, len: number, moonR: number, moonAt: number, width: number, seed: number, alpha = 1, off: P = [0, 0]) => {+ // a Breguet hand: a slender tapering blade, a hollow "moon" ring near the tip, a needle point+ const d: P = [Math.sin(a), -Math.cos(a)], n: P = [Math.cos(a), Math.sin(a)], p = (t: number, s: number): P => { const q = W([d[0] * t + n[0] * s, d[1] * t + n[1] * s]); return [q[0] + off[0], q[1] + off[1]]; };+ const tail = -len * 0.18, m = len * moonAt;+ const blade = [p(tail, width * 1.1), p(0, width), p(m - moonR * 1.1, width * 0.55), p(m - moonR * 1.1, -width * 0.55), p(0, -width), p(tail, -width * 1.1)];+ fillShape(g, blade, BIRO, 0.9 * alpha);+ const moon: P[] = [], hole: P[] = [];+ for (let i = 0; i < 28; i++) { const t = (i / 28) * Math.PI * 2; moon.push(p(m + Math.cos(t) * moonR, Math.sin(t) * moonR)); hole.push(p(m + moonR * 0.12 + Math.cos(t) * moonR * 0.56, Math.sin(t) * moonR * 0.56)); }+ const c = g.cur, bb = bounds(moon); g.touch(bb.x0 - 2, bb.y0 - 2, bb.x1 + 2, bb.y1 + 2);+ c.fillStyle = BIRO; c.globalAlpha = 0.9 * alpha; c.beginPath(); moon.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); hole.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); c.fill("evenodd"); c.globalAlpha = 1;+ fillShape(g, [p(m + moonR * 0.9, width * 0.5), p(len, 0.4), p(m + moonR * 0.9, -width * 0.5)], BIRO, 0.9 * alpha);+ if (alpha < 1) return;+ stroke(g, [p(tail, 0), p(len * 0.5, 0), p(len, 0)], { w: 0.9, op: 0.5, seed, wob: 0.1 });+ stroke(g, [p(m + moonR * 0.95, 0), p(len, 0)], { w: 0.8, op: 0.9, seed: seed + 1, wob: 0.05, blob: true });+};++// ---------------------------------------------------------------- the chain+const chain = (g: Gfx, start: P, seed: number) => {+ // curb chain lying on the table: links alternate face-on (a ring) and edge-on (a short bar)+ const path = smooth([start, [start[0] + 60, start[1] - 96], [start[0] + 190, start[1] - 150], [start[0] + 330, start[1] - 112], [start[0] + 430, start[1] - 20], [start[0] + 520, start[1] + 120], [1120, start[1] + 190]], false, 20);+ const r = rng(seed);+ let d = 0; const cum = [0]; for (let i = 1; i < path.length; i++) cum.push(cum[i - 1] + Math.hypot(path[i][0] - path[i - 1][0], path[i][1] - path[i - 1][1]));+ const atD = (s: number): [P, P] => { let i = 1; while (i < path.length - 1 && cum[i] < s) i++; const f = (s - cum[i - 1]) / (cum[i] - cum[i - 1] || 1), p = lerpP(path[i - 1], path[i], clamp(f)), dx = path[i][0] - path[i - 1][0], dy = path[i][1] - path[i - 1][1], l = Math.hypot(dx, dy) || 1; return [p, [dx / l, dy / l]]; };+ let k = 0;+ while (d < cum[cum.length - 1] - 20) {+ const [p, t] = atD(d + 13), n: P = [-t[1], t[0]], face = k % 2 === 0, L = 17, Wd = face ? 10.5 : 4.2;+ const o: P[] = [], iN: P[] = [];+ for (let i = 0; i < 24; i++) { const a = (i / 24) * Math.PI * 2; o.push([p[0] + t[0] * Math.cos(a) * L + n[0] * Math.sin(a) * Wd, p[1] + t[1] * Math.cos(a) * L + n[1] * Math.sin(a) * Wd]); iN.push([p[0] + t[0] * Math.cos(a) * L * 0.6 + n[0] * Math.sin(a) * Wd * 0.34, p[1] + t[1] * Math.cos(a) * L * 0.6 + n[1] * Math.sin(a) * Wd * 0.34]); }+ // its shadow on the table, down and right+ hatch(g, o.map(([x, y]) => [x + 5, y + 7] as P), -0.95, 2.6, () => true, seed + k * 3, 0.5);+ fillShape(g, o, PAPER);+ if (face) fillShape(g, iN, PAPER);+ hatch(g, o, 0.6, 2.8, (x, y) => ((x - p[0]) * LIGHT[0] + (y - p[1]) * LIGHT[1]) < -1 && !(face && inside(iN, x, y)), seed + k * 3 + 1, 0.72);+ stroke(g, [...o.slice(0, 13)], { w: 1.05, op: 0.9, seed: seed + k * 5 + 2, wob: 0.2, retrace: true });+ stroke(g, [...o.slice(12), o[0]], { w: 1.05, op: 0.9, seed: seed + k * 5 + 3, wob: 0.2, retrace: true, blob: r() < 0.5 });+ if (face) stroke(g, [...iN, iN[0]], { w: 0.95, op: 0.85, seed: seed + k * 5 + 4, wob: 0.15 });+ d += face ? 27 : 23; k++;+ }+};++export const drawPocketWatch = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, BIRO_M);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, 1080, 1080);+ const caseF = ring(R_CASE, 120), caseB = caseF.map(([x, y]) => [x + TH[0], y + TH[1]] as P);++ g.group("plain", () => {+ // construction first, the way the sketch was started: centre lines and a looser ellipse+ stroke(g, [W([-340, 0]), W([0, 0]), W([340, 0])], { w: 0.8, op: 0.16, seed: 1, wob: 0.6 });+ stroke(g, [W([0, -400]), W([0, 0]), W([0, 340])], { w: 0.8, op: 0.16, seed: 2, wob: 0.6 });+ stroke(g, ring(R_CASE + 14, 40).map(([x, y]) => [x - 4, y + 3] as P), { w: 0.8, op: 0.13, seed: 3, wob: 1.2 });++ // the watch's shadow on the table: cross-hatched, heaviest where the case touches down+ const shadow = ring(R_CASE, 90).map(([x, y]) => [x + 46, y + 40] as P);+ const sd = (x: number, y: number) => Math.hypot(x - C[0] - 46, y - C[1] - 40) / R_CASE;+ hatch(g, shadow, -0.95, 4.6, () => true, 101, 0.55);+ hatch(g, shadow, 0.55, 4.8, (x, y) => sd(x, y) < 0.97 && (x - C[0]) + (y - C[1]) > 60, 102, 0.5);+ chain(g, W([10, -R_CASE - 108]), 300);++ // the case side, a sliver of cylinder: short strokes that follow its curve, dense in the shade+ fillShape(g, caseB, PAPER); fillShape(g, caseF, PAPER);+ const band: P[] = [...caseF, ...caseB.slice().reverse()];+ void band;+ for (let i = 0; i < 240; i++) {+ const a = (i / 240) * Math.PI * 2, f = W(polar(R_CASE, a)), b2: P = [f[0] + TH[0], f[1] + TH[1]], dx = f[0] - C[0], dy = f[1] - C[1], l = Math.hypot(dx, dy);+ const facing = (dx / l) * TH[0] + (dy / l) * TH[1];+ if (facing < 4) continue; // only the side turned toward us shows its band+ const shade = 1 - bezelTone(f[0], f[1]);+ if (i % (shade > 0.55 ? 1 : shade > 0.3 ? 2 : 4)) continue;+ stroke(g, [lerpP(f, b2, 0.05), lerpP(f, b2, 1.02)], { w: 0.85, op: 0.55 + shade * 0.35, seed: 400 + i, wob: 0.1 });+ }+ { const n = caseB.length, vis = (i: number) => { const f = caseF[i], dx = f[0] - C[0], dy = f[1] - C[1], l = Math.hypot(dx, dy); return (dx / l) * TH[0] + (dy / l) * TH[1] > 2; };+ let s0 = 0; while (vis(s0) || !vis((s0 + 1) % n)) s0 = (s0 + 1) % n; // the first index where the visible arc begins+ const arc: P[] = []; for (let k = 1; k <= n && vis((s0 + k) % n); k++) arc.push(caseB[(s0 + k) % n]);+ stroke(g, arc, { w: 1.15, op: 0.9, seed: 410, wob: 0.3, retrace: true, blob: true }); }++ // the bezel: reeded outer edge, cylinder tone laid in as hatching along the ring+ const bez: P[] = [...caseF, caseF[0], ...ring(R_BEZ, 120).reverse(), ring(R_BEZ, 120)[119]];+ const bezIn = ring(R_BEZ, 60);+ const inBez = (x: number, y: number) => { const q = Math.hypot((x - C[0]), (y - C[1])); return q > R_BEZ * 0.93 && q < R_CASE * 1.0; };+ hatch(g, caseF, -0.9, 3.6, (x, y) => inBez(x, y) && !inside(bezIn, x, y) && bezelTone(x, y) < 0.72, 111, 0.66);+ hatch(g, caseF, 0.62, 3.8, (x, y) => inBez(x, y) && !inside(bezIn, x, y) && bezelTone(x, y) < 0.42, 112, 0.62);+ hatch(g, caseF, 0.05, 4.0, (x, y) => inBez(x, y) && !inside(bezIn, x, y) && bezelTone(x, y) < 0.24, 113, 0.6);+ void bez;+ for (let i = 0; i < 180; i++) { const a = (i / 180) * Math.PI * 2, p0 = W(polar(R_CASE, a)), p1 = W(polar(R_CASE - 11, a)); stroke(g, [p0, p1], { w: 0.75, op: 0.35 + 0.5 * (1 - bezelTone(p0[0], p0[1])), seed: 500 + i, wob: 0.05 }); }+ stroke(g, caseF.slice(0, 61), { w: 1.25, op: 0.9, seed: 510, wob: 0.3, retrace: true, blob: true });+ stroke(g, [...caseF.slice(60), caseF[0], caseF[1]], { w: 1.25, op: 0.9, seed: 511, wob: 0.3, retrace: true, blob: true });+ stroke(g, [...ring(R_CASE - 12, 100), ring(R_CASE - 12, 100)[0]], { w: 0.8, op: 0.55, seed: 512, wob: 0.2 });+ stroke(g, [...ring(R_BEZ, 110), ring(R_BEZ, 110)[0], ring(R_BEZ, 110)[1]], { w: 1.15, op: 0.9, seed: 513, wob: 0.2, retrace: true });++ // the dial: paper, a soft bezel shadow and a crystal reflection in single hatching, one glare left bare+ const dial = ring(R_BEZ, 110);+ hatch(g, dial, -0.9, 4.4, (x, y) => dialTone(x, y) < 0.86, 121, 0.5);+ hatch(g, dial, 0.6, 4.6, (x, y) => dialTone(x, y) < 0.62, 122, 0.5);+ [R_TRACK, R_TRACK2].forEach((rr, k) => stroke(g, [...ring(rr, 110), ring(rr, 110)[0], ring(rr, 110)[1]], { w: 0.95, op: 0.88, seed: 130 + k, wob: 0.15 }));+ for (let i = 0; i < 60; i++) { const a = (i / 60) * Math.PI * 2, five = i % 5 === 0; stroke(g, [W(polar(R_TRACK - 1, a)), W(polar(five ? R_TRACK2 - 6 : R_TRACK2 + 1, a))], { w: five ? 1.3 : 0.85, op: 0.9, seed: 140 + i, wob: 0.04 }); }+ const labels = ["XII", "I", "II", "III", "IIII", "V", "VI", "VII", "VIII", "IX", "X", "XI"];+ labels.forEach((t, i) => { if (i === 6) return; numeral(g, t, (i / 12) * Math.PI * 2, 34, 1000 + i * 20); }); // six is taken by the seconds dial+ // sub-seconds, sunk into the dial: a shadowed step on its upper-left rim+ const sub = ring(R_SUB, 70, SUB);+ hatch(g, sub, 0.6, 3.4, (x, y) => { const c0 = W(SUB), dx = x - c0[0], dy = y - c0[1], l = Math.hypot(dx, dy) || 1; return l > R_SUB * 0.72 && (dx / l) * LIGHT[0] + (dy / l) * LIGHT[1] > 0.1; }, 150, 0.7);+ stroke(g, [...sub, sub[0], sub[1]], { w: 1.05, op: 0.9, seed: 151, wob: 0.12, retrace: true });+ stroke(g, [...ring(R_SUB - 9, 60, SUB), ring(R_SUB - 9, 60, SUB)[0]], { w: 0.75, op: 0.7, seed: 152, wob: 0.1 });+ for (let i = 0; i < 60; i++) { const a = (i / 60) * Math.PI * 2, c0 = SUB, p0 = polar(R_SUB - 1, a), p1 = polar(i % 5 ? R_SUB - 6 : R_SUB - 10, a); stroke(g, [W([c0[0] + p0[0], c0[1] + p0[1]]), W([c0[0] + p1[0], c0[1] + p1[1]])], { w: i % 5 ? 0.6 : 0.9, op: 0.85, seed: 160 + i, wob: 0.02 }); }+ const sa = 2.35, s0 = W(SUB), s1 = W([SUB[0] + polar(R_SUB - 8, sa)[0], SUB[1] + polar(R_SUB - 8, sa)[1]]), s2 = W([SUB[0] - polar(12, sa)[0], SUB[1] - polar(12, sa)[1]]);+ stroke(g, [s2, s0, s1], { w: 1.0, op: 0.95, seed: 170, wob: 0.03, blob: true });+ fillShape(g, ring(3, 12, SUB), BIRO, 0.9);++ // the hands at ten past ten, each throwing a hair of shadow onto the dial+ const hourA = (10 + 8 / 60) / 12 * Math.PI * 2, minA = (8 / 60) * Math.PI * 2;+ breguet(g, hourA, 138, 15, 0.7, 5.2, 180, 0.16, [5, 6]); breguet(g, minA, 206, 13, 0.76, 4.2, 190, 0.16, [6, 7]);+ breguet(g, hourA, 138, 15, 0.7, 5.2, 180);+ breguet(g, minA, 206, 13, 0.76, 4.2, 190);+ fillShape(g, ring(11, 16), BIRO, 0.95); fillShape(g, ring(4.5, 12), PAPER); fillShape(g, ring(2, 8), BIRO, 0.9);++ // pendant, crown and bow at twelve+ const pend = [W([-24, -R_CASE + 6]), W([-17, -R_CASE - 26]), W([17, -R_CASE - 26]), W([24, -R_CASE + 6])];+ fillShape(g, pend, PAPER);+ hatch(g, pend, 0.6, 3, (x, y) => (x - W([0, -R_CASE - 10])[0]) > -4, 200, 0.7);+ stroke(g, [pend[0], pend[1], pend[2], pend[3]], { w: 1.1, op: 0.92, seed: 201, wob: 0.15, retrace: true });+ const crown: P[] = [W([-21, -R_CASE - 26]), W([-21, -R_CASE - 64]), W([21, -R_CASE - 64]), W([21, -R_CASE - 26])];+ fillShape(g, crown, PAPER);+ for (let i = -18; i <= 18; i += 3.2) stroke(g, [W([i, -R_CASE - 28]), W([i, -R_CASE - 62])], { w: 0.8, op: i > 2 ? 0.9 : 0.55, seed: 210 + Math.round(i * 10), wob: 0.05 }); // the knurling+ stroke(g, [...crown, crown[0]], { w: 1.15, op: 0.92, seed: 220, wob: 0.12, retrace: true });+ const bowC: P = [0, -R_CASE - 78], bowO = ring(52, 70, bowC).filter((_, i) => i < 30 || i > 40), bowI = ring(41, 70, bowC).filter((_, i) => i < 30 || i > 40);+ hatch(g, [...ring(52, 70, bowC), ...ring(41, 70, bowC).reverse()], -0.9, 3, (x, y) => { const c0 = W(bowC); return (x - c0[0]) + (y - c0[1]) > -6; }, 230, 0.7);+ stroke(g, bowO, { w: 1.2, op: 0.92, seed: 231, wob: 0.2, retrace: true, blob: true });+ stroke(g, bowI, { w: 1.05, op: 0.85, seed: 232, wob: 0.2, retrace: true });+ });+ g.paper("paper", 0.07);+};++export const pocketWatch: Film = {+ meta: { title: "Pocket watch · ballpoint sketch", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "pocketWatch", start: 0, end: 1, draw: drawPocketWatch }],+};+void lerp;diff --git a/engine/src/canvas-core/print.ts b/engine/src/canvas-core/print.tsnew file mode 100644index 0000000..a99d9ec--- /dev/null+++ b/engine/src/canvas-core/print.ts@@ -0,0 +1,73 @@+// Print Bit (risograph) on the portable canvas core. Same shapes as proof-4's Print panel.+// Each drum is drawn on its own layer, eaten by pinholes and mottle (texture tiles), and+// overprinted with `multiply` at its own registration offset. The hand-cut wobble that the+// SVG build got from a displacement filter is baked into the geometry here.+import { Ctx, Env, Gfx, P, RISOLINE, arc, displace, halftone, heart, oval, poly, sample, softBox, tube } from "./core";++const INK = { pink: "#ff48b0", blue: "#0078bf", yellow: "#ffd400" }, PAPER = "#f5efe2";+const cut = (pts: P[]) => displace(displace(pts, 2.2, 0.07, 2, 6), 0.9, 0.45, 1, 9); // scissors, not a plotter: a slow wander plus a fine nibble+const smooth = (pts: P[], per = 8) => cut(sample(pts, true, Math.max(per, 10)));+const dense = (pts: P[]) => cut(poly(pts, 6)); // straight-edged shapes still need vertices to wobble++export const drawPrint = (ctx: Ctx, frame: number, env: Env) => {+ const g = new Gfx(ctx, env, frame, RISOLINE), W = env.W, H = env.H;+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = PAPER; ctx.fillRect(0, 0, W, H);+ const fill = (pts: P[], color: string, alpha = 1) => g.fill(pts, color, alpha);+ const dots = (b: { x0: number; y0: number; x1: number; y1: number }, pitch: number, ang: number, tone: (x: number, y: number) => number, color: string, clip?: P[]) => {+ const c = g.cur; g.touch(b.x0 - 10, b.y0 - 10, b.x1 + 10, b.y1 + 10); c.save(); if (clip) { g.path(c, clip); c.clip(); } c.fillStyle = color; c.beginPath();+ halftone(b, pitch, ang, tone).forEach(([x, y, r]) => { const [q] = cut([[x, y]]); c.moveTo(q[0] + r, q[1]); c.arc(q[0], q[1], r, 0, Math.PI * 2); }); c.fill(); c.restore();+ };+ const drum = (off: P, fn: () => void) => g.group("plain", fn, { blend: "multiply", off, textures: ["risoSpeck", "risoMottle"] });+ const lit = (cx: number, cy: number, r: number, k = 0.8, base = 0.06) => (x: number, y: number) => base + k * Math.max(0, ((x - cx) * 0.6 + (y - cy) * 0.8) / r);++ const headP: P[] = softBox(280, 210, 246, 182, 4.2, 18).map(([x, y], i) => [x + [2, -1, 0, 3, -2][i % 5], y + [-1, 2, 1, -2, 0][i % 5]] as P);+ const bodyP: P[] = softBox(280, 365, 138, 108, 5, 16).map(([x, y], i) => [x + [1, -2, 2][i % 3], y + [0, 1, -1][i % 3]] as P);+ const head = smooth(headP), body = smooth(bodyP), sun = smooth(oval(300, 236, 192, 190, 14)), quarter = cut([[0, 560], ...arc(0, 560, 152, 152, -Math.PI / 2, 0, 24)]);+ const keyShaft = smooth(poly([[344, 361], [386, 359], [386, 373], [344, 374]], 2), 3), keyA = smooth(oval(398, 351, 18, 19, 8)), keyB = smooth(oval(399, 386, 19, 18, 8));+ const Y: P = [-4.5, 3.5], K: P = [4.5, -3], B: P = [0, 0];++ // drum 1: yellow+ drum(Y, () => {+ dots({ x0: 100, y0: 40, x1: 500, y1: 430 }, 7.5, 28, (_x, y) => 0.2 + 0.6 * ((y - 46) / 380), INK.yellow, sun);+ fill(head, INK.yellow, 0.92); fill(smooth(oval(326, 50, 27, 26, 9)), INK.yellow); fill(keyShaft, INK.yellow); fill(keyA, INK.yellow); fill(keyB, INK.yellow);+ [0, 1, 2, 3, 4].forEach((i) => fill(smooth(poly([[40, 400 + i * 18], [136 - i * 3, 399 + i * 18], [136 - i * 3, 407 + i * 18], [40, 408 + i * 18]], 3), 3), INK.yellow));+ });+ // drum 2: fluorescent pink+ drum(K, () => {+ fill(cut(arc(158.5, 215, 35, 36, Math.PI / 2, (3 * Math.PI) / 2, 18)), INK.pink); fill(cut(arc(401.5, 215, 35, 36, -Math.PI / 2, Math.PI / 2, 18)), INK.pink);+ fill(smooth(oval(204, 252, 18, 16, 8)), INK.pink); fill(smooth(oval(356, 252, 17, 17, 8)), INK.pink); fill(smooth(oval(440, 236, 27, 26, 9)), INK.pink); fill(smooth(oval(176, 420, 24, 25, 9)), INK.pink); fill(smooth(oval(331, 46, 17, 17, 8)), INK.pink);+ fill(cut([...arc(226, 500, 30, 30, Math.PI, 1.5 * Math.PI, 10), [230, 470], [230, 500]]), INK.pink); fill(cut([...arc(334, 500, 30, 30, 0, -0.5 * Math.PI, 10), [330, 470], [330, 500]]), INK.pink);+ dots({ x0: 150, y0: 110, x1: 410, y1: 310 }, 6.5, 62, lit(260, 190, 150, 1.0, 0), INK.pink, head); // the head turns: pink screen over yellow = orange+ fill(dense([[450, 470], [510, 470], [480, 416]]), INK.pink, 0.9);+ dots({ x0: 100, y0: 300, x1: 500, y1: 430 }, 7.5, 62, (_x, y) => 0.55 * Math.max(0, (y - 330) / 100), INK.pink, sun);+ dots({ x0: 50, y0: 76, x1: 118, y1: 144 }, 6.5, 62, (x, y) => (Math.hypot(x - 84, y - 110) > 34 ? 0 : 0.15 + 0.6 * ((y - 76) / 68)), INK.pink);+ });+ // the body is knocked out of the sun, so the heart and screen print on clean paper+ g.group("plain", () => { fill(body, PAPER); fill(smooth(oval(280, 366, 80, 64, 10)), PAPER); });+ drum(K, () => { fill(smooth(heart(280, 368, 24), 5), INK.pink); fill(keyShaft, INK.pink, 0.9); fill(keyA, INK.pink, 0.9); fill(keyB, INK.pink, 0.9); });+ // drum 3: blue, the key drum+ drum(B, () => {+ dots({ x0: 0, y0: 400, x1: 160, y1: 560 }, 7, 28, (x, y) => 0.12 + 0.75 * (1 - Math.hypot(x, y - 560) / 152), INK.blue, quarter);+ [[[232, 330], [206, 370], [182, 408]], [[330, 330], [366, 326], [394, 316]], [[394, 316], [416, 284], [434, 250]]].forEach((c) => fill(smooth(tube(c as P[], 12, 12, true), 4), INK.blue));+ fill(smooth(poly([[238, 414], [264, 415], [263, 474], [238, 473]], 2), 3), INK.blue); fill(smooth(poly([[296, 415], [322, 414], [322, 473], [297, 474]], 2), 3), INK.blue);+ fill(cut([...arc(230, 500, 34, 34, Math.PI, 1.5 * Math.PI, 10), [270, 466], [270, 500]]), INK.blue); fill(cut([...arc(330, 500, 34, 34, 0, -0.5 * Math.PI, 10), [290, 466], [290, 500]]), INK.blue);+ fill(body, INK.blue); const c = g.cur; c.globalCompositeOperation = "destination-out"; fill(dense([[245, 337], [315, 335], [316, 397], [244, 396]]), "#000"); c.globalCompositeOperation = "source-over"; // the screen window+ fill(smooth(oval(232, 204, 19, 20, 9)), INK.blue); fill(smooth(oval(328, 203, 20, 19, 9)), INK.blue);+ fill(cut([[251, 246], [266, 247.6], [280, 248], [295, 247], [309, 245], ...arc(280, 245.5, 29, 28, 0.08, Math.PI - 0.08, 14)]), INK.blue);+ [[462, 196], [484, 222], [494, 256]].forEach(([x, y]) => fill(smooth(oval(x, y, 5, 5, 6)), INK.blue));+ [[70, 250], [96, 276], [60, 300]].forEach(([x, y]) => fill(dense([[x - 2, y - 10], [x + 2, y - 10], [x + 2, y - 2], [x + 10, y - 2], [x + 10, y + 2], [x + 2, y + 2], [x + 2, y + 10], [x - 2, y + 10], [x - 2, y + 2], [x - 10, y + 2], [x - 10, y - 2], [x - 2, y - 2]]), INK.blue));+ });+ // the body turns too: pink screen over blue = purple+ drum(K, () => dots({ x0: 205, y0: 305, x1: 355, y1: 425 }, 6.5, 62, lit(260, 350, 90, 0.9, 0), INK.pink, body));+ // the key drawing, in blue litho crayon+ drum(B, () => {+ g.pen(headP, { closed: true, w: 3.6, color: INK.blue, seed: 3, wobble: 0.5 }); g.pen(poly([[290, 120], [272, 104], [304, 92], [276, 78], [306, 66], [322, 56]], 2), { w: 4.2, color: INK.blue, seed: 4, wobble: 0.4 });+ g.pen([[182, 150], [176, 190], [180, 226]], { w: 2.2, color: INK.blue, seed: 5, opacity: 0.8 }); g.pen([[196, 136], [188, 160]], { w: 2.2, color: INK.blue, seed: 6, opacity: 0.8 });+ });+ // paper showing through the eyes, roller banding, and what the printer leaves in the margin+ g.group("plain", () => { const c = g.cur; c.fillStyle = PAPER; [[225, 197, 6], [321, 196, 6.4]].forEach(([x, y, r]) => { c.beginPath(); c.arc(x, y, r, 0, Math.PI * 2); c.fill(); }); });+ g.group("plain", () => { const c = g.cur; c.fillStyle = "#e9e0cc"; [[214, 5], [468, 7]].forEach(([y, h]) => c.fillRect(0, y, W, h)); }, { blend: "multiply", alpha: 0.22 });+ g.group("plain", () => { const c = g.cur; c.strokeStyle = "#1b1b1b"; c.lineWidth = 1.1; [[24, 24], [536, 24], [24, 536], [536, 536]].forEach(([x, y]) => { c.beginPath(); c.arc(x, y, 7, 0, Math.PI * 2); c.moveTo(x - 12, y); c.lineTo(x + 12, y); c.moveTo(x, y - 12); c.lineTo(x, y + 12); c.stroke(); }); }, { alpha: 0.9 });+ drum(B, () => { [[232, INK.yellow], [262, INK.pink], [292, INK.blue]].forEach(([x, col]) => { const c = g.cur; c.fillStyle = col as string; c.fillRect(x as number, 530, 26, 14); }); });+ g.paper("paper", 0.26); g.paper("coldpress", 0.1); g.paper("coldpress", 0.14);+};diff --git a/engine/src/canvas-core/ranunculus.ts b/engine/src/canvas-core/ranunculus.tsnew file mode 100644index 0000000..864730c--- /dev/null+++ b/engine/src/canvas-core/ranunculus.ts@@ -0,0 +1,78 @@+import { Gfx, PENCIL, arc, line, oval, rng, tube, type Ctx, type Env, type P } from "./core";+import type { Film } from "./film";++// Broad, cupped outer petals give way to densely folded inner petals.+// Each lip is offset independently so the bloom never becomes a radial rosette.+const petal = (g: Gfx, radius: number, angle: number, width: number, depth: number, seed: number, tier: number) => {+ const r = rng(seed), cx = 531 + (r() - 0.5) * 14, cy = 391 + (r() - 0.5) * 12;+ const place = ([x, y]: P): P => [cx + Math.cos(angle) * y - Math.sin(angle) * x, cy + (Math.sin(angle) * y + Math.cos(angle) * x) * 0.87];+ const lip = arc(0, radius - depth * 0.28, width, depth * 0.45, Math.PI, 0, 9)+ .map(([x, y], i): P => [x, y + Math.sin(i * 1.8 + seed) * depth * 0.045]);+ const shape = [...lip, [width * 0.73, radius - depth * 0.61], [width * 0.15, radius - depth], [-width * 0.63, radius - depth * 0.7]] as P[];+ const colors = ["#f7ddd2", "#f4cbbb", "#efb8a8", "#e8a491", "#df907f", "#d88071", "#c77364"];+ g.group("paint", () => {+ g.form(shape.map(place), colors[tier], tier < 3 ? "#ce8c8a" : "#ac6667", { seed, light: [-3.2, -4.6], alpha: 0.94 });+ g.wash([...lip.slice(1, 8), [0, radius - depth * 0.17]].map(p => place(p as P)), "#fff2dc", { seed: seed + 1, alpha: 0.28, dx: -1, dy: -1, shrink: 0.91, rim: false });+ });+ g.group("ink", () => {+ g.pen(lip.map(place), { seed: seed + 2, w: 0.88, opacity: 0.43, color: "#726262", wobble: 0.65, boil: 0, taper: 1, retrace: true });+ for (let j = 0; j < 3; j++) {+ const x = (j - 1) * width * 0.42;+ g.pen(line([x * 0.45, radius - depth * 0.69], [x, radius - depth * 0.06], (r() - 0.5) * 7).map(place), { seed: seed + 10 + j, w: 0.48, opacity: 0.17, color: "#986b69", wobble: 0.35, boil: 0, retrace: false });+ }+ });+};++const leaf = (g: Gfx, origin: P, direction: number, size: number, seed: number) => {+ const place = ([x, y]: P): P => [origin[0] + (x * Math.cos(direction) - y * Math.sin(direction)) * size, origin[1] + (x * Math.sin(direction) + y * Math.cos(direction)) * size];+ // Ranunculus foliage is divided into pointed lobes.+ const edge: P[] = [[0, 0], [28, -22], [35, -51], [52, -37], [78, -65], [81, -38], [116, -39], [101, -17], [147, 0], [105, 12], [113, 31], [80, 25], [73, 52], [50, 31], [30, 39], [22, 17]];+ g.group("paint", () => g.form(edge.map(place), "#a4b28b", "#637f70", { seed, light: [-3, -4], alpha: 0.9 }));+ g.group("ink", () => {+ g.pen(edge.map(place), { seed: seed + 1, closed: true, w: 0.95, opacity: 0.45, wobble: 0.65, boil: 0, color: "#5f6a5c" });+ g.pen(line([0, 0], [139, 0], -3).map(place), { seed: seed + 2, w: 0.9, opacity: 0.55, boil: 0 });+ [[35, -45], [77, -57], [111, -34], [71, 45], [107, 27]].forEach(([x, y], i) => g.pen(line([x * 0.56, 0], [x, y], 3).map(place), { seed: seed + 3 + i, w: 0.55, opacity: 0.35, boil: 0, retrace: false }));+ });+};++export const drawRanunculus = (ctx: Ctx, _frame: number, env: Env) => {+ // A still has no line boil across frames; its only randomness is seeded geometry.+ const g = new Gfx(ctx, env, 0, PENCIL);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ ctx.fillStyle = "#fffaf3";+ ctx.fillRect(0, 0, env.W, env.H);+ const stem: P[] = [[547, 548], [557, 645], [539, 756], [517, 880], [524, 991]];+ const stalk = tube(stem, 8, 4, true);+ g.group("paint", () => g.form(stalk, "#a6b48b", "#708776", { seed: 21, light: [-3, -1] }));+ g.group("ink", () => g.pen(stalk, { seed: 22, closed: true, w: 0.95, opacity: 0.53, wobble: 0.6, boil: 0 }));+ leaf(g, [541, 760], -2.55, 1.25, 40);+ leaf(g, [549, 698], -0.57, 1.02, 60);+ g.group("paint", () => g.form(oval(543, 548, 48, 34, 10), "#abb68b", "#6f8069", { seed: 90, light: [-4, -5] }));++ const r = rng(7321);+ const rings = [+ { radius: 252, count: 11, width: 99, depth: 150 },+ { radius: 211, count: 13, width: 77, depth: 116 },+ { radius: 171, count: 14, width: 62, depth: 94 },+ { radius: 134, count: 14, width: 49, depth: 74 },+ { radius: 100, count: 12, width: 38, depth: 58 },+ { radius: 70, count: 11, width: 28, depth: 42 },+ { radius: 43, count: 9, width: 21, depth: 31 },+ ];+ rings.forEach((ring, tier) => {+ const offset = tier * 0.39 + 0.14;+ for (let i = 0; i < ring.count; i++) {+ const a = offset + i * Math.PI * 2 / ring.count + (r() - 0.5) * 0.15;+ petal(g, ring.radius * (0.95 + r() * 0.1), a, ring.width * (0.88 + r() * 0.24), ring.depth * (0.92 + r() * 0.16), 1000 + tier * 500 + i * 25, tier);+ }+ });+ for (let i = 0; i < 5; i++) petal(g, 20 - i * 2, i * 2.4, 12 - i, 17, 6000 + i * 25, 6);+ g.paper("paper", 0.12);+ g.paper("coldpress", 0.18);+};++export const ranunculus: Film = {+ meta: { title: "Ranunculus · pencil + watercolour", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "ranunculus", start: 0, end: 1, draw: drawRanunculus }],+};diff --git a/engine/src/canvas-core/riso.ts b/engine/src/canvas-core/riso.tsnew file mode 100644index 0000000..d474783--- /dev/null+++ b/engine/src/canvas-core/riso.ts@@ -0,0 +1,34 @@+// RISOGRAPH TOOLKIT for representational subjects. Volume comes from a halftone screen whose+// dots change size with a TONE FUNCTION, so realism is a matter of writing the right tone+// function for the form: a lit dome, a cylinder, distance to a fold.+import { Gfx, Medium, P, displace, halftone, poly, rng, sample } from "./core";++export const INK = { pink: "#ff48b0", blue: "#0078bf", yellow: "#ffd400", teal: "#00838a", red: "#f15060" }, PAPER = "#f5efe2";+export const LITHO: Medium = { nib: 1.5, taper: 0.95, pressure: 1.15, retrace: false, wobble: 0.9, rough: 0.9 }; // litho crayon: swells and thins+export const cut = (pts: P[]) => displace(displace(pts, 2.2, 0.07, 2, 6), 0.9, 0.45, 1, 9);+export const smooth = (pts: P[], per = 10) => cut(sample(pts, true, per));+export const straight = (pts: P[]) => cut(poly(pts, 6));+export const REG = { yellow: [-4.5, 3.5] as P, pink: [4.5, -3] as P, blue: [0, 0] as P };+export const drum = (g: Gfx, off: P, fn: () => void) => g.group("plain", fn, { blend: "multiply", off, textures: ["risoSpeck", "risoMottle"] });+export const screen = (g: Gfx, b: { x0: number; y0: number; x1: number; y1: number }, pitch: number, ang: number, tone: (x: number, y: number) => number, color: string, clip?: P[]) => {+ const c = g.cur; g.touch(b.x0 - 10, b.y0 - 10, b.x1 + 10, b.y1 + 10); c.save(); if (clip) { g.path(c, clip); c.clip(); } c.fillStyle = color; c.beginPath();+ halftone(b, pitch, ang, tone).forEach(([x, y, r]) => { c.moveTo(x + r, y); c.arc(x, y, r, 0, Math.PI * 2); }); c.fill(); c.restore();+};+export const bounds = (pts: P[]) => { let x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9; pts.forEach(([x, y]) => { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }); return { x0, y0, x1, y1 }; };+export const inside = (pts: P[], x: number, y: number) => { let c = false; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const [xi, yi] = pts[i], [xj, yj] = pts[j]; if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c; } return c; };+// how far across the form is this point, 0..1, along one axis? (a cylinder lit from one side)+export const across = (pts: P[], axis: "x" | "y") => { const memo = new Map<number, [number, number]>(), a = axis === "x" ? 0 : 1, o = 1 - a; return (x: number, y: number) => { const q = [x, y], key = Math.round(q[o]); let span = memo.get(key); if (!span) { let lo = 1e9, hi = -1e9; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const p = pts[i], r = pts[j]; if (p[o] > key !== r[o] > key) { const v = p[a] + ((key - p[o]) * (r[a] - p[a])) / (r[o] - p[o]); lo = Math.min(lo, v); hi = Math.max(hi, v); } } span = [lo, hi]; memo.set(key, span); } return span[1] <= span[0] ? 0 : Math.max(0, Math.min(1, (q[a] - span[0]) / (span[1] - span[0]))); }; };+// nearest distance to a set of polylines, through a grid so 30k dots stay cheap+export const nearField = (lines: P[][], cell = 28) => {+ const grid = new Map<string, P[]>(), put = (p: P) => { const k = `${Math.floor(p[0] / cell)},${Math.floor(p[1] / cell)}`; (grid.get(k) ?? grid.set(k, []).get(k)!).push(p); };+ lines.forEach((l) => { for (let i = 1; i < l.length; i++) { const a = l[i - 1], b = l[i], n = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1]) / 4)); for (let k = 0; k <= n; k++) put([a[0] + ((b[0] - a[0]) * k) / n, a[1] + ((b[1] - a[1]) * k) / n]); } });+ return (x: number, y: number) => { const cx = Math.floor(x / cell), cy = Math.floor(y / cell); let d = cell * 1.5; for (let i = -1; i <= 1; i++) for (let j = -1; j <= 1; j++) for (const p of grid.get(`${cx + i},${cy + j}`) ?? []) d = Math.min(d, Math.hypot(p[0] - x, p[1] - y)); return d; };+};+// a fold that wanders like a real one, plus the little side branches folds always have+export const wander = (pts: P[], amp: number, wl: number, seed: number): P[] => { const s = sample(pts, false, 14), r = rng(seed), ph = r() * 6.28; let len = 0; return s.map((p, i) => { const q = s[Math.min(s.length - 1, i + 1)], o = s[Math.max(0, i - 1)], dx = q[0] - o[0], dy = q[1] - o[1], l = Math.hypot(dx, dy) || 1; if (i) len += Math.hypot(p[0] - o[0], p[1] - o[1]); const ends = Math.min(1, i / 8, (s.length - 1 - i) / 8), w = (Math.sin((len / wl) * 6.28 + ph) + 0.45 * Math.sin((len / wl) * 15.1 + ph * 2)) * amp * ends; return [p[0] - (dy / l) * w, p[1] + (dx / l) * w] as P; }); };+export const twigs = (line: P[], every: number, seed: number, lenLo = 16, lenHi = 38): P[][] => { const r = rng(seed), out: P[][] = []; let acc = every * r(); for (let i = 2; i < line.length - 2; i++) { acc += Math.hypot(line[i][0] - line[i - 1][0], line[i][1] - line[i - 1][1]); if (acc < every) continue; acc = 0; if (r() < 0.25) continue; const dx = line[i + 1][0] - line[i - 1][0], dy = line[i + 1][1] - line[i - 1][1], a = Math.atan2(dy, dx) + (r() < 0.5 ? 1 : -1) * (1.1 + r() * 0.8), L = lenLo + r() * (lenHi - lenLo), b = (r() - 0.5) * 0.9; out.push([line[i], [line[i][0] + Math.cos(a) * L * 0.5, line[i][1] + Math.sin(a) * L * 0.5], [line[i][0] + Math.cos(a + b) * L, line[i][1] + Math.sin(a + b) * L]]); } return out; };+export const plateMarks = (g: Gfx, W: number, H: number, inks: string[]) => {+ g.group("plain", () => { const c = g.cur; c.strokeStyle = "#1b1b1b"; c.lineWidth = 1.1; [[26, 26], [W - 26, 26], [26, H - 26], [W - 26, H - 26]].forEach(([x, y]) => { c.beginPath(); c.arc(x, y, 7, 0, Math.PI * 2); c.moveTo(x - 12, y); c.lineTo(x + 12, y); c.moveTo(x, y - 12); c.lineTo(x, y + 12); c.stroke(); }); }, { alpha: 0.9 });+ drum(g, [0, 0], () => inks.forEach((col, i) => { const c = g.cur; c.fillStyle = col; c.fillRect(W / 2 - inks.length * 16 + i * 32, H - 34, 28, 14); }));+ g.paper("paper", 0.26); g.paper("coldpress", 0.22);+};diff --git a/engine/src/canvas-core/score.ts b/engine/src/canvas-core/score.tsnew file mode 100644index 0000000..7f4902c--- /dev/null+++ b/engine/src/canvas-core/score.ts@@ -0,0 +1,14 @@+// A tiny pure-JS score for the fixtures film: plucks on the beat, a bell on the last cut.+// No Web Audio, no Node APIs: just maths into two Float32Arrays, so it runs under ANY backend.+export const fixturesScore = (fps: number, bpm: number, frames: number) => (sr: number): [Float32Array, Float32Array] => {+ const n = Math.ceil((frames / fps) * sr), L = new Float32Array(n), R = new Float32Array(n), beat = 60 / bpm;+ const note = (t0: number, hz: number, dur: number, gain: number, pan: number, bell = false) => {+ const i0 = Math.floor(t0 * sr), len = Math.floor(dur * sr);+ for (let i = 0; i < len && i0 + i < n; i++) { const t = i / sr, env = Math.exp(-t * (bell ? 2.2 : 7)) * Math.min(1, t * 400), v = (Math.sin(2 * Math.PI * hz * t) + (bell ? 0.5 * Math.sin(2 * Math.PI * hz * 2.76 * t) + 0.25 * Math.sin(2 * Math.PI * hz * 5.4 * t) : 0.3 * Math.sin(2 * Math.PI * hz * 2 * t))) * env * gain; L[i0 + i] += v * (1 - pan); R[i0 + i] += v * pan; }+ };+ const scale = [261.63, 329.63, 392.0, 329.63, 293.66, 349.23, 440.0, 349.23, 392.0, 523.25];+ for (let b = 0; b * beat < frames / fps; b++) { note(b * beat, scale[b % scale.length], 0.5, 0.22, 0.35 + 0.3 * (b % 2)); if (b % 2 === 0) note(b * beat, scale[b % scale.length] / 2, 0.7, 0.16, 0.5); }+ note(6 * beat, 1046.5, 2.2, 0.2, 0.5, true); // DING on the cut into the last shot+ for (let i = 0; i < n; i++) { L[i] = Math.tanh(L[i] * 1.4); R[i] = Math.tanh(R[i] * 1.4); }+ return [L, R];+};diff --git a/engine/src/canvas-core/storybook.ts b/engine/src/canvas-core/storybook.tsnew file mode 100644index 0000000..9aaa08b--- /dev/null+++ b/engine/src/canvas-core/storybook.ts@@ -0,0 +1,142 @@+// Storybook Bit (pencil + watercolour) on the portable canvas core. A transliteration of+// the proof-4 panel (src/roster.tsx Storybook + src/characters.tsx Bit), same seeds, same+// control points, so any difference you see is the MEDIUM, not the drawing.+import { Env, GRAPHITE, Gfx, P, PENCIL, TINT, arc, heart, line, oval, rng, tube, turn, Ctx } from "./core";++const SHADE = { white: "#c9d2e4", rose: "#cf8291", denim: "#52739f", butter: "#d9b24f" };+const at = (o: P, pts: P[]): P[] => pts.map(([x, y]) => [o[0] + x, o[1] + y]);+const dir = (a: P, b: P) => Math.atan2(b[1] - a[1], b[0] - a[0]);+const HEAD: P[] = [[-70, -40], [-52, -58], [-10, -65], [34, -63], [62, -51], [75, -22], [77, 14], [67, 44], [34, 58], [-8, 61], [-46, 56], [-70, 39], [-79, 6], [-78, -20]];+const BODY: P[] = [[-44, -42], [-20, -50], [16, -50], [42, -42], [54, -14], [57, 18], [45, 42], [14, 52], [-16, 52], [-46, 42], [-57, 16], [-54, -16]];+const BOOT: P[] = [[-13, -8], [-14, 6], [-9, 12], [20, 12], [28, 9], [29, 1], [22, -6], [10, -9], [4, -13]];++type Pose = "open" | "rest";+const handShape = (pose: Pose, k: number) => {+ const R = 13 * k, c: P = [15 * k, 0], spec = pose === "open" ? { a: [-0.62, -0.04, 0.54], len: 17, w: 0.3, thumb: [-1.75, 13] } : { a: [-0.46, 0.0, 0.46], len: 10, w: 0.2, thumb: [-1.5, 10] };+ const on = (ang: number, r: number): P => [c[0] + Math.cos(ang) * r, c[1] + Math.sin(ang) * r], pts: P[] = [[0, -7.5 * k], [5 * k, -11 * k]], ta = spec.thumb[0], tl = spec.thumb[1] * k, valleys: P[] = [];+ pts.push(on(ta - 0.34, R), on(ta - 0.16, R + tl * 0.8), on(ta, R + tl), on(ta + 0.2, R + tl * 0.7), on(ta + 0.36, R * 0.98));+ spec.a.forEach((a, i) => { const L = spec.len * k * (i === 1 ? 1.08 : 1); pts.push(on(a - spec.w, R + L * 0.55), on(a - spec.w * 0.5, R + L * 0.95), on(a, R + L), on(a + spec.w * 0.5, R + L * 0.95), on(a + spec.w, R + L * 0.55)); if (i < 2) { const v = on((a + spec.a[i + 1]) / 2, pose === "open" ? R : R + L * 0.42); pts.push(v); valleys.push(v); } });+ pts.push(on(1.15, R), on(1.9, R * 0.98), [5 * k, 11 * k], [0, 7.5 * k]);+ return { pts, valleys, c };+};+const hand = (g: Gfx, wrist: P, angle: number, pose: Pose, seed: number) => {+ const flip = Math.cos(angle) < 0 ? -1 : 1, place = (pts: P[]): P[] => turn(pts.map(([x, y]) => [wrist[0] + x, wrist[1] + y * flip] as P), wrist[0], wrist[1], (angle * 180) / Math.PI);+ const h = handShape(pose, 1), shape = place(h.pts), cuff = place([[-7, -9.5], [3, -10.5], [4, 0], [3, 10.5], [-7, 9.5], [-8, 0]]);+ g.group("paint", () => { g.form(shape, TINT.white, SHADE.white, { seed, light: [-3, -4] }); g.form(cuff, TINT.rose, SHADE.rose, { seed: seed + 1, light: [-2, -3] }); });+ g.group("ink", () => {+ g.pen(shape, { closed: true, w: 2.9, seed: seed + 2, wobble: 0.5, boil: 0.35, taper: 0.5 });+ if (pose === "open") h.valleys.forEach((v, i) => { const inner: P = [v[0] + (h.c[0] - v[0]) * 0.32, v[1] + (h.c[1] - v[1]) * 0.32]; g.pen(place(line(v, inner, 0.5)), { w: 1.5, seed: seed + 3 + i, wobble: 0.3, boil: 0.3, opacity: 0.75, retrace: false }); });+ g.pen(cuff, { closed: true, w: 2.5, seed: seed + 7, wobble: 0.4, boil: 0.3, taper: 0.5 });+ [-0.45, 0.45].forEach((t, i) => g.pen(place(line([-5.5, t * 9], [2, t * 9.6])), { w: 1.6, seed: seed + 8 + i, wobble: 0.2, opacity: 0.65, retrace: false }));+ });+};+const limb = (g: Gfx, from: P, to: P, bend: number, r: number, seed: number) => {+ const mid = line(from, to, bend)[1], shape = tube([from, mid, to], r, r * 0.86, false);+ const along = (t: number): P => { const a = t < 0.5 ? from : mid, b = t < 0.5 ? mid : to, u = t < 0.5 ? t * 2 : (t - 0.5) * 2; return [a[0] + (b[0] - a[0]) * u, a[1] + (b[1] - a[1]) * u]; };+ g.group("paint", () => g.form(shape, TINT.white, SHADE.white, { seed, light: [-3, -3] }));+ g.group("ink", () => { g.pen(shape, { closed: true, w: 2.8, seed: seed + 1, wobble: 0.5, boil: 0.35, taper: 0.4 }); [0.2, 0.36, 0.52, 0.68, 0.84].forEach((t, i) => { const p = along(t), q = along(t + 0.04), a = dir(p, q) + Math.PI / 2; g.pen(line([p[0] - Math.cos(a) * r * 0.85, p[1] - Math.sin(a) * r * 0.85], [p[0] + Math.cos(a) * r * 0.85, p[1] + Math.sin(a) * r * 0.85], 2.2), { w: 1.7, seed: seed + 2 + i, wobble: 0.2, opacity: 0.6, retrace: false }); }); });+};++// Bit, lit, waving. Local coordinates, feet at (0,0).+export const drawBit = (g: Gfx, frame: number, seed: number, p: { look: number; tilt: number; lean: number; handL: P; handR: P }) => {+ const { look, tilt, lean, handL, handR } = p, hc: P = [lean * 0.6, -200], bc: P = [0, -86];+ const H = (pts: P[]) => turn(at(hc, pts), hc[0], hc[1], tilt), B = (pts: P[]) => turn(at(bc, pts), 0, 0, lean * 0.12);+ const coil: P[] = [[28, -64], [41, -71], [27, -80], [43, -88], [30, -97], [45, -105], [38, -114]], bulbC: P = [39, -130], bulb = H([bulbC])[0];+ const keyTurn = Math.abs(Math.cos(frame * 0.22)), sL = B([[-50, -28]])[0], sR = B([[50, -28]])[0], footR: P = [28, -12], bootR = at(footR, BOOT), bootL = at([-28, -12], BOOT.map(([x, y]) => [-x, y] as P));+ g.group("ink", () => g.hatch(-62, 8, 130, { n: 15, len: 12, angle: -0.45, seed: seed + 1, opacity: 0.32 }));+ // wind-up key+ g.group("paint", () => { g.form(oval(90, -111, 9, 13 * keyTurn + 3, 8), TINT.butter, SHADE.butter, { seed: seed + 2, light: [-2, -3] }); g.form(oval(90, -81, 9, 13 * keyTurn + 3, 8), TINT.butter, SHADE.butter, { seed: seed + 3, light: [-2, -3] }); });+ g.group("ink", () => {+ g.pen(line([52, -94], [84, -96], 1), { w: 3.6, seed: seed + 4, wobble: 0.4 }); g.pen(oval(90, -96, 5, 5, 7), { closed: true, w: 2.4, seed: seed + 7, wobble: 0.2, taper: 0.4 });+ g.pen(oval(90, -111, 4, Math.max(1.5, 6 * keyTurn), 7), { closed: true, w: 1.7, seed: seed + 8, wobble: 0.2, taper: 0.3, retrace: false }); g.pen(oval(90, -81, 4, Math.max(1.5, 6 * keyTurn), 7), { closed: true, w: 1.7, seed: seed + 9, wobble: 0.2, taper: 0.3, retrace: false });+ g.pen(oval(90, -111, 9, 13 * keyTurn + 3, 8), { closed: true, w: 2.6, seed: seed + 5, wobble: 0.3, taper: 0.5 }); g.pen(oval(90, -81, 9, 13 * keyTurn + 3, 8), { closed: true, w: 2.6, seed: seed + 6, wobble: 0.3, taper: 0.5 });+ });+ // legs + boots+ limb(g, [-24, -40], [-27, -16], -2, 7.5, seed + 10); limb(g, [24, -40], [27, -16], 2, 7.5, seed + 20);+ g.group("paint", () => { g.form(bootL, TINT.denim, SHADE.denim, { seed: seed + 30, light: [-3, -4] }); g.form(bootR, TINT.denim, SHADE.denim, { seed: seed + 31, light: [-3, -4] }); });+ g.group("ink", () => [bootL, bootR].forEach((b, i) => {+ const o: P = i ? footR : [-28, -12], sx = i ? 1 : -1, M = (pts: P[]) => pts.map(([x, y]) => [o[0] + x * sx, o[1] + y] as P);+ g.pen(b, { closed: true, w: 3, seed: seed + 32 + i, wobble: 0.5, boil: 0.35, taper: 0.5 }); g.pen(M([[-13, 7], [6, 8], [28, 6]]), { w: 2, seed: seed + 34 + i, wobble: 0.3, opacity: 0.75, retrace: false });+ g.pen(M(arc(18, 3, 10, 10, 1.05 * Math.PI, 1.75 * Math.PI, 5)), { w: 2, seed: seed + 36 + i, wobble: 0.3, opacity: 0.7, retrace: false });+ [0, 1].forEach((j) => g.pen(M(line([-3 + j * 6, -7 + j], [3 + j * 6, -3 + j])), { w: 1.7, color: "#f4efe6", seed: seed + 38 + i * 2 + j, wobble: 0.2, retrace: false }));+ }));+ // arms, hands+ limb(g, sL, handL, -14, 7.5, seed + 40); limb(g, sR, handR, 14, 7.5, seed + 50);+ hand(g, handL, dir(line(sL, handL, -14)[1], handL), "rest", seed + 60); hand(g, handR, dir(line(sR, handR, 14)[1], handR), "open", seed + 80);+ // body+ const screen = B(at([0, -12], [[-27, -19], [0, -22], [27, -19], [29, 0], [27, 17], [0, 20], [-27, 17], [-29, 0]]));+ g.group("paint", () => {+ g.form(B(BODY), TINT.white, SHADE.white, { seed: seed + 100, light: [-7, -8], hi: [-24, -112, 12, 7, -30] }); g.form(screen, TINT.glow, "#f0c868", { seed: seed + 101, light: [-3, -3] });+ const flat = { dx: 0, dy: 0, shrink: 1, rim: false };+ g.wash(B(heart(0, -13, 10)), TINT.blush, { alpha: 0.95, seed: seed + 102, ...flat }); g.wash(B(arc(0, 30, 15, 14, Math.PI, 2 * Math.PI, 7)), "#fffaf0", { alpha: 0.95, seed: seed + 103, ...flat }); g.wash(B(arc(7, 30, 7, 9, Math.PI, 2 * Math.PI, 5)), TINT.sage, { alpha: 0.75, seed: seed + 104, ...flat });+ });+ g.group("ink", () => {+ g.pen(B(BODY), { closed: true, w: 4, seed: seed + 110, wobble: 0.8, boil: 0.4, taper: 0.6 }); g.pen(screen, { closed: true, w: 2.6, seed: seed + 111, wobble: 0.4, boil: 0.3, taper: 0.5 });+ g.pen(B(at([0, -12], [[-21, -13], [0, -16], [21, -13]])), { w: 1.6, seed: seed + 112, wobble: 0.3, opacity: 0.45, retrace: false }); g.pen(B(heart(0, -13, 10)), { closed: true, w: 1.9, color: "#c9566b", seed: seed + 113, wobble: 0.3, taper: 0.4 });+ g.pen(B(arc(0, 30, 15, 14, Math.PI, 2 * Math.PI, 8)), { w: 2.2, seed: seed + 114, wobble: 0.3 }); g.pen(B(line([-16, 30], [16, 30])), { w: 2.2, seed: seed + 115, wobble: 0.3 }); g.pen(B(line([0, 29], [9, 19])), { w: 2.4, color: "#c9566b", seed: seed + 116, wobble: 0.2, retrace: false });+ [[-43, -34], [43, -34], [-47, 34], [47, 34]].forEach(([x, y], i) => { const c = B([[x * 0.9, y]])[0]; g.pen(oval(c[0], c[1], 2.6, 2.6, 6), { closed: true, w: 1.6, seed: seed + 117 + i, wobble: 0.2, opacity: 0.7, retrace: false }); });+ const hp = B([[24, 30]])[0]; g.hatch(hp[0], hp[1], 24, { n: 5, len: 13, angle: -0.9, seed: seed + 125, opacity: 0.35 });+ });+ const collar = at([lean * 0.3, -140], [[-24, -7], [0, -10], [24, -7], [26, 3], [0, 8], [-26, 3]]);+ g.group("paint", () => g.form(collar, "#e6dfd6", "#b9b0a6", { seed: seed + 130, light: [-2, -3] })); g.group("ink", () => g.pen(collar, { closed: true, w: 2.6, seed: seed + 131, wobble: 0.4, taper: 0.5 }));+ // antenna + bulb+ g.group("plain", () => g.glow(bulb[0], bulb[1], 46, TINT.glow, 0.35 * (0.7 + 0.2 * Math.sin(frame * 0.2)) * 2));+ g.group("paint", () => g.form(H(oval(bulbC[0], bulbC[1], 13, 15, 9)), "#fff0b0", "#f2c65a", { seed: seed + 140, light: [-3, -4], hi: [bulb[0] - 5, bulb[1] - 6, 4, 2.4] }));+ g.group("ink", () => {+ g.pen(H(coil), { w: 2.8, seed: seed + 141, wobble: 0.5, boil: 0.5, taper: 0.4 }); g.pen(H(oval(bulbC[0], bulbC[1], 13, 15, 9)), { closed: true, w: 2.7, seed: seed + 142, wobble: 0.4, taper: 0.5 });+ g.pen(H(at(bulbC, [[-5, 6], [-3, -3], [0, 3], [3, -3], [5, 6]])), { w: 1.7, color: "#c9872a", seed: seed + 143, wobble: 0.2, opacity: 0.8, retrace: false });+ [0, 1, 2, 3, 4, 5].forEach((i) => { const a = -2.9 + i * 0.55; g.pen(H(line([bulbC[0] + Math.cos(a) * 22, bulbC[1] + Math.sin(a) * 22], [bulbC[0] + Math.cos(a) * (33 + (i % 2) * 5), bulbC[1] + Math.sin(a) * (33 + (i % 2) * 5)])), { w: 2.3, color: "#c9973a", seed: seed + 144 + i, wobble: 0.3, retrace: false }); });+ });+ // head+ g.group("paint", () => { [-1, 1].forEach((s) => g.form(H(oval(s * 81 + 1, 2, 11, 17, 9)), TINT.rose, SHADE.rose, { seed: seed + 150 + s, light: [-2, -3] })); g.form(H(HEAD), TINT.white, SHADE.white, { seed: seed + 152, light: [-9, -10], hi: [hc[0] - 40, hc[1] - 40, 16, 8, -28] }); });+ g.group("ink", () => {+ [-1, 1].forEach((s) => { g.pen(H(oval(s * 81 + 1, 2, 11, 17, 9)), { closed: true, w: 2.8, seed: seed + 153 + s, wobble: 0.4, taper: 0.5 }); g.pen(H(line([s * 81 - 3, -5], [s * 81 + 5, 9])), { w: 1.8, seed: seed + 156 + s, wobble: 0.2, opacity: 0.6, retrace: false }); });+ g.pen(H(HEAD), { closed: true, w: 4.2, seed: seed + 160, wobble: 0.9, boil: 0.4, taper: 0.6 }); g.pen(H([[-68, -33], [-30, -41], [10, -43], [44, -41], [69, -34]]), { w: 1.9, seed: seed + 161, wobble: 0.4, opacity: 0.5, retrace: false });+ [[-54, -46], [58, -47]].forEach(([x, y], i) => g.pen(H(oval(x, y, 2.6, 2.6, 6)), { closed: true, w: 1.6, seed: seed + 162 + i, wobble: 0.2, opacity: 0.7, retrace: false }));+ g.pen(H(arc(26, -62, 9, 7, Math.PI, 2 * Math.PI, 5)), { w: 2.4, seed: seed + 164, wobble: 0.3 }); const hp = H([[36, 44]])[0]; g.hatch(hp[0], hp[1], 30, { n: 6, len: 14, angle: -0.95, seed: seed + 165, opacity: 0.33 });+ });+ // face+ const fo: P = [hc[0] + look * 4, hc[1] + 6], fs = seed + 170, gap = 31, T = (pts: P[]) => turn(at(fo, pts), fo[0], fo[1], tilt);+ g.group("paint", () => [-1, 1].forEach((s) => g.wash(T(oval(s * (gap + 22), 20, 14, 8.5, 8)), TINT.blush, { alpha: 0.5, seed: fs + s, dx: 0, dy: 0, shrink: 1, rim: false })));+ g.group("ink", () => {+ [-1, 1].forEach((s, i) => {+ const x = s * gap + look * 3, y = i ? -1 : 0, c = T([[x, y]])[0], k: Ctx = g.cur;+ g.touch(c[0] - 13, c[1] - 13, c[0] + 13, c[1] + 13); k.fillStyle = GRAPHITE; k.beginPath(); k.ellipse(c[0], c[1], 8.4, 10.8, (tilt * Math.PI) / 180, 0, Math.PI * 2); k.fill();+ k.fillStyle = "#fffaf3"; k.beginPath(); k.arc(c[0] - 2.6 + look * 1.5, c[1] - 3.8, 3.3, 0, Math.PI * 2); k.fill(); k.globalAlpha = 0.85; k.beginPath(); k.arc(c[0] + 2.8 + look * 1.5, c[1] + 3.6, 1.5, 0, Math.PI * 2); k.fill(); k.globalAlpha = 1;+ g.pen(T(arc(x, y - 13, 10, 6, 1.25 * Math.PI, 1.75 * Math.PI, 4)), { w: 2, seed: fs + 14 + i, wobble: 0.3, opacity: 0.55, retrace: false });+ });+ g.pen(T(arc(0, 20, 9, 8, 0.12 * Math.PI, 0.88 * Math.PI, 6)), { w: 2.9, seed: fs + 20, wobble: 0.3, boil: 0.3 });+ [-1, 1].forEach((s) => { const c = T([[s * (gap + 22) - 7, 17]])[0]; g.hatch(c[0], c[1], 13, { n: 3, len: 9, color: TINT.blush, pw: 2.6, opacity: 0.9, seed: fs + 30 + s }); });+ });+};++export const drawStorybook = (ctx: Ctx, frame: number, env: Env) => {+ const g = new Gfx(ctx, env, frame, PENCIL), W = env.W, H = env.H;+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = "#fbf6ea"; ctx.fillRect(0, 0, W, H);+ // the painting stops short of the sheet+ g.group("paint", () => {+ g.wash([[40, 46], [170, 36], [300, 42], [430, 34], [522, 44], [528, 170], [520, 300], [526, 430], [518, 488], [400, 480], [280, 490], [150, 482], [42, 490], [34, 380], [42, 250], [36, 130]], "#f3d9b4", { alpha: 0.62, seed: 2 });+ g.wash(oval(170, 150, 150, 105, 9), "#a9cdea", { alpha: 0.24, seed: 3 }); g.wash(oval(420, 330, 120, 150, 9), "#f2b9a0", { alpha: 0.26, seed: 4 }); g.wash(oval(318, 96, 80, 70, 8), TINT.glow, { alpha: 0.5, seed: 5 });+ g.wash([[34, 470], [150, 452], [300, 460], [430, 450], [530, 466], [524, 530], [300, 538], [44, 530]], "#9cc79a", { alpha: 0.62, seed: 6 }); g.wash([[60, 486], [200, 474], [330, 480], [330, 500], [190, 506], [70, 504]], "#6fa874", { alpha: 0.35, seed: 7 });+ g.wash(oval(292, 494, 124, 13, 10), "#7d6fa8", { alpha: 0.42, seed: 8 });+ });+ // pencil underdrawing, left in+ g.group("ink", () => {+ const U = "#8d90a6";+ g.pen(turn(oval(300, 214, 128, 104, 12), 300, 214, 6), { closed: true, w: 1.4, color: U, seed: 9, opacity: 0.45, wobble: 2 }); g.pen(oval(292, 392, 86, 92, 10), { closed: true, w: 1.4, color: U, seed: 10, opacity: 0.42, wobble: 2 });+ g.pen([[318, 96], [300, 214], [288, 400], [286, 500]], { w: 1.3, color: U, seed: 11, opacity: 0.42 }); g.pen([[170, 232], [300, 214], [432, 196]], { w: 1.3, color: U, seed: 12, opacity: 0.4 });+ g.pen([[36, 470], [150, 454], [300, 461], [430, 452], [530, 468]], { w: 2, seed: 13, opacity: 0.55 });+ [[66, 0], [84, 1], [104, 0], [128, 1], [430, 0], [452, 1], [474, 0], [500, 1]].forEach(([x, k], i) => g.pen([[x, 472], [x + (k ? 5 : -4), 456 - (i % 3) * 4], [x + (k ? 9 : -8), 444 - (i % 3) * 5]], { w: 1.9, color: "#5f8f62", seed: 20 + i, retrace: false }));+ [[176, 512, 9, 5], [396, 516, 11, 6], [232, 524, 6, 4]].forEach(([x, y, a, b], i) => g.pen(oval(x, y, a, b, 7), { closed: true, w: 1.6, seed: 40 + i, opacity: 0.6 }));+ });+ ([[64, 440, "#f2899c", 50], [488, 430, "#c7b3e0", 60], [446, 452, "#f5b98a", 70], [98, 462, "#f3d577", 80]] as [number, number, string, number][]).forEach(([x, y, c, seed]) => {+ g.group("paint", () => { const flat = { dx: 3, dy: 2, shrink: 0.94, rim: true }; [0, 1, 2, 3, 4].forEach((i) => g.wash(oval(x + Math.cos(i * 1.256 + 0.4) * 9, y + Math.sin(i * 1.256 + 0.4) * 9, 7.5, 7.5, 6), c, { alpha: 0.85, seed: seed + i, ...flat })); g.wash(oval(x, y, 3.4, 3.4, 5), TINT.butter, { alpha: 0.95, seed: seed + 6, ...flat }); });+ g.group("ink", () => { g.pen([[x, y + 9], [x + 2, y + 24], [x - 1, y + 40]], { w: 1.8, color: "#6f9b6a", seed: seed + 7, retrace: false }); g.pen(oval(x, y, 16, 16, 9), { closed: true, w: 1.5, seed: seed + 8, opacity: 0.6, wobble: 2 }); });+ });+ // the actor: same placement maths as <Actor x=272 y=492 s=2.75> around a 1080 viewBox in a 560 box+ const seed = 3, bob = Math.sin(frame * 0.16 + seed) * 2;+ g.push(272, 492 + bob * 2.75, 2.75 * (560 / 1080)); drawBit(g, frame, seed, { look: 1, tilt: 6, lean: 3, handL: [-80, -58], handR: [94, -178] }); g.pop();+ // paint off the brush+ g.group("paint", () => { const c = g.cur; ([[5, 26, [50, 60, 510, 470], "#e9a887", 3], [8, 12, [60, 380, 500, 520], "#6fa874", 2.6]] as [number, number, number[], string, number][]).forEach(([sd, n, box, col, rmax]) => { const r = rng(sd); for (let i = 0; i < n; i++) { const x = box[0] + r() * (box[2] - box[0]), y = box[1] + r() * (box[3] - box[1]), k = r(); g.touch(x - 5, y - 5, x + 5, y + 5); c.globalAlpha = 0.5 * (0.5 + r() * 0.5); c.fillStyle = col; c.beginPath(); c.arc(x, y, 0.5 + k * k * rmax, 0, Math.PI * 2); c.fill(); } c.globalAlpha = 1; }); });+ g.paper("paper", 0.13); g.vignette("rgba(90,50,50,0.11)"); g.paper("coldpress", 0.2);+};diff --git a/engine/src/canvas-core/styleGallery.ts b/engine/src/canvas-core/styleGallery.tsnew file mode 100644index 0000000..08f1c69--- /dev/null+++ b/engine/src/canvas-core/styleGallery.ts@@ -0,0 +1,64 @@+import { Gfx, PENCIL, type Ctx, type Env } from "./core";+import type { Film } from "./film";+import { letter } from "./drafting";+import { drawRanunculus } from "./ranunculus";+import { drawKoi } from "./koi";+import { drawPocketWatch } from "./pocketWatch";+import { drawBalloon } from "./balloon";+import { drawWren } from "./wren";+import { drawMoonPhases } from "./moonPhases";+import { drawFox } from "./fox";+import { drawLighthouse } from "./lighthouse";++// THE STYLE GALLERY. Eight subjects, eight hands, one engine, laid out as a contact sheet.+// The sheet is itself a film drawn by code: every tile is its subject's own pure draw function,+// rendered at full size into an offscreen surface and set down on the sheet, so the gallery is+// exactly as asset-free and as reproducible as the pictures on it. Nothing here is a photograph.++const TILE = 1000, GUT = 44, LAB = 92, HEAD = 150, COLS = 4, ROWS = 2;+const GW = COLS * TILE + (COLS + 1) * GUT, GH = HEAD + ROWS * (TILE + LAB) + (ROWS + 1) * GUT;+const SHEET = "#eee8dc", INKC = "#2a2521", MUTED = "#8a7f72";++const PLATES: { draw: (ctx: Ctx, f: number, env: Env) => void; style: string; subject: string }[] = [+ { draw: drawRanunculus, style: "PENCIL & WATERCOLOUR", subject: "RANUNCULUS" },+ { draw: drawKoi, style: "MARKER COMIC", subject: "KOI" },+ { draw: drawPocketWatch, style: "BALLPOINT SKETCH", subject: "POCKET WATCH" },+ { draw: drawBalloon, style: "CRAYON", subject: "HOT-AIR BALLOON" },+ { draw: drawWren, style: "INK & LINE-WASH", subject: "WREN ON A TWIG" },+ { draw: drawMoonPhases, style: "CHALKBOARD", subject: "PHASES OF THE MOON" },+ { draw: drawFox, style: "CUT-PAPER COLLAGE", subject: "FOX AT DUSK" },+ { draw: drawLighthouse, style: "RISOGRAPH", subject: "LIGHTHOUSE AT SUNSET" },+];++export const drawStyleGallery = (ctx: Ctx, _frame: number, env: Env) => {+ const s = env.scale;+ ctx.setTransform(s, 0, 0, s, 0, 0);+ ctx.fillStyle = SHEET; ctx.fillRect(0, 0, GW, GH);+ // one full-size surface, reused for every plate: each subject draws exactly as it does alone+ const sub: Env = { W: 1080, H: 1080, scale: s, cache: env.cache, canvas: env.canvas, image: env.image };+ const L = env.canvas(Math.round(1080 * s), Math.round(1080 * s));+ const g = new Gfx(ctx, env, 0, PENCIL);+ PLATES.forEach((p, i) => {+ const col = i % COLS, row = Math.floor(i / COLS), x = GUT + col * (TILE + GUT), y = HEAD + GUT + row * (TILE + LAB + GUT);+ L.ctx.setTransform(1, 0, 0, 1, 0, 0); L.ctx.globalAlpha = 1; L.ctx.globalCompositeOperation = "source-over"; L.ctx.clearRect(0, 0, L.canvas.width, L.canvas.height);+ p.draw(L.ctx, 0, sub);+ // the print, lying on the sheet: a soft shadow under it, a hairline edge+ ctx.setTransform(s, 0, 0, s, 0, 0);+ ctx.fillStyle = "rgba(60,45,30,0.10)"; ctx.fillRect(x + 6, y + 9, TILE, TILE); ctx.fillStyle = "rgba(60,45,30,0.08)"; ctx.fillRect(x + 2, y + 3, TILE, TILE);+ ctx.imageSmoothingEnabled = true; ctx.imageSmoothingQuality = "high";+ ctx.drawImage(L.canvas as CanvasImageSource, 0, 0, L.canvas.width, L.canvas.height, x, y, TILE, TILE);+ ctx.strokeStyle = "rgba(42,37,33,0.35)"; ctx.lineWidth = 1; ctx.strokeRect(x + 0.5, y + 0.5, TILE - 1, TILE - 1);+ // the caption, lettered like a contact sheet: number, the hand, then the subject+ letter(g, String(i + 1).padStart(2, "0"), x, y + TILE + 30, { cap: 26, color: MUTED, seed: 900 + i, w: 2.2, opacity: 0.95 });+ letter(g, p.style, x + 64, y + TILE + 30, { cap: 26, color: INKC, seed: 910 + i, w: 2.4, opacity: 0.95 });+ letter(g, p.subject, x + 64, y + TILE + 66, { cap: 17, color: MUTED, seed: 920 + i, w: 1.6, opacity: 0.9 });+ });+ letter(g, "ANIDOODLE / EIGHT HANDS, ONE ENGINE", GUT, 52, { cap: 46, color: INKC, seed: 1, w: 3.2, opacity: 0.95 });+ letter(g, "EVERY MARK DRAWN IN CODE. NO PHOTOGRAPHS, NO IMAGE OR AUDIO ASSETS, EVERY PLATE DETERMINISTIC.", GUT, 118, { cap: 19, color: MUTED, seed: 2, w: 1.7, opacity: 0.9 });+};++export const styleGallery: Film = {+ meta: { title: "anidoodle · style gallery", W: GW, H: GH, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "gallery", start: 0, end: 1, draw: drawStyleGallery }],+};diff --git a/engine/src/canvas-core/wren.ts b/engine/src/canvas-core/wren.tsnew file mode 100644index 0000000..914b892--- /dev/null+++ b/engine/src/canvas-core/wren.ts@@ -0,0 +1,161 @@+import { Gfx, rng, tube, type Ctx, type Env, type Medium, type P } from "./core";+import type { Film } from "./film";+import { blob, bounds, clamp, clipped, fillShape, lerpP, mix, smooth } from "./gallery";++// WREN ON A TWIG · ink + line-wash. The washes go down first and wet: they flood a little past+// where the line will be, the pigment slides down and settles along the BOTTOM edge of every+// shape, and where a second drop hit damp paper it pushed a pale backrun with a dark crinkled+// rim. Then the pen: a flexible nib, loose, thick where it pressed and hair-thin where it lifted,+// contours left open where the light eats the edge. A few spatters where the pen was shaken.+//+// The bird is a Eurasian wren, singing: round as a ball, tail cocked straight up, a pale+// eyebrow over a dark eyestripe, a thin decurved bill wide open, fine dark barring across the+// wing and tail, and pale spots on the coverts. It grips a hawthorn twig with its toes wrapped+// round the bark. A cluster of haws for the only red. Light from the upper left.++const INK_M: Medium = { nib: 1.7, taper: 1, pressure: 1.75, retrace: false, wobble: 1.35, rough: 0.6 };+const INK = "#16131f", PAPER = "#fbf8f0";+const BROWN = "#a0693a", DARKB = "#5e3a20", BUFF = "#e6c794", RUFOUS = "#b8733a", UMBER = "#6e4a2c", SAP = "#6f8f3e", HAW = "#c3262d";++// ---------------------------------------------------------------- wet media+// a wash: the core's displaced wet edge, then pigment pooled along the bottom of the same shape+const wet = (g: Gfx, pts: P[], color: string, o: { alpha: number; seed: number; pool?: number; bloom?: P | null; bloomR?: number }) => {+ const { alpha, seed, pool = 0.55, bloom = null, bloomR = 22 } = o, b = bounds(pts);+ g.group("paint", () => {+ g.wash(pts, color, { alpha, seed, dx: 7, dy: 6, shrink: 1.07, rim: true });+ clipped(g, pts, () => {+ const c = g.cur, gr = c.createLinearGradient(0, b.y0 + (b.y1 - b.y0) * 0.45, 0, b.y1 + 2);+ gr.addColorStop(0, color + "00"); gr.addColorStop(0.75, color + Math.round(255 * alpha * pool * 0.6).toString(16).padStart(2, "0")); gr.addColorStop(1, color + Math.round(255 * clamp(alpha * pool * 1.3)).toString(16).padStart(2, "0"));+ c.fillStyle = gr; c.fillRect(b.x0 - 20, b.y0, b.x1 - b.x0 + 40, b.y1 - b.y0 + 20);+ });+ if (bloom) { // a backrun: a pale cauliflower where a wetter drop pushed the pigment out to a dark crinkled rim+ const bl = blob(bloom[0], bloom[1], bloomR, bloomR * 0.8, seed + 7, 0.32, 18);+ fillShape(g, bl, PAPER, 0.42);+ const c = g.cur; c.strokeStyle = mix(color, INK, 0.25); c.globalAlpha = alpha * 0.9; c.lineWidth = 1.6; c.beginPath(); bl.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); c.stroke(); c.globalAlpha = 1;+ }+ });+};+// the pen: one loose stroke through a few control points, pressure making it thick and thin+const pen = (g: Gfx, pts: P[], w: number, seed: number, op = 0.95, wob = 0.9) => g.pen(pts, { w, color: INK, seed, wobble: wob, boil: 0, taper: 1, opacity: op, retrace: false });+const inked = (g: Gfx, fn: () => void) => g.group("plain", fn);++// ---------------------------------------------------------------- the twig and its haws+const twigLine: P[] = [[40, 806], [250, 752], [470, 712], [640, 690], [820, 652], [1080, 594]];+const side: P[] = [[792, 658], [846, 604], [884, 540], [930, 506]];+const lower: P[] = [[268, 748], [236, 806], [214, 868]];++const twig = (g: Gfx) => {+ const main = tube(twigLine, 17, 6, true), sb = tube(side, 7, 3, true), lb = tube(lower, 7, 3, true);+ wet(g, main, UMBER, { alpha: 0.62, seed: 30, pool: 0.8 }); wet(g, sb, UMBER, { alpha: 0.55, seed: 31 }); wet(g, lb, UMBER, { alpha: 0.55, seed: 32 });+ // leaves on the side shoot and at the tip: hawthorn-lobed, a green that goes blue in the shade+ const leaf = (base: P, ang: number, len: number, seed: number) => {+ const r = rng(seed), d: P = [Math.cos(ang), Math.sin(ang)], n: P = [-d[1], d[0]], at = (t: number, s: number): P => [base[0] + d[0] * t * len + n[0] * s * len, base[1] + d[1] * t * len + n[1] * s * len];+ const edge = [at(0, 0), at(0.2, 0.14), at(0.38, 0.3), at(0.5, 0.22), at(0.62, 0.34), at(0.78, 0.2), at(1, 0.02), at(0.8, -0.2), at(0.64, -0.3), at(0.5, -0.2), at(0.35, -0.28), at(0.18, -0.13)];+ const shape = smooth(edge, true, 5);+ wet(g, shape, mix(SAP, "#3f6c5e", r() * 0.4), { alpha: 0.6, seed, pool: 0.7 });+ return { shape, mid: [at(0, 0), at(0.55, 0.01 * (r() - 0.5)), at(0.95, 0)] as P[], veins: [0.3, 0.5, 0.7].map((t, k) => [at(t, 0), at(t + 0.12, (k % 2 ? 1 : -1) * 0.22)] as P[]) };+ };+ const leaves = [leaf([884, 540], -1.9, 96, 40), leaf([860, 580], -0.25, 110, 41), leaf([930, 506], -0.75, 88, 42), leaf([1010, 612], -1.1, 80, 43), leaf([236, 800], 2.2, 84, 44)];+ // haws hanging under the branch: crimson, a bare-paper highlight, dark where the pigment sank+ const haws: P[] = [[318, 772], [344, 786], [300, 796], [330, 810], [356, 812], [312, 822]];+ haws.forEach(([x, y], i) => wet(g, blob(x, y, 12, 12.5, 60 + i, 0.06, 12), HAW, { alpha: 0.85, seed: 60 + i, pool: 0.9 }));+ g.group("plain", () => haws.forEach(([x, y], i) => fillShape(g, blob(x - 4, y - 5, 3.4, 2.6, 70 + i, 0.1, 8), PAPER, 0.9)));+ inked(g, () => {+ // the bark: the top edge left open where the light hits, the underside pressed firmly+ const top = twigLine.map(([x, y], i) => [x, y - lerpP([17, 0], [6, 0], i / (twigLine.length - 1))[0]] as P), bot = twigLine.map(([x, y], i) => [x, y + lerpP([17, 0], [6, 0], i / (twigLine.length - 1))[0]] as P);+ pen(g, top.slice(0, 3), 1.7, 80, 0.8); pen(g, top.slice(3), 1.5, 81, 0.75);+ pen(g, bot.slice(0, 4), 2.6, 82); pen(g, bot.slice(3), 2.2, 83);+ pen(g, side.map(([x, y]) => [x + 4, y + 3] as P), 1.9, 84); pen(g, lower.map(([x, y]) => [x + 4, y] as P), 1.9, 85);+ // thorns and bark ticks+ const r = rng(86);+ [[150, 770, -1], [410, 716, -1], [700, 676, 1], [960, 616, -1], [590, 700, 1]].forEach(([x, y, s], i) => pen(g, [[x - 6, y], [x + 2, y + (s as number) * 14], [x + 7, y]], 1.4, 87 + i, 0.9, 0.3));+ for (let i = 0; i < 16; i++) { const t = r(), p = lerpP(twigLine[Math.floor(t * 4)], twigLine[Math.floor(t * 4) + 1], (t * 4) % 1); pen(g, [[p[0] - 5, p[1] - 2 + r() * 6], [p[0] + 6, p[1] + r() * 5]], 0.9, 100 + i, 0.55, 0.3); }+ leaves.forEach((l, i) => { pen(g, l.shape.filter((_, k) => k % 2 === 0), 1.3, 120 + i, 0.8, 0.7); pen(g, l.mid, 1.1, 130 + i, 0.7, 0.3); l.veins.forEach((v, k) => pen(g, v, 0.7, 140 + i * 5 + k, 0.55, 0.2)); });+ haws.forEach(([x, y], i) => { const bl = blob(x, y, 12, 12.5, 60 + i, 0.06, 12); pen(g, bl.slice(Math.floor(bl.length * 0.35)).concat(bl.slice(0, 2)), 1.3, 160 + i, 0.85, 0.4); fillShape(g, blob(x + 1, y + 11, 2.2, 1.8, 170 + i, 0.1, 6), INK, 0.8); });+ pen(g, [[300, 752], [312, 764], [318, 772]], 1, 180, 0.8, 0.2); pen(g, [[336, 752], [340, 772], [344, 786]], 1, 181, 0.8, 0.2); pen(g, [[322, 752], [324, 790], [330, 810]], 1, 182, 0.8, 0.2);+ });+};++// ---------------------------------------------------------------- the wren+const BODY: P[] = [[394, 450], [428, 416], [482, 420], [560, 448], [614, 494], [620, 536], [606, 582], [578, 624], [528, 650], [468, 634], [418, 590], [396, 540], [390, 492]];+const TAIL: P[] = [[590, 506], [606, 468], [626, 418], [646, 368], [662, 330], [690, 336], [684, 382], [664, 434], [644, 486], [622, 528]];+const WING: P[] = [[472, 476], [530, 468], [584, 500], [620, 552], [610, 584], [566, 598], [516, 580], [484, 540]];+const BELLY: P[] = [[410, 560], [452, 604], [506, 630], [560, 624], [548, 596], [488, 580], [440, 548]];++const bird = (g: Gfx) => {+ const body = smooth(BODY, true, 8), tail = smooth(TAIL, true, 8), wing = smooth(WING, true, 8), belly = smooth(BELLY, true, 8);+ // washes: warm brown all over, buff under, the wing and tail a darker umber, rufous on the back+ wet(g, tail, UMBER, { alpha: 0.62, seed: 200, pool: 0.4 });+ wet(g, body, BROWN, { alpha: 0.55, seed: 201, pool: 0.75, bloom: [548, 470], bloomR: 20 });+ wet(g, belly, BUFF, { alpha: 0.5, seed: 202, pool: 0.3 });+ wet(g, blob(520, 460, 70, 26, 203, 0.2, 12, 0.35), RUFOUS, { alpha: 0.35, seed: 204, pool: 0.2 });+ wet(g, wing, DARKB, { alpha: 0.45, seed: 205, pool: 0.6 });+ // the face: a pale eyebrow lifted out, a dark stripe through the eye+ g.group("plain", () => fillShape(g, smooth([[398, 446], [430, 436], [470, 440], [494, 452], [470, 450], [432, 448], [402, 456]], true, 6), mix(BUFF, PAPER, 0.5), 0.9));+ wet(g, smooth([[398, 462], [428, 454], [466, 460], [490, 474], [462, 472], [428, 470], [400, 472]], true, 6), DARKB, { alpha: 0.55, seed: 206, pool: 0.2 });++ inked(g, () => {+ // the contour: open where the light eats the edge (crown, back), pressed at the belly and under the tail+ const b = smooth(BODY, true, 6), n = b.length;+ pen(g, b.slice(Math.round(n * 0.0), Math.round(n * 0.2)), 2.4, 300, 0.9); // crown to nape, light+ pen(g, b.slice(Math.round(n * 0.25), Math.round(n * 0.4)), 2.2, 301, 0.8); // a broken back line+ pen(g, b.slice(Math.round(n * 0.44), Math.round(n * 0.78)), 4.6, 302, 0.96); // rump, vent, belly: firm+ pen(g, b.slice(Math.round(n * 0.52), Math.round(n * 0.72)).map(([x, y]) => [x + 3, y + 4] as P), 2.2, 304, 0.55, 1.6); // a second searching stroke under the belly+ pen(g, b.slice(Math.round(n * 0.76), Math.round(n * 0.99)), 3.6, 303, 0.95); // breast and throat+ const r2 = rng(305); for (let i = 0; i < 9; i++) { const x = 420 + r2() * 90, y = 520 + r2() * 90; pen(g, [[x, y], [x + 6, y + 5], [x + 9, y + 12]], 1.3, 306 + i, 0.4, 0.5); } // loose feather flicks on the breast+ const t = smooth(TAIL, true, 6), m = t.length;+ pen(g, t.slice(0, Math.round(m * 0.55)), 2.4, 310, 0.88); pen(g, t.slice(Math.round(m * 0.5), m - 2), 3.6, 311, 0.93);+ for (let i = 0; i < 9; i++) { const f = 0.12 + i * 0.1, a = lerpP(TAIL[1], TAIL[4], f), c = lerpP(TAIL[9], TAIL[6], f); pen(g, [lerpP(a, c, 0.06), lerpP(lerpP(a, c, 0.5), [a[0] - 3, a[1] + 3], 0.3), lerpP(a, c, 0.94)], 1.5, 320 + i, 0.8, 0.4); } // tail barring+ // the folded wing: its lower edge firm, primaries barred, pale spots on the coverts+ const w2 = smooth(WING, true, 6), q = w2.length;+ pen(g, w2.slice(Math.round(q * 0.12), Math.round(q * 0.64)), 3.4, 330, 0.93); pen(g, w2.slice(Math.round(q * 0.6), Math.round(q * 0.9)), 2.2, 331, 0.8);+ for (let i = 0; i < 7; i++) { const x = 548 + i * 9, y = 526 + i * 7; pen(g, [[x - 8, y - 12], [x - 2, y - 4], [x + 6, y + 6]], 1.6, 340 + i, 0.85, 0.3); }+ const sp: P[] = [[486, 490], [503, 503], [519, 488], [534, 506], [552, 497], [568, 512], [512, 518]]; for (let i = 0; i < sp.length; i++) { const [x, y] = sp[i]; fillShape(g, blob(x, y, 3.2, 2.2, 350 + i, 0.2, 8), PAPER, 0.95); pen(g, [[x - 5, y + 3], [x, y + 5], [x + 5, y + 3]], 0.9, 356 + i, 0.8, 0.2); }+ // flank barring, faint+ for (let i = 0; i < 6; i++) { const x = 548 + i * 10, y = 596 + (i % 2) * 5; pen(g, [[x - 7, y], [x, y + 4], [x + 7, y + 1]], 1.0, 360 + i, 0.55, 0.3); }+ // the bill, wide open in song, and the pink gape inside it+ g.group("plain", () => fillShape(g, [[397, 460], [362, 450], [364, 462], [397, 472]], "#d9806a", 0.8));+ pen(g, [[400, 452], [376, 443], [346, 439]], 3.2, 370, 0.97, 0.15); pen(g, [[398, 459], [374, 451], [348, 441]], 1.6, 371, 0.9, 0.15);+ pen(g, [[400, 477], [378, 472], [352, 467]], 2.8, 372, 0.97, 0.15);+ pen(g, [[402, 462], [432, 460], [470, 466], [492, 474]], 2.2, 375, 0.7, 0.4); // the eyestripe, drawn+ pen(g, [[392, 478], [398, 496], [404, 520]], 1.1, 373, 0.5, 0.4); // throat feathers parting as it sings+ // the eye: a bead with a catchlight, half-lidded by the eyestripe+ fillShape(g, blob(432, 461, 7.2, 7, 380, 0.05, 10), INK); fillShape(g, blob(429.5, 458.5, 2.2, 2, 381, 0.05, 8), PAPER);+ // legs and toes wrapped round the twig+ [[498, 640, 486, 700], [534, 644, 540, 696]].forEach(([x0, y0, x1, y1], i) => {+ fillShape(g, [[x0 - 4, y0], [x0 + 4, y0], [x1 + 3, y1], [x1 - 3, y1]], "#b98468", 0.75);+ pen(g, [[x0, y0], [lerpP([x0, y0], [x1, y1], 0.5)[0] + 2, lerpP([x0, y0], [x1, y1], 0.5)[1]], [x1, y1]], 2.6, 390 + i, 0.95, 0.2);+ pen(g, [[x1, y1], [x1 - 14, y1 + 2], [x1 - 22, y1 + 12]], 1.6, 392 + i, 0.95, 0.2); // front toes curl over the bark+ pen(g, [[x1, y1], [x1 - 4, y1 + 8], [x1 - 10, y1 + 18]], 1.5, 394 + i, 0.9, 0.2);+ pen(g, [[x1, y1], [x1 + 12, y1 + 4], [x1 + 16, y1 + 14]], 1.5, 396 + i, 0.9, 0.2); // the hind toe grips from behind+ });+ });+};++const background = (g: Gfx) => {+ // one loose wash behind the bird, cool, with a warm drop let into it lower down while it was wet+ g.group("paint", () => {+ g.wash(blob(560, 500, 330, 250, 10, 0.3, 22, -0.35), "#9fb3c8", { alpha: 0.28, seed: 10, dx: 0, dy: 6, shrink: 1 });+ g.wash(blob(440, 700, 230, 120, 11, 0.35, 18, -0.2), "#d8b98a", { alpha: 0.25, seed: 11, dx: 0, dy: 4, shrink: 1 });+ g.wash(blob(700, 330, 120, 90, 12, 0.35, 16, 0.3), "#b8c7d6", { alpha: 0.22, seed: 12, dx: 0, dy: 4, shrink: 1 });+ });+ // spatters flicked off the nib+ g.group("plain", () => { const r = rng(13); for (let i = 0; i < 22; i++) { const x = 160 + r() * 820, y = 280 + r() * 640, big = r() < 0.25; if (Math.hypot(x - 510, y - 530) < 170) continue; fillShape(g, blob(x, y, big ? 3.6 : 1.4 + r(), big ? 3 : 1.2 + r() * 0.8, 20 + i, 0.3, 8), INK, 0.7 + r() * 0.3); } });+};++export const drawWren = (ctx: Ctx, _frame: number, env: Env) => {+ const g = new Gfx(ctx, env, 0, INK_M);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ ctx.fillStyle = PAPER; ctx.fillRect(0, 0, 1080, 1080);+ background(g);+ twig(g);+ bird(g);+ g.paper("coldpress", 0.16);+ g.paper("paper", 0.08);+};++export const wren: Film = {+ meta: { title: "Wren on a twig · ink + line-wash", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },+ assets: { images: {} },+ shots: [{ id: "wren", start: 0, end: 1, draw: drawWren }],+};diff --git a/engine/src/hosts/page-balloon.ts b/engine/src/hosts/page-balloon.tsnew file mode 100644index 0000000..ccd44b1--- /dev/null+++ b/engine/src/hosts/page-balloon.ts@@ -0,0 +1,4 @@+import { balloon } from "../canvas-core/balloon";+import { mountFilm } from "./page";++mountFilm(balloon);diff --git a/engine/src/hosts/page-fox.ts b/engine/src/hosts/page-fox.tsnew file mode 100644index 0000000..e2a07e8--- /dev/null+++ b/engine/src/hosts/page-fox.ts@@ -0,0 +1,4 @@+import { fox } from "../canvas-core/fox";+import { mountFilm } from "./page";++mountFilm(fox);diff --git a/engine/src/hosts/page-koi.ts b/engine/src/hosts/page-koi.tsnew file mode 100644index 0000000..292e7ab--- /dev/null+++ b/engine/src/hosts/page-koi.ts@@ -0,0 +1,4 @@+import { koi } from "../canvas-core/koi";+import { mountFilm } from "./page";++mountFilm(koi);diff --git a/engine/src/hosts/page-lighthouse.ts b/engine/src/hosts/page-lighthouse.tsnew file mode 100644index 0000000..2b5046a--- /dev/null+++ b/engine/src/hosts/page-lighthouse.ts@@ -0,0 +1,4 @@+import { lighthouse } from "../canvas-core/lighthouse";+import { mountFilm } from "./page";++mountFilm(lighthouse);diff --git a/engine/src/hosts/page-mellan.ts b/engine/src/hosts/page-mellan.tsnew file mode 100644index 0000000..87e898a--- /dev/null+++ b/engine/src/hosts/page-mellan.ts@@ -0,0 +1,4 @@+import { mellan } from "../canvas-core/mellan";+import { mountFilm } from "./page";++mountFilm(mellan);diff --git a/engine/src/hosts/page-mellanUnspool.ts b/engine/src/hosts/page-mellanUnspool.tsnew file mode 100644index 0000000..e8b2693--- /dev/null+++ b/engine/src/hosts/page-mellanUnspool.ts@@ -0,0 +1,4 @@+import { mellanUnspool } from "../canvas-core/mellanUnspool";+import { mountFilm } from "./page";++mountFilm(mellanUnspool);diff --git a/engine/src/hosts/page-moonPhases.ts b/engine/src/hosts/page-moonPhases.tsnew file mode 100644index 0000000..7a4417b--- /dev/null+++ b/engine/src/hosts/page-moonPhases.ts@@ -0,0 +1,4 @@+import { moonPhases } from "../canvas-core/moonPhases";+import { mountFilm } from "./page";++mountFilm(moonPhases);diff --git a/engine/src/hosts/page-pocketWatch.ts b/engine/src/hosts/page-pocketWatch.tsnew file mode 100644index 0000000..e433965--- /dev/null+++ b/engine/src/hosts/page-pocketWatch.ts@@ -0,0 +1,4 @@+import { pocketWatch } from "../canvas-core/pocketWatch";+import { mountFilm } from "./page";++mountFilm(pocketWatch);diff --git a/engine/src/hosts/page-ranunculus.ts b/engine/src/hosts/page-ranunculus.tsnew file mode 100644index 0000000..dd9c661--- /dev/null+++ b/engine/src/hosts/page-ranunculus.ts@@ -0,0 +1,4 @@+import { ranunculus } from "../canvas-core/ranunculus";+import { mountFilm } from "./page";++mountFilm(ranunculus);diff --git a/engine/src/hosts/page-styleGallery.ts b/engine/src/hosts/page-styleGallery.tsnew file mode 100644index 0000000..abb2f7d--- /dev/null+++ b/engine/src/hosts/page-styleGallery.ts@@ -0,0 +1,4 @@+import { styleGallery } from "../canvas-core/styleGallery";+import { mountFilm } from "./page";++mountFilm(styleGallery);diff --git a/engine/src/hosts/page-wren.ts b/engine/src/hosts/page-wren.tsnew file mode 100644index 0000000..3ed6104--- /dev/null+++ b/engine/src/hosts/page-wren.ts@@ -0,0 +1,4 @@+import { wren } from "../canvas-core/wren";+import { mountFilm } from "./page";++mountFilm(wren);diff --git a/engine/src/hosts/page.ts b/engine/src/hosts/page.tsnew file mode 100644index 0000000..72c775d--- /dev/null+++ b/engine/src/hosts/page.ts@@ -0,0 +1,43 @@+// THE ONE GENERATED PAGE. Playwright, the HTML player and (Phase 5) Hyperframes all drive this+// same page through window.FILM. Everything host-specific (DOM, clocks, asset decoding, Web+// Audio) lives HERE; the art core never sees it.+import type { Ctx, Env, Layer } from "../canvas-core/core";+import { Film, renderFrame, validate } from "../canvas-core/film";++declare global { interface Window { FILM: unknown; __ASSETS__?: Record<string, string> } }++export const mountFilm = (film: Film) => {+ const canvas = document.getElementById("film") as HTMLCanvasElement, images = new Map<string, CanvasImageSource>();+ let env: Env, ctx: Ctx, current = 0;+ // Safari before 16.4 has no 2D OffscreenCanvas: fall back to a detached <canvas>. The core cannot tell the difference.+ const surface = (w: number, h: number): Layer => { const c = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(w, h) : Object.assign(document.createElement("canvas"), { width: w, height: h }); return { canvas: c, ctx: c.getContext("2d") as unknown as Ctx } as Layer; };+ const mount = (scale = 1) => { canvas.width = Math.round(film.meta.W * scale); canvas.height = Math.round(film.meta.H * scale); ctx = canvas.getContext("2d")!; env = { W: film.meta.W, H: film.meta.H, scale, cache: new Map(), canvas: surface, image: (n) => images.get(n) }; return film.meta; };+ // contract rule 4: every asset is loaded AND decoded before frame 0, or the film refuses to start+ const ready = (async () => {+ const problems = validate(film); if (problems.length) throw new Error("timeline: " + problems.join("; "));+ await Promise.all(Object.entries(film.assets.images).map(async ([name, url]) => { const img = new Image(); img.src = window.__ASSETS__?.[name] ?? url; await img.decode(); images.set(name, img); }));+ mount(1); return film.meta;+ })();+ const seek = (frame: number) => { const t0 = performance.now(); const shot = renderFrame(film, ctx, frame, env); ctx.getImageData(0, 0, 1, 1); current = frame; return { shot, ms: performance.now() - t0 }; }; // getImageData forces the deferred raster so the timing is real+ const hash = () => { const d = ctx.getImageData(0, 0, canvas.width, canvas.height).data; let h = 0x811c9dc5; for (let i = 0; i < d.length; i++) { h ^= d[i]; h = Math.imul(h, 0x01000193); } return (h >>> 0).toString(16); };+ const b64 = (u8: Uint8Array) => { let s = ""; for (let i = 0; i < u8.length; i += 0x8000) s += String.fromCharCode(...u8.subarray(i, i + 0x8000)); return btoa(s); };+ const audio = (sr: number) => { if (!film.audio) return null; const [L, R] = film.audio(sr), pcm = new Int16Array(L.length * 2); for (let i = 0; i < L.length; i++) { pcm[i * 2] = Math.max(-1, Math.min(1, L[i])) * 32767; pcm[i * 2 + 1] = Math.max(-1, Math.min(1, R[i])) * 32767; } return { sampleRate: sr, frames: L.length, pcm16: b64(new Uint8Array(pcm.buffer)) }; };+ const warm = () => film.shots.forEach((s) => { seek(s.start); seek(s.start + ((s.end - s.start) >> 1)); }); // first + middle frame of every shot: builds tiles, pre-allocates the layer pool+ window.FILM = { meta: film.meta, ready, mount, seek, hash, audio, warm, png: () => canvas.toDataURL("image/png").slice(22), frame: () => current };++ // ---- the player: click or space to play, arrows to step, ?frame=N to open on a frame+ ready.then(() => {+ const q = new URLSearchParams(location.search); if (q.has("adapter")) return; // a backend is driving: stay still+ seek(Number(q.get("frame") ?? 0));+ let playing = false, ac: AudioContext | null = null, t0 = 0, f0 = 0, node: AudioBufferSourceNode | null = null;+ const stop = () => { playing = false; node?.stop(); node = null; };+ const play = () => {+ ac ??= new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)(); playing = true; f0 = current >= film.meta.durationFrames - 1 ? 0 : current; t0 = ac.currentTime;+ if (film.audio) { const [L, R] = film.audio(ac.sampleRate), buf = ac.createBuffer(2, L.length, ac.sampleRate); buf.getChannelData(0).set(L); buf.getChannelData(1).set(R); node = ac.createBufferSource(); node.buffer = buf; node.connect(ac.destination); node.start(0, f0 / film.meta.fps); }+ const tick = () => { if (!playing) return; const f = f0 + Math.floor((ac!.currentTime - t0) * film.meta.fps); if (f >= film.meta.durationFrames) { seek(film.meta.durationFrames - 1); stop(); return; } if (f !== current) seek(f); requestAnimationFrame(tick); }; tick();+ };+ const toggle = () => (playing ? stop() : play());+ canvas.addEventListener("click", toggle);+ addEventListener("keydown", (e) => { if (e.key === " ") { e.preventDefault(); toggle(); } if (e.key === "ArrowRight") { stop(); seek(Math.min(film.meta.durationFrames - 1, current + 1)); } if (e.key === "ArrowLeft") { stop(); seek(Math.max(0, current - 1)); } });+ });+};diff --git a/engine/tools/adapters/README.md b/engine/tools/adapters/README.mdnew file mode 100644index 0000000..502bebb--- /dev/null+++ b/engine/tools/adapters/README.md@@ -0,0 +1,66 @@+# Render adapters++An adapter is the only thing that knows how a film becomes pixels. The art core never sees one.++Every adapter exports the same four things, so `tools/gate.mjs` can hold any of them to the same+bar without knowing which it has got:++```js+export const name = "html-player"; // what to call it in a report+export const describe = () => "one sentence"; // what this adapter DELIVERS+export const probe = () => ({ ok, why }); // can it run here, and if not, why not+export const open = async (env, film, opts) => session;+```++`opts` carries `{ scale, workers }`. `workers` is the number of independent draw contexts the+session runs; the gate uses it to re-draw the same frames a different way and check they come out+the same. A session is:++```js+{ workers, // how many it actually opened+ info(), // -> film.meta+ frame(n, w), // -> { png: Buffer, shot, drawMs }+ hash(n, w), // -> stable hex digest of the drawn pixels+ audio(sampleRate), // -> { sampleRate, frames, pcm16 } | null+ artifact(), // -> { path, kind, bytes, checks: [{ok,label,detail}] } | null+ close() }+```++## The four adapters++| Adapter | Delivers | Runs here |+| --- | --- | --- |+| `playwright` | frames, as a means to an MP4 | yes |+| `html-player` | THE PAGE: one self-contained offline HTML file | yes |+| `remotion` | frames through a Remotion `<Composition>`, one still per frame | yes (`[email protected]`) |+| `hyperframes` | frames seeked in headless Chrome by the Hyperframes engine | no: `npm i -D @hyperframes/engine` (Node >= 22, Chrome, ffmpeg), then `node tools/gate.mjs <film> --adapter hyperframes` |++Every adapter reaches the art through the same pure `renderFrame(film, ctx, frame, env)` and the+same `film.audio(sampleRate)`. None of them is visible from `src/canvas-core`.++Two notes worth carrying:++- **`remotion` renders every frame COLD** (a still is its own page), so it proves frame N owes+ nothing to the frames before it, and it CANNOT catch a stale cache. `html-player` shares one+ warm cache across frames and can. They check different things; run both.+- **`hyperframes` is not installed**, so its node-side capture calls have never been run. Its+ page-side FrameAdapter is proved on its own, against Hyperframes' published contract, by+ `node tools/verify-frame-adapter.mjs` — finite duration, forward/backward/random seeks, the+ same state for the same frame, and seeked pixels identical to the plain player's.++`artifact()` is the adapter's own deliverable, if it has one. The playwright adapter has none: it+is a means to an MP4. The html-player adapter's deliverable IS the page, so it returns it and+declares the checks that make that page worth shipping.++## The gate++`node tools/gate.mjs <film> [--adapter html-player] [--mp4 out/x.mp4] [--samples 12]`++Three checks, PASS/FAIL, non-zero exit on any failure:++1. **Determinism** — the same sampled frames drawn twice, at two different worker counts, in two+ different orders. Byte-identical, or PSNR above 45 dB.+2. **Contract** — a static scan of every module the film draws through: no `Math.random`, `Date`,+ `performance.now`, `ctx.filter`, network, or image/font assets; all randomness via `rng(seed)`.+3. **Dead air** — no identical consecutive frames and no 15-frame window under 0.5 % changed area,+ measured on a rendered MP4 that the gate only ever READS.diff --git a/engine/tools/adapters/html-player.mjs b/engine/tools/adapters/html-player.mjsnew file mode 100644index 0000000..dabd881--- /dev/null+++ b/engine/tools/adapters/html-player.mjs@@ -0,0 +1,72 @@+// HTML-PLAYER ADAPTER. The film's deliverable here is not a video, it is the PAGE: one+// self-contained HTML file that plays the whole thing in any browser with no server, no network+// and no sibling files. That is the artifact this adapter produces and the one it is judged on.+//+// It still renders frames, because the gate has to be able to draw the same frame twice and+// compare. It does that by opening N INDEPENDENT instances of the page, which is a stronger test+// than it sounds: each instance has its own texture tiles, its own layer pool and its own cache,+// so two instances agreeing means the caches are genuinely keyed on what the pixels depend on and+// not on the order somebody happened to ask for frames in.+import { readFileSync, statSync } from "node:fs";+import { resolve } from "node:path";+import { pathToFileURL } from "node:url";+import { buildPage } from "../build-page.mjs";+import { detect } from "../detect.mjs";++export const name = "html-player";+export const describe = () => "a single self-contained HTML file that plays the film in any browser, offline";++export const probe = () => {+ const env = detect();+ if (!env.pw.ok) return { ok: false, why: `needs playwright to drive the page: ${env.pw.why}` };+ if (!env.browser.ok) return { ok: false, why: `needs a chromium build: ${env.browser.why}` };+ return { ok: true, why: `${env.pw.id}@${env.pw.version}, ${env.browser.why}`, env };+};++// what makes a self-contained page worth shipping: nothing in it may reach outside itself+export const pageChecks = (html) => {+ const has = (re) => { const m = html.match(re); return m ? m.length : 0; };+ const assets = html.match(/window\.__ASSETS__=([^;]*);/);+ return [+ { ok: has(/https?:\/\//g) === 0, label: "no http(s) reference of any kind", detail: `${has(/https?:\/\//g)} found` },+ { ok: has(/<(img|audio|video|source|link|iframe)\b/gi) === 0, label: "no external element (img, audio, video, link)", detail: `${has(/<(img|audio|video|source|link|iframe)\b/gi)} found` },+ { ok: has(/@font-face/gi) === 0, label: "no web font", detail: `${has(/@font-face/gi)} found` },+ { ok: has(/data:[a-z]+\/[a-z0-9.+-]+;base64/gi) === 0, label: "no embedded binary asset", detail: `${has(/data:[a-z]+\/[a-z0-9.+-]+;base64/gi)} found` },+ { ok: has(/fetch\(|XMLHttpRequest|importScripts/g) === 0, label: "no network call in the bundle", detail: `${has(/fetch\(|XMLHttpRequest|importScripts/g)} found` },+ { ok: assets ? assets[1].trim() === "{}" : false, label: "the asset manifest is empty", detail: assets ? assets[1].trim() : "manifest absent" },+ { ok: /window\.FILM\s*=/.test(html), label: "exposes window.FILM so any host can drive it", detail: "" },+ { ok: /audio\s*[:(]/.test(html), label: "carries its own audio, synthesized in the page", detail: "" },+ ];+};++export const open = async (film, opts = {}) => {+ const { scale = 1, workers = 1 } = opts;+ const p = probe();+ if (!p.ok) throw new Error(`html-player: ${p.why}`);+ const out = resolve(`dist/${film}.html`);+ const built = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });+ const html = readFileSync(out, "utf8");++ const browser = await p.env.pw.lib.chromium.launch({ executablePath: p.env.browser.executablePath, args: ["--disable-background-timer-throttling"] });+ const context = await browser.newContext({ viewport: { width: 640, height: 640 }, deviceScaleFactor: 1 });+ const pages = [];+ for (let i = 0; i < workers; i++) {+ const page = await context.newPage(), errors = [];+ page.on("pageerror", (e) => errors.push(e.message));+ page.on("request", (r) => { if (!r.url().startsWith("file:") && !r.url().startsWith("data:")) errors.push(`page reached the network: ${r.url()}`); }); /* the page is supposed to be offline: prove it at run time, not just by reading it */+ await page.goto(pathToFileURL(out).href + "?adapter=html-player");+ await page.evaluate(async (s) => { await window.FILM.ready; window.FILM.mount(s); window.FILM.warm(); }, scale);+ if (errors.length) throw new Error("page failed: " + errors.join("; "));+ pages.push(page);+ }+ const pick = (w) => pages[((w % pages.length) + pages.length) % pages.length];+ return {+ workers: pages.length,+ info: () => pages[0].evaluate(() => window.FILM.meta),+ frame: async (n, w = 0) => { const r = await pick(w).evaluate((f) => { const s = window.FILM.seek(f); return { ...s, png: window.FILM.png() }; }, n); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms }; },+ hash: (n, w = 0) => pick(w).evaluate((f) => { window.FILM.seek(f); return window.FILM.hash(); }, n),+ audio: (sr) => pages[0].evaluate((s) => window.FILM.audio(s), sr),+ artifact: () => ({ path: out, kind: "self-contained HTML player", bytes: statSync(out).size, meta: built.meta, checks: pageChecks(html) }),+ close: () => browser.close(),+ };+};diff --git a/engine/tools/adapters/hyperframes.mjs b/engine/tools/adapters/hyperframes.mjsnew file mode 100644index 0000000..27f2269--- /dev/null+++ b/engine/tools/adapters/hyperframes.mjs@@ -0,0 +1,119 @@+// HYPERFRAMES ADAPTER. Hyperframes (@hyperframes/engine) drives a SEEKABLE page: headless Chrome,+// one deterministic seek per frame, captured through Chrome's BeginFrame rather than by letting a+// clock run. Its page-side contract is a FRAME ADAPTER:+//+// type FrameAdapter = {+// id: string;+// init?: (ctx) => Promise<void> | void;+// getDurationFrames: () => number;+// seekFrame: (frame: number) => Promise<void> | void; // a FRAME NUMBER, not seconds+// destroy?: () => Promise<void> | void;+// };+//+// and it asks of that adapter exactly what this engine already guarantees: a finite frame count,+// forward, backward and random seeks, the SAME STATE whenever the same frame is asked for again,+// no wall-clock timers, no unseeded randomness, and all async work finished before capture. That+// is the pull model this film was built on, so the adapter below is nine lines of plumbing:+// `seekFrame(n)` is `window.FILM.seek(n)` and nothing else.+//+// NOT INSTALLED HERE. @hyperframes/engine is not a dependency of this project, so every reference+// to it is behind a dynamic import inside open(): this file imports clean, probe() says exactly+// what is missing and how to get it, and the gate reports CANNOT RUN rather than failing. See+// tools/adapters/README.md for the one-line install.+//+// WHAT IS VERIFIED AND WHAT IS NOT. The page-side FrameAdapter shape above is from Hyperframes'+// published contract and is implemented exactly. The node-side capture calls are taken from the+// engine's own README example, but they have NOT been run here, because running them means+// installing the package. So this adapter refuses to guess: it checks that the module really+// exports what it is about to call and, if not, says what it found instead. A backend that is+// not installed should report that it is not installed, never quietly produce a wrong answer.+import { createHash } from "node:crypto";+import { createRequire } from "node:module";+import { mkdirSync, readFileSync } from "node:fs";+import { join, resolve } from "node:path";+import { pathToFileURL } from "node:url";+import { buildPage } from "../build-page.mjs";++const require = createRequire(import.meta.url);+const version = (id) => { try { return require(`${id}/package.json`).version; } catch { return null; } };++export const name = "hyperframes";+export const describe = () => "the film seeked frame by frame in headless Chrome by the Hyperframes engine";++export const ENGINE = "@hyperframes/engine";+export const INSTALL = `npm i -D ${ENGINE}`;++export const probe = () => {+ const v = version(ENGINE);+ if (!v) return { ok: false, why: `${ENGINE} is not installed (${INSTALL}); needs Node >= 22, Chrome and ffmpeg` };+ return { ok: true, why: `${ENGINE}@${v}` };+};++// The page-side frame adapter, as a string because it is evaluated in the BROWSER. It is the+// whole of the Hyperframes contract for this film, and it adds no state of its own: every answer+// comes from window.FILM, which is the same surface playwright and the html player drive.+export const FRAME_ADAPTER = (film) => `+ (() => {+ const ready = window.FILM.ready.then(() => window.FILM.mount(${JSON.stringify(1)}));+ const adapter = {+ id: ${JSON.stringify(film)},+ init: () => ready,+ getDurationFrames: () => window.FILM.meta.durationFrames,+ seekFrame: (n) => { window.FILM.seek(n); }, /* synchronous by design: the draw is finished before this returns, so there is nothing to await and nothing to race */+ destroy: () => {},+ };+ window.__hfAdapter = adapter;+ // The engine's own README describes a simpler surface on window.__hf. Both are served from+ // the one object so there is a single source of truth whichever the installed version asks for.+ window.__hf = { duration: () => adapter.getDurationFrames(), seek: (n) => adapter.seekFrame(n), adapter };+ })();+`;++const need = (mod, names) => {+ const missing = names.filter((n) => typeof mod[n] !== "function");+ if (missing.length) throw new Error(`hyperframes: ${ENGINE}@${version(ENGINE)} does not export ${missing.join(", ")} (it exports: ${Object.keys(mod).filter((k) => typeof mod[k] === "function").sort().join(", ") || "no functions"}). This adapter was written against the engine's documented capture API; if that API has moved, fix it here rather than guessing.`);+};++export const open = async (film, opts = {}) => {+ const { scale = 1, workers = 1 } = opts;+ const p = probe();+ if (!p.ok) throw new Error(`hyperframes: ${p.why}`);+ const engine = await import(ENGINE);+ need(engine, ["acquireBrowser", "createCaptureSession", "initializeSession", "captureFrame", "closeCaptureSession"]);++ // Built into .tmp, never over the shipped page: out/ holds the approved deliverable and no+ // adapter has any business rewriting it to render a frame.+ const dir = resolve(".tmp/hyperframes", film);+ mkdirSync(dir, { recursive: true });+ const out = join(dir, `${film}.html`);+ const built = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });+ const { writeFileSync } = await import("node:fs");+ writeFileSync(out, readFileSync(out, "utf8").replace("</body>", `<script>${FRAME_ADAPTER(film)}</script></body>`));++ const leases = [], sessions = [];+ for (let i = 0; i < Math.max(1, workers); i++) {+ const lease = await engine.acquireBrowser({ captureMode: "beginFrame" });+ const session = engine.createCaptureSession({ browser: lease.browser, url: pathToFileURL(out).href + "?adapter=hyperframes", width: Math.round(built.meta.W * scale), height: Math.round(built.meta.H * scale), fps: built.meta.fps });+ await engine.initializeSession(session);+ leases.push(lease); sessions.push(session);+ }+ const pick = (w) => sessions[((w % sessions.length) + sessions.length) % sessions.length];++ const grab = async (n, w) => {+ const f = Math.max(0, Math.min(built.meta.durationFrames - 1, Math.round(n)));+ const file = join(dir, `f${f}-w${w % Math.max(1, workers)}.png`);+ const t0 = Date.now();+ await engine.captureFrame(pick(w), f, file);+ return { png: readFileSync(file), drawMs: Date.now() - t0 };+ };++ return {+ workers: sessions.length,+ info: () => built.meta,+ frame: async (n, w = 0) => { const r = await grab(n, w); return { png: r.png, shot: null, drawMs: r.drawMs }; },+ hash: async (n, w = 0) => createHash("sha256").update((await grab(n, w)).png).digest("hex").slice(0, 16),+ audio: async (sr) => { const s = pick(0); return s && engine.captureAudio ? engine.captureAudio(s, sr) : null; }, /* the engine mixes audio from <audio> elements; this film synthesizes its score in the page, so there is none to mix */+ artifact: () => null,+ close: async () => { for (const s of sessions) await engine.closeCaptureSession(s); for (const l of leases) await l.release(); },+ };+};diff --git a/engine/tools/adapters/playwright.mjs b/engine/tools/adapters/playwright.mjsnew file mode 100644index 0000000..b0c2f13--- /dev/null+++ b/engine/tools/adapters/playwright.mjs@@ -0,0 +1,22 @@+// PLAYWRIGHT ADAPTER. Thin by design: open the generated page, ask it for frame N, take the+// canvas pixels. Frame accuracy comes from the pull model (frame N is a pure function of N),+// not from anything Playwright does.+import { pathToFileURL } from "node:url";++export const name = "playwright";+export const open = async ({ pw, browser: found }, pagePath, { scale = 1, workers = 1 } = {}) => {+ const browser = await pw.lib.chromium.launch({ executablePath: found.executablePath, args: ["--disable-background-timer-throttling"] });+ const context = await browser.newContext({ viewport: { width: 640, height: 640 }, deviceScaleFactor: 1 });+ const pages = [];+ for (let i = 0; i < workers; i++) { const page = await context.newPage(); const errors = []; page.on("pageerror", (e) => errors.push(e.message)); await page.goto(pathToFileURL(pagePath).href + "?adapter=playwright"); await page.evaluate(async (s) => { await window.FILM.ready; window.FILM.mount(s); window.FILM.warm(); }, scale); /* warm = build texture tiles once, outside the timed frames */ if (errors.length) throw new Error("page failed: " + errors.join("; ")); pages.push(page); }+ const pick = (n) => pages[n % pages.length];+ return {+ workers: pages.length,+ info: () => pages[0].evaluate(() => window.FILM.meta),+ // -> { png: Buffer, shot, drawMs, captureMs }+ frame: async (n, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate((f) => { const s = window.FILM.seek(f); const t = performance.now(); const png = window.FILM.png(); return { ...s, png, enc: performance.now() - t }; }, n); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },+ hash: (n, w = 0) => pick(w).evaluate((f) => { window.FILM.seek(f); return window.FILM.hash(); }, n),+ audio: (sr) => pages[0].evaluate((s) => window.FILM.audio(s), sr),+ close: () => browser.close(),+ };+};diff --git a/engine/tools/adapters/remotion.mjs b/engine/tools/adapters/remotion.mjsnew file mode 100644index 0000000..13b84ba--- /dev/null+++ b/engine/tools/adapters/remotion.mjs@@ -0,0 +1,116 @@+// REMOTION ADAPTER. Drives the same pure art core through a Remotion <Composition>: a canvas in+// a React component, `renderFrame(film, ctx, frame, env)` keyed to useCurrentFrame(), and the+// score read straight off `film.audio(sampleRate)`. Remotion supplies the frame number and takes+// the screenshot; it is told nothing else, and the art core never learns it is there.+//+// WHAT THIS ADAPTER PROVES, AND WHAT IT DOES NOT. Each still is rendered in its own page, so+// every frame here is drawn COLD. That is a real and complementary check: it proves frame N owes+// nothing to the frames rendered before it. It is also why this adapter cannot catch a stale+// cache the way html-player can, and the gate's determinism section is weaker when pointed at+// it. Run BOTH; neither is the whole bar. (`references/backends-and-adapters.md` has the worked+// case: an order-dependence only a warm, shared-cache adapter can surface.)+import { createHash } from "node:crypto";+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { createRequire } from "node:module";+import { join, resolve } from "node:path";++const require = createRequire(import.meta.url);+const tryRequire = (id) => { try { return require(id); } catch { return null; } };+const version = (id) => tryRequire(`${id}/package.json`)?.version ?? null;++export const name = "remotion";+export const describe = () => "the same art core rendered through a Remotion <Composition>, one still per frame";++export const probe = () => {+ const need = ["remotion", "@remotion/bundler", "@remotion/renderer"];+ const missing = need.filter((id) => !version(id));+ if (missing.length) return { ok: false, why: `not installed: ${missing.join(", ")} (npm i ${missing.join(" ")})` };+ const vs = need.map((id) => `${id}@${version(id)}`);+ const spread = new Set(need.map((id) => version(id)));+ if (spread.size > 1) return { ok: false, why: `remotion packages disagree on version (${vs.join(", ")}); they must match` };+ return { ok: true, why: vs.join(", ") };+};++// The film module is the source of truth for meta and for the score. It is read the way+// build-page.mjs reads it: bundled on its own, with no host attached, so nothing can disagree.+const loadFilm = async (film) => {+ const { build } = await import("esbuild");+ const out = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text;+ return (await import("data:text/javascript;base64," + Buffer.from(out).toString("base64"))).film;+};++const pcm16 = (film, sr) => {+ if (!film.audio) return null;+ const [L, R] = film.audio(sr), pcm = new Int16Array(L.length * 2);+ for (let i = 0; i < L.length; i++) { pcm[i * 2] = Math.max(-1, Math.min(1, L[i])) * 32767; pcm[i * 2 + 1] = Math.max(-1, Math.min(1, R[i])) * 32767; }+ return { sampleRate: sr, frames: L.length, pcm16: Buffer.from(pcm.buffer).toString("base64") };+};++// Bundling is per FILM, not per session: the gate opens an adapter many times in one process and+// webpack has no business running again for a bundle that cannot have changed.+const bundles = new Map();+const bundleFor = async (film, bundle) => {+ if (!bundles.has(film)) {+ const dir = resolve(".tmp/remotion", film);+ mkdirSync(dir, { recursive: true });+ const entry = join(dir, "entry.tsx");+ // Three lines, generated. The COMPONENT lives in the repo where it can be read and reviewed;+ // only the static import of the one film is written out, and registerRoot is written in full+ // because Remotion reads the entry file looking for that exact call.+ writeFileSync(entry, [+ `import { registerRoot } from "remotion";`,+ `import { ${film} } from ${JSON.stringify(resolve("src/canvas-core", film))};`,+ `import { rootFor } from ${JSON.stringify(resolve("tools/adapters/remotion/canvas.tsx"))};`,+ `registerRoot(rootFor(${film}));`, ``,+ ].join("\n"));+ bundles.set(film, bundle({ entryPoint: entry, outDir: join(dir, "bundle"), onProgress: () => {} })); /* outDir keeps the build inside the project, not in the system temp */+ }+ return bundles.get(film);+};++export const open = async (film, opts = {}) => {+ const { scale = 1, workers = 1 } = opts;+ const p = probe();+ if (!p.ok) throw new Error(`remotion: ${p.why}`);+ const { bundle } = require("@remotion/bundler");+ const { getCompositions, renderStill, openBrowser } = require("@remotion/renderer");++ const data = await loadFilm(film);+ const serveUrl = await bundleFor(film, bundle);+ const comps = await getCompositions(serveUrl);+ const composition = comps.find((c) => c.id === data.meta.title);+ // The composition is not trusted to agree with the film: if Remotion is about to render a+ // different length or a different size, that is a silent wrong answer, so it is an error here.+ if (!composition) throw new Error(`remotion: the bundle has no composition '${data.meta.title}' (found: ${comps.map((c) => c.id).join(", ") || "none"})`);+ if (composition.durationInFrames !== data.meta.durationFrames) throw new Error(`remotion: composition is ${composition.durationInFrames} frames, the film is ${data.meta.durationFrames}`);+ if (composition.width !== data.meta.W || composition.height !== data.meta.H) throw new Error(`remotion: composition is ${composition.width}x${composition.height}, the film is ${data.meta.W}x${data.meta.H}`);++ // Independent browsers, so "two workers" means two genuinely separate instances rather than two+ // tabs sharing one process. Remotion gives each still its own page regardless, which is what+ // makes every frame here a cold draw.+ const browsers = [];+ for (let i = 0; i < Math.max(1, workers); i++) browsers.push(await openBrowser("chrome"));+ const pick = (w) => browsers[((w % browsers.length) + browsers.length) % browsers.length];+ const dir = resolve(".tmp/remotion", film);++ const still = async (n, w) => {+ const f = Math.max(0, Math.min(data.meta.durationFrames - 1, Math.round(n)));+ const file = join(dir, `f${f}-w${w % Math.max(1, workers)}.png`);+ const t0 = Date.now();+ await renderStill({ composition, serveUrl, output: file, frame: f, imageFormat: "png", scale, puppeteerInstance: pick(w), overwrite: true });+ if (!existsSync(file)) throw new Error(`remotion: renderStill wrote nothing for frame ${f}`);+ return { png: readFileSync(file), drawMs: Date.now() - t0 };+ };++ return {+ workers: browsers.length,+ info: () => data.meta,+ frame: async (n, w = 0) => { const r = await still(n, w); return { png: r.png, shot: (data.shots.find((s) => n >= s.start && n < s.end) ?? {}).id ?? null, drawMs: r.drawMs }; },+ // Hashed through the PNG the renderer wrote: that file IS what this backend produces, so+ // hashing anything else would be grading something the backend does not actually deliver.+ hash: async (n, w = 0) => createHash("sha256").update((await still(n, w)).png).digest("hex").slice(0, 16),+ audio: async (sr) => pcm16(data, sr),+ artifact: () => null, /* like playwright: a means to an MP4, not a deliverable of its own */+ close: async () => { for (const b of browsers) await b.close({ silent: true }); },+ };+};diff --git a/engine/tools/adapters/remotion/canvas.tsx b/engine/tools/adapters/remotion/canvas.tsxnew file mode 100644index 0000000..548c306--- /dev/null+++ b/engine/tools/adapters/remotion/canvas.tsx@@ -0,0 +1,75 @@+// THE REMOTION COMPONENT. The only React in the building that knows about the art core, and it+// knows exactly one thing: frame N goes on a canvas. `renderFrame(film, ctx, frame, env)` is the+// whole contract (canvas-core/film.ts), so Remotion is a HOST here, not a framework the art is+// written against. Nothing under src/canvas-core imports this file, or React, or remotion.+//+// Two details carry the determinism:+//+// delayRender Remotion screenshots the DOM when React has committed, which for us is too+// early: a committed <canvas> is a blank one until the effect runs. The frame is+// held open until the draw has finished, so what is captured is the drawing and+// never the empty element.+// useCurrentFrame is the ONLY input. There is no rAF loop, no clock and no state carried+// from the previous frame, which is what makes a Remotion render and a browser+// render of frame N the same pixels.+import React, { useCallback, useEffect, useRef, useState } from "react";+import { Composition, continueRender, delayRender, useCurrentFrame, useVideoConfig } from "remotion";+import type { Ctx, Env, Layer } from "../../../src/canvas-core/core";+import { Film, renderFrame, validate } from "../../../src/canvas-core/film";++// The host supplies offscreen surfaces; the core never makes one itself (core.ts, Env).+const surface = (w: number, h: number): Layer => {+ const c = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(w, h) : Object.assign(document.createElement("canvas"), { width: w, height: h });+ return { canvas: c, ctx: c.getContext("2d") as unknown as Ctx } as Layer;+};++export const FilmCanvas: React.FC<{ film: Film; scale?: number }> = ({ film, scale = 1 }) => {+ const frame = useCurrentFrame();+ const { width, height } = useVideoConfig();+ const ref = useRef<HTMLCanvasElement>(null);+ const envRef = useRef<Env | null>(null);+ const [handle] = useState(() => delayRender(`film "${film.meta.title}" frame ${frame}`));+ const done = useCallback(() => continueRender(handle), [handle]);++ useEffect(() => {+ const canvas = ref.current;+ if (!canvas) return;+ // One env per mounted component, so a Remotion render that walks frames in order gets the+ // same warm-cache path a browser does. Every cache key names its own inputs (surface.ts),+ // so warm and cold must agree; if they ever stop agreeing the gate says so.+ if (!envRef.current) {+ const problems = validate(film);+ if (problems.length) throw new Error("timeline: " + problems.join("; "));+ envRef.current = { W: film.meta.W, H: film.meta.H, scale, cache: new Map(), canvas: surface, image: () => undefined };+ }+ const ctx = canvas.getContext("2d") as Ctx;+ renderFrame(film, ctx, frame, envRef.current);+ ctx.getImageData(0, 0, 1, 1); /* force the deferred raster before the screenshot is taken */+ done();+ }, [frame, film, scale, done]);++ return <canvas ref={ref} width={Math.round(width * scale)} height={Math.round(height * scale)} style={{ width, height, display: "block" }} />;+};++// A whole Remotion root for one film: the composition's id IS the film's title, and its+// dimensions and length come from the film's own meta rather than being restated here.+//+// The film is CLOSED OVER, never passed as defaultProps. A Film carries functions (every shot's+// draw, and the score), and Remotion serializes props: handing it the film would ask it to JSON+// a function. The entry file is generated per film, so closing over one is free.+export const rootFor = (film: Film, scale = 1): React.FC => {+ const One: React.FC = () => <FilmCanvas film={film} scale={scale} />;+ return () => (+ <Composition+ id={film.meta.title}+ component={One}+ durationInFrames={film.meta.durationFrames}+ fps={film.meta.fps}+ width={film.meta.W}+ height={film.meta.H}+ />+ );+};++// registerRoot() is deliberately NOT called here. Remotion reads the ENTRY FILE looking for it,+// and an entry that hides the call behind a helper is an entry that fails to bundle.diff --git a/engine/tools/build-page.mjs b/engine/tools/build-page.mjsnew file mode 100644index 0000000..0ca66c3--- /dev/null+++ b/engine/tools/build-page.mjs@@ -0,0 +1,20 @@+// Build ONE self-contained HTML file: the art core + film, bundled, with every asset in the+// manifest inlined as a data URI. No network, no server, no sibling files.+import { build } from "esbuild";+import { readFileSync, writeFileSync, mkdirSync } from "node:fs";+import { extname, join } from "node:path";++const MIME = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp", ".woff2": "font/woff2" };+export const buildPage = async ({ entry, out, title, plugins = [] }) => {+ const js = (await build({ entryPoints: [entry], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", plugins })).outputFiles[0].text;+ // read the manifest out of the film module itself, so the page and the film can never disagree+ const probe = (await build({ stdin: { contents: `export { ${title} as film } from "./src/canvas-core/${title}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins })).outputFiles[0].text;+ const { film } = await import("data:text/javascript;base64," + Buffer.from(probe).toString("base64"));+ const assets = Object.fromEntries(Object.entries(film.assets.images).map(([name, file]) => { const mime = MIME[extname(file).toLowerCase()]; if (!mime) throw new Error(`asset '${name}': unsupported type ${file}`); return [name, `data:${mime};base64,${readFileSync(join(process.cwd(), file)).toString("base64")}`]; }));+ const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${film.meta.title}</title>+<style>html,body{margin:0;height:100%;background:#1b1a1a;display:grid;place-items:center}canvas{max-width:100vw;max-height:100vh;aspect-ratio:${film.meta.W}/${film.meta.H};cursor:pointer;background:#fff}</style></head>+<body><canvas id="film"></canvas><script>window.__ASSETS__=${JSON.stringify(assets)};</script><script>${js.replace(/<\/script/g, "<\\/script")}</script></body></html>`;+ mkdirSync(join(out, ".."), { recursive: true }); writeFileSync(out, html);+ return { out, bytes: html.length, meta: film.meta };+};+if (import.meta.url === `file://${process.argv[1]}`) { const title = process.argv[2] ?? "fixtures"; const r = await buildPage({ entry: `src/hosts/page-${title}.ts`, out: `dist/${title}.html`, title }); console.log(`built ${r.out} (${(r.bytes / 1024).toFixed(0)} KB, self-contained)`); }diff --git a/engine/tools/deadair.mjs b/engine/tools/deadair.mjsnew file mode 100644index 0000000..b4538b3--- /dev/null+++ b/engine/tools/deadair.mjs@@ -0,0 +1,44 @@+// node tools/deadair.mjs <film|path.mp4> [--win 15] [--min 0.5] [--exempt a:b]+// GATE G-AIR. Decodes the rendered MP4 and measures, per frame, the fraction of pixels that+// changed since the previous frame. Two identical frames anywhere, or any window of `win`+// frames whose changed area never reaches `min` percent, is dead air and fails.+import { execFileSync, spawnSync } from "node:child_process";+import { existsSync } from "node:fs";+import { resolve } from "node:path";++const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; };+const a0 = process.argv[2];+if (!a0) { console.error("usage: node tools/deadair.mjs <film|path.mp4> [--win 15] [--min 0.5] [--exempt 525:540]"); process.exit(2); }+const file = resolve(a0.endsWith(".mp4") ? a0 : `out/${a0}.mp4`);+if (!existsSync(file)) { console.error(`no such file: ${file}`); process.exit(2); }+const WIN = Number(arg("win", 15)), MIN = Number(arg("min", 0.5)) / 100, THRESH = Number(arg("thresh", 4)), SIZE = Number(arg("size", 270));+const exempt = (arg("exempt", "") || "").split(",").filter(Boolean).map((s) => s.split(":").map(Number));++// decode small: 135x135 grey is plenty to see whether anything moved, and it keeps this honest+const W = SIZE, H = SIZE, px = W * H;+const out = spawnSync("ffmpeg", ["-v", "error", "-i", file, "-vf", `scale=${W}:${H}`, "-pix_fmt", "gray", "-f", "rawvideo", "-"], { maxBuffer: 1 << 30 });+if (out.status) { console.error(out.stderr.toString()); process.exit(2); }+const buf = out.stdout, n = Math.floor(buf.length / px);+const probe = execFileSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=nb_frames,duration", "-of", "csv=p=0", file]).toString().trim();+console.log(`${file}\n ${n} frames decoded at ${W}x${H} grey, threshold ${THRESH}/255 (${probe})`);++const changed = [0];+for (let f = 1; f < n; f++) {+ const a = buf.subarray((f - 1) * px, f * px), b = buf.subarray(f * px, (f + 1) * px);+ let c = 0; for (let i = 0; i < px; i++) if (Math.abs(a[i] - b[i]) > THRESH) c++;+ changed.push(c / px);+}+const inExempt = (f) => exempt.some(([a, b]) => f >= a && f < b);+const still = [], windows = [];+for (let f = 1; f < n; f++) if (changed[f] === 0 && !inExempt(f)) still.push(f);+for (let f = 1; f + WIN <= n; f++) { let m = 0; for (let k = f; k < f + WIN; k++) m = Math.max(m, changed[k]); if (m < MIN && !inExempt(f)) windows.push([f, f + WIN, m]); }+const merged = []; windows.forEach(([a, b, m]) => { const last = merged[merged.length - 1]; if (last && a <= last[1]) { last[1] = Math.max(last[1], b); last[2] = Math.max(last[2], m); } else merged.push([a, b, m]); });++const stat = (xs) => { const s = [...xs].sort((x, y) => x - y); return { med: s[s.length >> 1], min: s[0], max: s[s.length - 1] }; };+const st = stat(changed.slice(1));+console.log(` changed area per frame: median ${(st.med * 100).toFixed(2)}% min ${(st.min * 100).toFixed(2)}% max ${(st.max * 100).toFixed(2)}%`);+if (still.length) console.log(` FAIL: ${still.length} frame(s) identical to the one before: ${still.slice(0, 12).join(", ")}${still.length > 12 ? " ..." : ""}`);+if (merged.length) merged.forEach(([a, b, m]) => console.log(` FAIL: frames ${a}-${b} never exceed ${(m * 100).toFixed(2)}% changed area (floor ${(MIN * 100).toFixed(1)}%)`));+const ok = !still.length && !merged.length;+console.log(ok ? " G-AIR: PASS" : " G-AIR: FAIL");+process.exit(ok ? 0 : 1);diff --git a/engine/tools/detect.mjs b/engine/tools/detect.mjsnew file mode 100644index 0000000..884a14e--- /dev/null+++ b/engine/tools/detect.mjs@@ -0,0 +1,60 @@+// Find a render backend WITHOUT installing anything. Reports exactly what it found and why it+// chose it. A backend is usable only if its library AND a browser binary AND ffmpeg all exist.+import { execFileSync } from "node:child_process";+import { existsSync, readdirSync } from "node:fs";+import { createRequire } from "node:module";+import { homedir } from "node:os";+import { join } from "node:path";++const require = createRequire(import.meta.url);+const tryRequire = (id, from) => { try { return createRequire(from)(id); } catch { return null; } };+const globalRoot = () => { try { return execFileSync("npm", ["root", "-g"], { stdio: ["ignore", "pipe", "ignore"] }).toString().trim(); } catch { return null; } };++export const findFfmpeg = () => { const bin = process.env.FFMPEG || "ffmpeg"; try { const v = execFileSync(bin, ["-version"], { stdio: ["ignore", "pipe", "ignore"] }).toString().split("\n")[0]; return { ok: true, bin, why: v }; } catch { return { ok: false, why: "ffmpeg not on PATH (set FFMPEG=/path/to/ffmpeg)" }; } };++export const findPlaywright = () => {+ const here = join(process.cwd(), "package.json"), g = globalRoot(), tried = [];+ const candidates = [["playwright", here], ["playwright-core", here], ...(g ? [["playwright", join(g, "x.js")], ["playwright-core", join(g, "x.js")], ["playwright-core", join(g, "@playwright/mcp/package.json")], ["playwright-core", join(g, "agent-browser/package.json")]] : [])];+ for (const [id, from] of candidates) { const lib = tryRequire(id, from); tried.push(`${id} from ${from}`); if (lib?.chromium) { const version = tryRequire(`${id}/package.json`, from)?.version; return { ok: true, lib, id, from, version }; } }+ return { ok: false, why: `no playwright found (looked in: ${tried.join("; ")})` };+};+// Prefer the browser playwright expects; otherwise the newest cached headless shell or chromium.+export const findBrowser = (lib) => {+ try { const p = lib.chromium.executablePath(); if (p && existsSync(p)) return { ok: true, executablePath: undefined, why: `playwright default: ${p}` }; } catch { /* fall through */ }+ const cache = process.env.PLAYWRIGHT_BROWSERS_PATH || join(homedir(), process.platform === "darwin" ? "Library/Caches/ms-playwright" : ".cache/ms-playwright");+ if (!existsSync(cache)) {+ const local = remotionShell();+ return local ? { ok: true, executablePath: local, why: `remotion's own chrome-headless-shell in node_modules (no playwright cache at ${cache})` } : { ok: false, why: `no browser cache at ${cache}, and none in node_modules/.remotion` };+ }+ const dirs = readdirSync(cache).filter((d) => /^chromium(_headless_shell)?-\d+$/.test(d)).sort((a, b) => Number(b.split("-")[1]) - Number(a.split("-")[1]) || (a.includes("headless") ? -1 : 1));+ for (const d of dirs) { const stack = [join(cache, d)]; while (stack.length) { const dir = stack.pop(); for (const e of readdirSync(dir, { withFileTypes: true })) { const f = join(dir, e.name); if (e.isDirectory() && !e.name.endsWith(".app") ? true : false) stack.push(f); else if (e.isDirectory()) stack.push(f); else if (/^(chrome-headless-shell|chrome|Chromium)$/.test(e.name)) return { ok: true, executablePath: f, why: `cached ${d} (playwright's own revision is not installed)` }; } } }+ const local = remotionShell();+ if (local) return { ok: true, executablePath: local, why: `remotion's own chrome-headless-shell in node_modules (no playwright cache at ${cache})` };+ return { ok: false, why: `no chromium build in ${cache}, and none in node_modules/.remotion` };+};+// Remotion keeps a chrome-headless-shell INSIDE the project. It is a real Chromium and it is+// already on disk, so when the playwright cache is missing there is no reason to download a+// second one. Worth knowing: it is a different build from playwright's, so pixels hashed against+// it are comparable within a run but not necessarily to hashes taken on another machine's shell.+const remotionShell = () => {+ const root = join(process.cwd(), "node_modules/.remotion/chrome-headless-shell");+ if (!existsSync(root)) return null;+ const stack = [root];+ while (stack.length) {+ const dir = stack.pop();+ for (const e of readdirSync(dir, { withFileTypes: true })) {+ const f = join(dir, e.name);+ if (e.isDirectory()) stack.push(f);+ else if (e.name === "chrome-headless-shell") return f;+ }+ }+ return null;+};+export const findRemotion = () => { const v = tryRequire("remotion/package.json", join(process.cwd(), "package.json"))?.version; return v ? { ok: true, version: v } : { ok: false, why: "remotion is not a dependency of this project" }; };++export const detect = () => {+ const ffmpeg = findFfmpeg(), pw = findPlaywright(), browser = pw.ok ? findBrowser(pw.lib) : { ok: false, why: "needs playwright" }, remotion = findRemotion();+ const report = { ffmpeg: ffmpeg.ok ? ffmpeg.why : `MISSING: ${ffmpeg.why}`, playwright: pw.ok ? `${pw.id}@${pw.version} (${pw.from})` : `MISSING: ${pw.why}`, browser: browser.ok ? browser.why : `MISSING: ${browser.why}`, remotion: remotion.ok ? `remotion@${remotion.version} (adapter lands in Phase 3)` : remotion.why, hyperframes: "not probed (Phase 5, by decision)" };+ const chosen = pw.ok && browser.ok && ffmpeg.ok ? "playwright" : null;+ return { chosen, report, ffmpeg, pw, browser };+};diff --git a/engine/tools/emit.mjs b/engine/tools/emit.mjsnew file mode 100644index 0000000..53bebad--- /dev/null+++ b/engine/tools/emit.mjs@@ -0,0 +1,94 @@+// EMIT. Ship the film as ONE self-contained HTML file, to a path with the film's own name on it,+// and then prove that the file on disk is the film that passed the gate.+//+// node tools/emit.mjs <film> [--out out/mechanical-lepidoptera.html] [--frames 24]+//+// The gate builds its page into dist/ as a means to an end: it needs something to drive. This is+// the end. The deliverable sits next to the MP4, named the same way, so the two cannot drift apart+// in a folder six months from now.+//+// Verification is deliberately done on the EMITTED file and not on the build that made it:+// 1 STATIC the adapter's own ship-worthiness checks, imported rather than copied, so the+// emitted page is held to exactly the bar the gate holds the dist page to.+// 2 OFFLINE loaded from file://, with every request that is not file: or data: treated as a+// failure. Reading the source proves it asks for nothing; this proves it takes+// nothing when it runs.+// 3 SAME FILM the emitted page is asked for N frames spread across the whole film and its own+// hashes are compared against the dist page the gate measured. Equal hashes mean+// the thing being shipped is the thing that was approved, not a rebuild of it.+import { readFileSync, statSync } from "node:fs";+import { resolve } from "node:path";+import { pathToFileURL } from "node:url";+import { buildPage } from "./build-page.mjs";+import { pageChecks, probe } from "./adapters/html-player.mjs";++const VAL = new Set(["out", "frames", "scale"]);+const pos = [], opt = {};+for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }+const die = (m) => { console.error(`emit: ${m}`); process.exit(1); };+const film = pos[0] ?? die("usage: node tools/emit.mjs <film> [--out out/x.html] [--frames 24]");+const kebab = film.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();+const out = resolve(opt.out ?? `out/${kebab}.html`);+const N = Math.max(4, +(opt.frames ?? 24)), SCALE = +(opt.scale ?? 1);++let fails = 0, checks = 0;+const say = (ok, label, detail = "") => { checks++; if (!ok) fails++; console.log(` ${ok ? "PASS" : "FAIL"} ${label}${detail ? " " + detail : ""}`); };+const head = (n, t) => console.log(`\n${n}. ${t}\n${"-".repeat(58)}`);++const p = probe();+if (!p.ok) die(p.why);++// ---------------------------------------------------------------- emit+const ship = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });+const dist = resolve(`dist/${film}.html`);+await buildPage({ entry: `src/hosts/page-${film}.ts`, out: dist, title: film }); /* the gate's page, to compare the shipped one against */+const DUR = ship.meta.durationFrames;+if (!Number.isInteger(DUR) || DUR < 2) die(`the film reports no usable length (durationFrames = ${DUR}): nothing below could be trusted`);+console.log(`EMIT "${ship.meta.title}" ${ship.meta.W}x${ship.meta.H} ${DUR} frames @ ${ship.meta.fps}fps`);+console.log(` ${out} (${(ship.bytes / 1024).toFixed(0)} KB, self-contained)`);++// ---------------------------------------------------------------- 1. static+head(1, "SHIP-WORTHY the file reaches outside itself for nothing");+const html = readFileSync(out, "utf8");+pageChecks(html).forEach((c) => say(c.ok, c.label, c.detail));+say(statSync(out).size === ship.bytes, "the file on disk is the file that was built", `${statSync(out).size} bytes`);++// ---------------------------------------------------------------- 2 & 3. run it+const browser = await p.env.pw.lib.chromium.launch({ executablePath: p.env.browser.executablePath, args: ["--disable-background-timer-throttling"] });+const context = await browser.newContext({ viewport: { width: 640, height: 640 }, deviceScaleFactor: 1 });+const openPage = async (file) => {+ const page = await context.newPage(), errors = [], reached = [];+ page.on("pageerror", (e) => errors.push(e.message));+ page.on("requestfailed", (r) => errors.push(`request failed: ${r.url()}`));+ page.on("request", (r) => { const u = r.url(); if (!u.startsWith("file:") && !u.startsWith("data:") && !u.startsWith("blob:")) reached.push(u); });+ await page.goto(pathToFileURL(file).href);+ await page.evaluate(async (s) => { await window.FILM.ready; window.FILM.mount(s); window.FILM.warm(); }, SCALE);+ return { page, errors, reached };+};++const shipped = await openPage(out);+head(2, "OFFLINE it does not just ASK for nothing, it TAKES nothing");+say(shipped.errors.length === 0, "the page runs clean, start to warm", shipped.errors.slice(0, 3).join("; ") || "no page error");+say(shipped.reached.length === 0, "nothing outside file: or data: was requested", shipped.reached.slice(0, 3).join("; ") || "0 outside requests");+const meta = await shipped.page.evaluate(() => window.FILM.meta);+say(meta.durationFrames === DUR && meta.fps === ship.meta.fps, "the running page reports the film it was built from", `${meta.durationFrames} frames @ ${meta.fps}fps`);++head(3, "SAME FILM the shipped page draws what the gate measured");+const golden = await openPage(dist);+if (golden.errors.length) die(`the dist page the gate measured will not run: ${golden.errors.join("; ")}`);+const frames = Array.from({ length: N }, (_, i) => Math.round((i / (N - 1)) * (DUR - 1)));+if (frames.some((f) => !Number.isInteger(f))) die(`refusing to compare frames ${frames.join(", ")}: a frame list that is not whole numbers passes by accident, it does not pass`);+const hashOf = async (h, f) => h.page.evaluate((n) => { window.FILM.seek(n); return window.FILM.hash(); }, f);+const bad = [], seen = new Set();+for (const f of frames) { const a = await hashOf(shipped, f), b = await hashOf(golden, f); if (typeof a !== "string" || !a) die(`frame ${f} produced no hash`); seen.add(a); if (a !== b) bad.push(f); }+say(seen.size > 1, "the sampled frames are genuinely different frames", `${seen.size} distinct hashes across ${frames.length} samples`); /* equal hashes prove nothing if every sample drew the same frame */+say(bad.length === 0, `${frames.length} frames across the film hash the same as the gate's page`, bad.length ? `differ at ${bad.join(", ")}` : `frames ${frames[0]}..${frames[frames.length - 1]}`);++const sr = 48000;+const [aShip, aGold] = [await shipped.page.evaluate((s) => window.FILM.audio(s), sr), await golden.page.evaluate((s) => window.FILM.audio(s), sr)];+const sameAudio = aShip && aGold && aShip.frames === aGold.frames && aShip.sampleRate === aGold.sampleRate;+say(!!sameAudio, "the page synthesizes the same score, in the page", sameAudio ? `${aShip.frames} samples @ ${aShip.sampleRate} Hz` : "audio missing or different");++await browser.close();+console.log(`\n${"=".repeat(58)}\nEMIT: ${fails ? `FAIL ${fails} of ${checks} checks failed` : `PASS ${checks}/${checks} checks`} ${out}`);+process.exit(fails ? 1 : 0);diff --git a/engine/tools/gate.mjs b/engine/tools/gate.mjsnew file mode 100644index 0000000..f327de9--- /dev/null+++ b/engine/tools/gate.mjs@@ -0,0 +1,152 @@+// THE QUALITY GATE. One gate, any adapter. It holds whatever backend it is handed to the same+// three bars and prints a verdict you can act on.+//+// node tools/gate.mjs <film> [--adapter html-player] [--mp4 out/x.mp4] [--samples 12] [--scale 1]+//+// 1 DETERMINISM the same sampled frames drawn twice, at two different worker counts, in two+// different orders. Byte-identical, or PSNR above 45 dB.+// 2 CONTRACT a static scan of every module the film draws through.+// 3 DEAD AIR no identical consecutive frames, no 15-frame window under 0.5 % changed.+//+// The gate NEVER writes to out/. It renders into .tmp/gate/ and it only ever READS the MP4 it is+// pointed at, so running it can never damage a finished film.+import { execFileSync, spawnSync } from "node:child_process";+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { resolve } from "node:path";++const VAL = new Set(["adapter", "mp4", "samples", "scale", "workers"]);+const pos = [], opt = {};+for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }+const film = pos[0] ?? "mechanicalLepidoptera";+const adapterName = opt.adapter ?? "html-player";+const SAMPLES = Math.max(4, +(opt.samples ?? 12)), SCALE = +(opt.scale ?? 1);+const TMP = resolve(".tmp/gate"); mkdirSync(TMP, { recursive: true });++let fails = 0, checks = 0;+const say = (ok, label, detail = "") => { checks++; if (!ok) fails++; console.log(` ${ok ? "PASS" : "FAIL"} ${label}${detail ? " " + detail : ""}`); };+const head = (n, t) => console.log(`\n${n}. ${t}\n${"-".repeat(58)}`);++// ---------------------------------------------------------------- 2. the contract, statically+// Deliberately first in the file and cheap: if the source can reach a clock or the network, no+// amount of agreeing renders proves anything, because the next machine may not agree.+const FORBIDDEN = [+ [/Math\.random/, "Math.random"], [/\bnew Date\b/, "new Date"], [/\bDate\.now\b/, "Date.now"],+ [/performance\.now/, "performance.now"], [/\bctx\.filter\b/, "ctx.filter"], [/\.filter\s*=[^=]/, "assignment to .filter"],+ [/\bnew Image\b/, "new Image"], [/\bnew OffscreenCanvas\b/, "new OffscreenCanvas"],+ [/\bfetch\s*\(/, "fetch()"], [/XMLHttpRequest/, "XMLHttpRequest"], [/\bimportScripts\b/, "importScripts"],+ [/\blocalStorage\b/, "localStorage"], [/\bcrypto\./, "crypto.*"],+ [/from\s+["']react["']/, "react import"], [/from\s+["']remotion["']/, "remotion import"], [/pencil\.tsx/, "pencil.tsx import"],+];+const stripComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");+const walk = (dir, out = []) => { for (const e of execFileSync("find", [dir, "-name", "*.ts", "-type", "f"]).toString().trim().split("\n").filter(Boolean)) out.push(e); return out; };++const contractScan = () => {+ head(2, "CONTRACT the art core cannot reach a clock, the network or a file");+ const files = [...walk("src/canvas-core"), `src/hosts/page-${film}.ts`].filter((f) => existsSync(f));+ const hits = [];+ for (const f of files) { const src = stripComments(readFileSync(f, "utf8")); FORBIDDEN.forEach(([re, label]) => { const m = src.match(new RegExp(re.source, "g")); if (m) hits.push(`${f}: ${label} x${m.length}`); }); }+ say(hits.length === 0, `no forbidden call in ${files.length} art-core modules`, hits.length ? hits.slice(0, 6).join(" | ") : "Math.random, Date, performance.now, ctx.filter, network, image/font loads: none");+ const rngSites = files.reduce((a, f) => a + (stripComments(readFileSync(f, "utf8")).match(/\brng\s*\(/g) ?? []).length, 0);+ const badSeed = files.flatMap((f) => (stripComments(readFileSync(f, "utf8")).match(/rng\s*\(\s*(Date|Math|performance)/g) ?? []));+ say(badSeed.length === 0 && rngSites > 0, `all randomness is rng(seed): ${rngSites} seeded call sites`, badSeed.length ? `UNSEEDED: ${badSeed.join(", ")}` : "no seed derived from a clock or Math.random");+ return files.length;+};++// ---------------------------------------------------------------- 3. dead air, on a real file+const deadAir = (mp4) => {+ head(3, "DEAD AIR something visibly moves in every second");+ if (!existsSync(mp4)) { say(false, "an MP4 to measure", `${mp4} not found`); return; }+ const W = 270, px = W * W;+ const grey = spawnSync("ffmpeg", ["-v", "error", "-i", mp4, "-vf", `scale=${W}:${W}`, "-pix_fmt", "gray", "-f", "rawvideo", "-"], { maxBuffer: 1 << 30 }).stdout;+ const n = Math.floor(grey.length / px), changed = [0];+ for (let f = 1; f < n; f++) { const A = grey.subarray((f - 1) * px, f * px), B = grey.subarray(f * px, (f + 1) * px); let c = 0; for (let i = 0; i < px; i++) if (Math.abs(A[i] - B[i]) > 4) c++; changed.push(c / px); }+ const still = []; for (let f = 1; f < n; f++) if (changed[f] === 0) still.push(f);+ const win = []; for (let f = 1; f + 15 <= n; f++) { let m = 0; for (let k = f; k < f + 15; k++) m = Math.max(m, changed[k]); if (m < 0.005) win.push(f); }+ const merged = []; win.forEach((f) => { const l = merged[merged.length - 1]; if (l && f <= l[1]) l[1] = f + 15; else merged.push([f, f + 15]); });+ // A film may LOCK an early act that is known to fail here. Report it, never launder it.+ const A1 = 540, lateStill = still.filter((f) => f >= A1), lateWin = merged.filter(([a]) => a >= A1);+ say(lateStill.length === 0, "no identical consecutive frames after the locked act", `${lateStill.length} after frame ${A1}, ${still.length} in the whole file`);+ say(lateWin.length === 0, "no 15-frame window under 0.5% changed after the locked act", lateWin.map(([a, b]) => `${a}-${b}`).join(", ") || "none");+ const mvt = changed.slice(A1 + 1).sort((a, b) => a - b);+ console.log(` ${n} frames measured; after frame ${A1}: median ${(mvt[mvt.length >> 1] * 100).toFixed(2)}% min ${(mvt[0] * 100).toFixed(2)}%`);+ if (still.length) console.log(` NOTE: ${still.length} still frames all sit inside the LOCKED Act 1 (locked by decision). Not counted against this gate.`);+};++// ---------------------------------------------------------------- 1. determinism, two ways round+const psnr = (a, b) => {+ const r = spawnSync("ffmpeg", ["-v", "error", "-i", a, "-i", b, "-lavfi", "psnr=stats_file=-", "-f", "null", "-"], { encoding: "utf8" });+ const m = (r.stdout + r.stderr).match(/psnr_avg:([0-9.]+|inf)/);+ return m ? (m[1] === "inf" ? Infinity : Number(m[1])) : NaN;+};++const run = async () => {+ console.log(`QUALITY GATE film "${film}" adapter "${adapterName}"`);+ const mod = await import(`./adapters/${adapterName}.mjs`);+ const p = mod.probe();+ console.log(`${mod.describe()}\n${p.ok ? "ready: " + p.why : "UNAVAILABLE: " + p.why}`);+ if (!p.ok) { console.log("\nGATE: CANNOT RUN"); process.exit(2); }++ head(1, "DETERMINISM the same frame, drawn two different ways, is the same frame");+ const s1 = await mod.open(film, { scale: SCALE, workers: 1 });+ const meta = await s1.info();+ const N = meta.durationFrames;+ const frames = Array.from({ length: SAMPLES }, (_, i) => Math.round((i * (N - 1)) / (SAMPLES - 1)));+ const h1 = []; for (const f of frames) h1.push(await s1.hash(f, 0)); // forward, one page+ const art = s1.artifact?.() ?? null;+ const aud1 = await s1.audio(48000);+ await s1.close();++ const W2 = 3;+ const s2 = await mod.open(film, { scale: SCALE, workers: W2 });+ const h2 = new Array(frames.length);+ for (let i = frames.length - 1; i >= 0; i--) h2[i] = await s2.hash(frames[i], i); // reversed, spread over 3 pages+ const aud2 = await s2.audio(48000);++ const same = frames.filter((_, i) => h1[i] === h2[i]).length;+ say(same === frames.length, `${frames.length} sampled frames hash-identical across 1 page and ${W2} pages, forward vs reversed`, `${same}/${frames.length} frames ${frames[0]}..${frames[frames.length - 1]}`);+ if (same !== frames.length) { // only pay for pixels when the hashes disagree+ let worst = Infinity;+ for (let i = 0; i < frames.length; i++) {+ if (h1[i] === h2[i]) continue;+ const a = resolve(TMP, `a${frames[i]}.png`), b = resolve(TMP, `b${frames[i]}.png`);+ const sA = await mod.open(film, { scale: SCALE, workers: 1 });+ writeFileSync(a, (await sA.frame(frames[i], 0)).png); await sA.close();+ writeFileSync(b, (await s2.frame(frames[i], i)).png);+ const v = psnr(a, b); worst = Math.min(worst, v);+ console.log(` frame ${frames[i]}: PSNR ${v === Infinity ? "inf" : v.toFixed(2)} dB`);+ }+ say(worst > 45, `every differing frame is visually identical (PSNR > 45 dB)`, `min PSNR ${worst === Infinity ? "inf" : worst.toFixed(2)} dB`);+ // A failure is only useful if it says WHERE to look. Redraw the first offender cold, then+ // again behind each earlier sample, and name the frame that poisons it: that is the signature+ // of a cache key that does not name everything its pixels depend on.+ const bad = frames.find((_, i) => h1[i] !== h2[i]);+ if (bad !== undefined) {+ const c0 = await mod.open(film, { scale: SCALE, workers: 1 }); const cold = await c0.hash(bad, 0); await c0.close();+ const culprits = [];+ for (const pre of frames.filter((f) => f !== bad)) {+ const c = await mod.open(film, { scale: SCALE, workers: 1 });+ await c.hash(pre, 0); const h = await c.hash(bad, 0); await c.close();+ if (h !== cold) culprits.push(pre);+ }+ console.log(culprits.length+ ? ` DIAGNOSIS: frame ${bad} is ORDER-DEPENDENT. Drawing frame(s) ${culprits.join(", ")} first changes it.\n That is a cache key that does not name everything its pixels depend on.`+ : ` DIAGNOSIS: frame ${bad} is stable within a session; the difference is between sessions.`);+ }+ }+ say(aud1 && aud2 ? aud1.pcm16 === aud2.pcm16 : false, "the synthesized audio is identical across sessions", aud1 ? `${aud1.frames} samples @ ${aud1.sampleRate} Hz` : "no audio");+ await s2.close();++ const nFiles = contractScan();+ deadAir(resolve(opt.mp4 ?? `out/${film.replace(/([A-Z])/g, "-$1").toLowerCase()}.mp4`));++ if (art) {+ head(4, `ARTIFACT what this adapter delivers`);+ console.log(` ${art.path} (${(art.bytes / 1024).toFixed(0)} KB, ${art.kind})`);+ art.checks.forEach((c) => say(c.ok, c.label, c.detail));+ }++ console.log(`\n${"=".repeat(58)}`);+ console.log(fails ? `GATE: FAIL ${fails} of ${checks} checks failed` : `GATE: PASS ${checks}/${checks} checks, ${nFiles} modules scanned`);+ process.exit(fails ? 1 : 0);+};+run().catch((e) => { console.error(`\ngate crashed: ${e.message}`); process.exit(2); });diff --git a/engine/tools/render.mjs b/engine/tools/render.mjsnew file mode 100644index 0000000..5933d51--- /dev/null+++ b/engine/tools/render.mjs@@ -0,0 +1,55 @@+// node tools/render.mjs [film] [--scale 1] [--workers 4] [--out out/x.mp4]+// Auto-detects a backend, renders every frame through it, encodes with ffmpeg, then VERIFIES.+import { spawn, execFileSync } from "node:child_process";+import { mkdirSync, writeFileSync } from "node:fs";+import { cpus } from "node:os";+import { join, resolve } from "node:path";+import { buildPage } from "./build-page.mjs";+import { detect } from "./detect.mjs";+import * as playwright from "./adapters/playwright.mjs";++const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; };+const film = process.argv[2] && !process.argv[2].startsWith("--") ? process.argv[2] : "fixtures";+const scale = Number(arg("scale", 1)), workers = Number(arg("workers", Math.max(1, Math.min(4, Math.floor(cpus().length / 2))))), out = resolve(arg("out", `out/${film}.mp4`));++const env = detect();+console.log("backends found:"); for (const [k, v] of Object.entries(env.report)) console.log(` ${k.padEnd(11)} ${v}`);+if (!env.chosen) { console.error("\nno usable render backend. The HTML player still works: node tools/build-page.mjs"); process.exit(2); }+console.log(`using: ${env.chosen}\n`);++const page = await buildPage({ entry: `src/hosts/page-${film}.ts`, out: resolve(`dist/${film}.html`), title: film });+console.log(`page: ${page.out} (${(page.bytes / 1024).toFixed(0)} KB)`);+const t0 = Date.now(), session = await playwright.open(env, page.out, { scale, workers }), meta = await session.info(), N = meta.durationFrames;+console.log(`film: "${meta.title}" ${meta.W}x${meta.H} @ ${meta.fps} fps, ${N} frames, ${meta.bpm} bpm, scale ${scale}, ${session.workers} page(s)`);++// audio: pure JS in the page -> WAV here+mkdirSync(resolve(".tmp"), { recursive: true }); const wav = resolve(`.tmp/${film}.wav`), a = await session.audio(48000);+if (a) { const pcm = Buffer.from(a.pcm16, "base64"), h = Buffer.alloc(44); h.write("RIFF", 0); h.writeUInt32LE(36 + pcm.length, 4); h.write("WAVEfmt ", 8); h.writeUInt32LE(16, 16); h.writeUInt16LE(1, 20); h.writeUInt16LE(2, 22); h.writeUInt32LE(a.sampleRate, 24); h.writeUInt32LE(a.sampleRate * 4, 28); h.writeUInt16LE(4, 32); h.writeUInt16LE(16, 34); h.write("data", 36); h.writeUInt32LE(pcm.length, 40); writeFileSync(wav, Buffer.concat([h, pcm])); }++mkdirSync(join(out, ".."), { recursive: true });+const ff = spawn(env.ffmpeg.bin, ["-y", "-loglevel", "error", "-f", "image2pipe", "-framerate", String(meta.fps), "-c:v", "png", "-i", "-", ...(a ? ["-i", wav] : []), "-c:v", "libx264", "-pix_fmt", "yuv420p", "-crf", "16", "-preset", "medium", ...(a ? ["-c:a", "aac", "-b:a", "192k", "-shortest"] : []), "-movflags", "+faststart", out], { stdio: ["pipe", "inherit", "inherit"] });+const done = new Promise((res, rej) => ff.on("close", (c) => (c ? rej(new Error(`ffmpeg exited ${c}`)) : res())));++// frames render in parallel across pages, and are fed to ffmpeg strictly in order+const cost = [], pending = new Map(); let next = 0, write = 0;+const pump = async () => { while (pending.has(write)) { const b = pending.get(write); pending.delete(write); if (!ff.stdin.write(b)) await new Promise((r) => ff.stdin.once("drain", r)); write++; } };+await Promise.all(Array.from({ length: session.workers }, async (_, w) => { while (next < N) { const n = next++; while (n - write > session.workers * 3) await new Promise((r) => setTimeout(r, 5)); const f = await session.frame(n, w); cost.push({ n, shot: f.shot, draw: f.drawMs, enc: f.encodeMs, rt: f.roundTripMs }); pending.set(n, f.png); await pump(); } }));+await pump(); ff.stdin.end(); await done;+const wall = (Date.now() - t0) / 1000;++// ---- frame cost+const stat = (xs) => { const s = [...xs].sort((a, b) => a - b); return { med: s[s.length >> 1], p95: s[Math.floor(s.length * 0.95)], max: s[s.length - 1] }; };+console.log("\nframe cost (ms), draw = art core only, png = canvas PNG encode in page:");+for (const id of [...new Set(cost.map((c) => c.shot))]) { const c = cost.filter((x) => x.shot === id), d = stat(c.map((x) => x.draw)), e = stat(c.map((x) => x.enc)); console.log(` ${id.padEnd(12)} draw median ${d.med.toFixed(0)} p95 ${d.p95.toFixed(0)} max ${d.max.toFixed(0)} | png median ${e.med.toFixed(0)} (${c.length} frames)`); }+const slow = [...cost].sort((a, b) => b.draw - a.draw).slice(0, 3).map((c) => `#${c.n} ${c.shot} ${c.draw.toFixed(0)}ms`).join(", ");+console.log(` slowest: ${slow}\n budget: 150 ms draw per frame -> ${cost.every((c) => c.draw <= 150) ? "PASS" : "OVER on " + cost.filter((c) => c.draw > 150).length + " frames"}`);+console.log(` wall clock: ${wall.toFixed(1)} s for ${N} frames = ${(N / wall).toFixed(1)} fps end to end (build + launch + render + encode)`);++// ---- verify: same frame, different order, different page. Standard = visually identical; hash equality is the cheap first test.+const probe = [0, 44, 45, 89, 90, N - 1].filter((n) => n < N), fwd = [], rev = [];+for (const n of probe) fwd.push(await session.hash(n, 0)); for (const n of [...probe].reverse()) rev.unshift(await session.hash(n, session.workers - 1));+const same = probe.filter((_, i) => fwd[i] === rev[i]).length;+console.log(`\ndeterminism: ${same}/${probe.length} probe frames hash-identical (forward on page 0 vs reversed on page ${session.workers - 1})${same === probe.length ? "" : " -> fall back to PSNR > 45 dB in the Phase 2 gate"}`);+await session.close();+const pr = execFileSync("ffprobe", ["-v", "error", "-show_entries", "stream=codec_type,codec_name,width,height,nb_frames,duration", "-of", "csv=p=0", out]).toString().trim().split("\n");+console.log(`\noutput: ${out}`); pr.forEach((l) => console.log(` ${l}`));diff --git a/engine/tools/scaffold.mjs b/engine/tools/scaffold.mjsnew file mode 100644index 0000000..8c8b9ef--- /dev/null+++ b/engine/tools/scaffold.mjs@@ -0,0 +1,81 @@+// SCAFFOLD. Turn the skill's engine into a working film project.+//+// node <skill>/engine/tools/scaffold.mjs <dir> [--film myFilm] [--example]+//+// The engine ships as parts, not as a project: `engine/src` holds the portable art core and the+// one page host, `example/src` holds the worked butterfly. A film needs them in ONE tree, because+// every tool here resolves `src/canvas-core/<film>.ts` and `src/hosts/page-<film>.ts` against the+// working directory. That is the whole job.+//+// --film <name> write a minimal film module and its host page, ready to render+// --example copy the mechanical-butterfly in as well, to READ. It is proof of craft, not+// a template: copying it gets you somebody else's film with your title on it.+import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";+import { dirname, join, resolve } from "node:path";+import { fileURLToPath } from "node:url";++const HERE = dirname(fileURLToPath(import.meta.url));+const ENGINE = resolve(HERE, "..");+const SKILL = resolve(ENGINE, "..");++const VAL = new Set(["film"]);+const pos = [], opt = {};+for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }+const die = (m) => { console.error(`scaffold: ${m}`); process.exit(1); };+const target = resolve(pos[0] ?? die("usage: node tools/scaffold.mjs <dir> [--film myFilm] [--example]"));+const film = opt.film && opt.film !== true ? String(opt.film) : null;+if (film && !/^[a-zA-Z][a-zA-Z0-9]*$/.test(film)) die(`--film '${film}' must be a bare identifier: it becomes a module name and an export name`);++mkdirSync(target, { recursive: true });+cpSync(join(ENGINE, "src"), join(target, "src"), { recursive: true });+cpSync(join(ENGINE, "tools"), join(target, "tools"), { recursive: true });+for (const f of ["package.json", "tsconfig.json"]) if (existsSync(join(ENGINE, f))) cpSync(join(ENGINE, f), join(target, f));++if (opt.example) {+ const ex = join(SKILL, "example", "src");+ if (!existsSync(ex)) die(`--example asked for, but ${ex} is not there`);+ cpSync(ex, join(target, "src"), { recursive: true });+}++// A film is data: meta, an empty asset manifest, and shots that tile [0, duration). The starter+// draws something that MOVES on every frame, because a film whose first frame is blank teaches+// the wrong habit and fails the dead-air gate on day one.+if (film) {+ const mod = join(target, "src/canvas-core", `${film}.ts`);+ if (existsSync(mod)) die(`${mod} already exists; refusing to overwrite a film module`);+ writeFileSync(mod, `import { Ctx, Env, rng } from "./core";+import { Film } from "./film";++// 120 bpm at 30 fps is a 15-frame beat. Cuts land on multiples of 15, events on multiples of 5.+const FPS = 30, BPM = 120, BEAT = (60 / BPM) * FPS, DURATION = BEAT * 32;++const draw = (ctx: Ctx, local: number, env: Env) => {+ const W = env.W * env.scale, H = env.H * env.scale, r = rng(1);+ ctx.fillStyle = "#12161c"; ctx.fillRect(0, 0, W, H);+ // Everything below is a pure function of \`local\`. No clock, no Math.random, no assets.+ const t = local / DURATION;+ for (let i = 0; i < 90; i++) {+ const a = r() * Math.PI * 2, rad = (0.08 + r() * 0.36) * Math.min(W, H);+ const x = W / 2 + Math.cos(a + t * Math.PI * 2) * rad, y = H / 2 + Math.sin(a + t * Math.PI * 2) * rad;+ ctx.globalAlpha = 0.25 + r() * 0.6;+ ctx.fillStyle = "#e8e3d2";+ ctx.beginPath(); ctx.arc(x, y, (1 + r() * 2.5) * env.scale, 0, Math.PI * 2); ctx.fill();+ }+ ctx.globalAlpha = 1;+};++export const ${film}: Film = {+ meta: { title: "${film}", W: 1080, H: 1080, fps: FPS, bpm: BPM, durationFrames: DURATION },+ assets: { images: {} },+ shots: [{ id: "one", start: 0, end: DURATION, draw }],+ // audio: (sampleRate) => [left, right], // see references/music-recipe.md before writing a note+};+`);+ writeFileSync(join(target, "src/hosts", `page-${film}.ts`), `import { ${film} } from "../canvas-core/${film}";\nimport { mountFilm } from "./page";\nmountFilm(${film});\n`);+}++const tree = (dir, depth = 0) => readdirSync(dir, { withFileTypes: true }).filter((e) => e.name !== "node_modules").slice(0, 6).map((e) => `${" ".repeat(depth + 1)}${e.name}${e.isDirectory() ? "/" : ""}`).join("\n");+console.log(`scaffolded ${target}\n${tree(target)}\n`);+console.log(`next:\n cd ${target}\n npm install`);+if (film) console.log(` node tools/still.mjs ${film} --out out/look.png # the ONE look still\n node tools/gate.mjs ${film} --mp4 out/${film.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}.mp4`);+if (opt.example) console.log(` node tools/gate.mjs mechanicalLepidoptera --mp4 out/mechanical-lepidoptera.mp4 # the worked example`);diff --git a/engine/tools/snap.mjs b/engine/tools/snap.mjsnew file mode 100644index 0000000..e2232a8--- /dev/null+++ b/engine/tools/snap.mjs@@ -0,0 +1,71 @@+// SNAP. Proof stills for scene work: render N sample frames of one shot (or of every shot) on+// ONE uncontended page, and optionally tile them into a contact sheet a human can look at.+// node tools/snap.mjs <film> [--shot id] [--samples N] [--sheet] [--only] [--scale S] [--out path]+// --only bundles the film with every SIBLING shot module shimmed to a no-op, so parallel scene+// work is never blocked by a sibling file that does not compile. Needs --shot in that mode.+import { build } from "esbuild";+import { execFileSync } from "node:child_process";+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { dirname, join, resolve } from "node:path";+import { buildPage } from "./build-page.mjs";+import { detect } from "./detect.mjs";+import * as playwright from "./adapters/playwright.mjs";++const VAL = new Set(["shot", "samples", "scale", "out"]);+const pos = [], opt = {};+for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }+const [film] = pos, shotId = opt.shot, samples = Math.max(1, +(opt.samples ?? 6)), scale = +(opt.scale ?? 1);+const die = (m) => { console.error(`snap: ${m}`); process.exit(1); };+if (!film) die("usage: node tools/snap.mjs <film> [--shot id] [--samples N] [--sheet] [--only] [--scale S] [--out path]");+if (opt.only && !shotId) die("--only needs --shot <id>: the one shot to bundle for real");+if (!existsSync(`src/canvas-core/${film}.ts`)) die(`no film module at src/canvas-core/${film}.ts`);+if (opt.only && !existsSync(`src/canvas-core/${film}/${shotId}.ts`)) die(`--only: no shot module at src/canvas-core/${film}/${shotId}.ts`);++// --only: shim every relative import from the film module that lands in its shot dir, except the target+const onlyPlugin = opt.only ? (() => {+ const target = resolve(`src/canvas-core/${film}/${shotId}.ts`).replace(/\.ts$/, ""), shims = {};+ let n = 0;+ for (const [, bindings, spec] of readFileSync(`src/canvas-core/${film}.ts`, "utf8").matchAll(/import\s*\{([^}]+)\}\s*from\s*"(\.[^"]+)"/g)) {+ const abs = resolve("src/canvas-core", spec).replace(/\.ts$/, "");+ if (!abs.startsWith(resolve(`src/canvas-core/${film}/`)) || abs === target) continue;+ const names = bindings.split(",").map((b) => b.trim().split(/\s+as\s+/)[0]).filter(Boolean);+ const shim = resolve(`.tmp/snap/shim-${film}-${n++}.ts`);+ mkdirSync(dirname(shim), { recursive: true });+ writeFileSync(shim, `// GENERATED by tools/snap.mjs (--only shim)\n${names.map((nm) => `export const ${nm} = () => undefined;`).join("\n")}\n`);+ shims[abs] = shim;+ }+ if (!Object.keys(shims).length) console.error("snap: --only: no sibling modules found to shim (shots may be inline in the film module)");+ else console.log(`--only: siblings shimmed to no-ops: ${Object.keys(shims).map((p) => p.split("/").pop()).join(", ")}`);+ return [{ name: "snap-only", setup: (b) => b.onResolve({ filter: /^[.]/ }, (args) => { const hit = shims[resolve(dirname(args.importer), args.path).replace(/\.ts$/, "")]; return hit ? { path: hit } : null; }) }];+})() : [];++// the film's own shots and meta, read through the same shim in --only mode+const probe = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: onlyPlugin })).outputFiles[0].text;+const f = (await import("data:text/javascript;base64," + Buffer.from(probe).toString("base64"))).film;+const targets = shotId ? [f.shots.find((s) => s.id === shotId) ?? die(`film '${film}' has no shot '${shotId}' (has: ${f.shots.map((s) => s.id).join(", ")})`)] : f.shots;++const env = detect();+if (!env.chosen) die("no render backend found (snap draws real frames); the HTML player still works: node tools/build-page.mjs");+const entry = opt.only ? (mkdirSync(".tmp/snap", { recursive: true }), resolve(`.tmp/snap/page-${film}--${shotId}.ts`)) : `src/hosts/page-${film}.ts`;+if (opt.only) writeFileSync(entry, `// GENERATED by tools/snap.mjs (--only bundle)\nimport { ${film} } from "../../src/canvas-core/${film}";\nimport { mountFilm } from "../../src/hosts/page";\nmountFilm(${film});\n`);+const page = await buildPage({ entry, out: resolve(opt.only ? `dist/snap-${film}--${shotId}.html` : `dist/${film}.html`), title: film, plugins: onlyPlugin });+console.log(`page: ${page.out} (${(page.bytes / 1024).toFixed(0)} KB)`);+const session = await playwright.open(env, page.out, { scale, workers: 1 });++// N evenly spaced frames across [start, end), first and last included+const framesOf = (s) => { const n = Math.min(samples, s.end - s.start); return Array.from({ length: n }, (_, i) => s.start + Math.round((i * (s.end - s.start - 1)) / Math.max(1, n - 1))); };+console.log(`film: "${f.meta.title}" ${f.meta.W}x${f.meta.H}, ${samples} sample(s) per shot, scale ${scale}`);+for (const s of targets) {+ const dir = join(".tmp", "snap", film, s.id), fs = framesOf(s), ms = [];+ mkdirSync(dir, { recursive: true });+ let i = 0;+ for (const fr of fs) { const r = await session.frame(fr, 0); ms.push(r.drawMs); writeFileSync(join(dir, `f${String(i++).padStart(4, "0")}.png`), r.png); if (r.shot !== s.id) console.error(`snap: warning: frame ${fr} was drawn by shot '${r.shot}', expected '${s.id}'`); }+ console.log(` ${s.id.padEnd(12)} frames ${fs.join(", ")} draw ms [${ms.map((m) => m.toFixed(0)).join(", ")}] -> ${dir}`);+ if (opt.sheet) {+ const cols = Math.ceil(Math.sqrt(fs.length)), rows = Math.ceil(fs.length / cols), out = targets.length === 1 && opt.out ? resolve(opt.out) : resolve(`out/snap-${film}-${s.id}.png`);+ mkdirSync(dirname(out), { recursive: true });+ execFileSync(env.ffmpeg.bin, ["-y", "-loglevel", "error", "-start_number", "0", "-framerate", "1", "-i", join(dir, "f%04d.png"), "-vf", `scale=360:-2,tile=${cols}x${rows}`, "-frames:v", "1", out]);+ console.log(` sheet: ${out} (${cols}x${rows})`);+ }+}+await session.close();diff --git a/engine/tools/still.mjs b/engine/tools/still.mjsnew file mode 100644index 0000000..4902fe5--- /dev/null+++ b/engine/tools/still.mjs@@ -0,0 +1,38 @@+// STILL. One frame of one film, at full resolution, to a path a human can open.+// node tools/still.mjs <film> --shot <id> --out out/x.png [--scale 1]+// The look still is rendered many times before a single frame of motion is, so+// this does exactly that and nothing else: build the page, draw the frame, write the PNG, print+// the draw cost and the frame's hash so a re-render can be proved identical.+import { createHash } from "node:crypto";+import { mkdirSync, writeFileSync } from "node:fs";+import { dirname, resolve } from "node:path";+import { buildPage } from "./build-page.mjs";+import { detect } from "./detect.mjs";+import * as playwright from "./adapters/playwright.mjs";++const VAL = new Set(["shot", "out", "scale", "frame"]);+const pos = [], opt = {};+for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }+const die = (m) => { console.error(`still: ${m}`); process.exit(1); };+const film = pos[0] ?? die("usage: node tools/still.mjs <film> --shot <id> --out out/x.png [--scale 1]");+const scale = Number(opt.scale ?? 1);++const env = detect();+if (!env.chosen) die("no render backend found; the HTML player still works: node tools/build-page.mjs " + film);+const page = await buildPage({ entry: `src/hosts/page-${film}.ts`, out: resolve(`dist/${film}.html`), title: film });+const session = await playwright.open(env, page.out, { scale, workers: 1 });+const meta = await session.info();+const probe = (await import("data:text/javascript;base64," + Buffer.from((await (await import("esbuild")).build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text).toString("base64"))).film;+const shots = opt.shot ? [probe.shots.find((s) => s.id === opt.shot) ?? die(`no shot '${opt.shot}' (has: ${probe.shots.map((s) => s.id).join(", ")})`)] : probe.shots;++console.log(`film: "${meta.title}" ${meta.W}x${meta.H}, scale ${scale}`);+for (const s of shots) {+ const n = opt.frame !== undefined ? Number(opt.frame) : s.start;+ const out = resolve(shots.length === 1 && opt.out ? opt.out : `out/still-${film}-${s.id}.png`);+ const a = await session.frame(n, 0);+ const b = await session.frame(n, 0); // drawn twice: a still that is not reproducible is not a gate+ mkdirSync(dirname(out), { recursive: true }); writeFileSync(out, a.png);+ const h = (p) => createHash("md5").update(p).digest("hex");+ console.log(` ${s.id.padEnd(12)} frame ${String(n).padEnd(5)} draw ${a.drawMs.toFixed(0)} ms md5 ${h(a.png)} ${h(a.png) === h(b.png) ? "reproducible" : "NOT REPRODUCIBLE"} -> ${out} (${(a.png.length / 1024).toFixed(0)} KB)`);+}+await session.close();diff --git a/engine/tools/verify-frame-adapter.mjs b/engine/tools/verify-frame-adapter.mjsnew file mode 100644index 0000000..01c85c3--- /dev/null+++ b/engine/tools/verify-frame-adapter.mjs@@ -0,0 +1,65 @@+// VERIFY FRAME ADAPTER. Hyperframes is not installed here, so its own engine cannot be run. What+// CAN be proved is the half of the contract this repo owns: the page-side FrameAdapter that the+// engine would drive. This holds it to Hyperframes' published requirements, using playwright as a+// stand-in driver:+//+// a finite, non-negative frame count+// forward, backward and RANDOM seeks+// the same state whenever the same frame is asked for again+// and, the part that actually matters, seeked pixels identical to the plain player's+//+// If the engine is ever installed, this stays useful: it isolates a page-side fault from an+// engine-side one, which is the difference between an hour and a day.+//+// node tools/verify-frame-adapter.mjs [film]+import { mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { join, resolve } from "node:path";+import { pathToFileURL } from "node:url";+import { buildPage } from "./build-page.mjs";+import { FRAME_ADAPTER, ENGINE, INSTALL, probe } from "./adapters/hyperframes.mjs";+import { detect } from "./detect.mjs";++const film = process.argv[2] ?? "mechanicalLepidoptera";+const dir = resolve(".tmp/hyperframes", film); mkdirSync(dir, { recursive: true });+const out = join(dir, `${film}.html`);+const built = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });+writeFileSync(out, readFileSync(out, "utf8").replace("</body>", `<script>${FRAME_ADAPTER(film)}</script></body>`));++const env = detect();+const browser = await env.pw.lib.chromium.launch({ executablePath: env.browser.executablePath });+const page = await (await browser.newContext({ viewport: { width: 640, height: 640 } })).newPage();+const errs = []; page.on("pageerror", (e) => errs.push(e.message));+await page.goto(pathToFileURL(out).href + "?adapter=hyperframes");+await page.evaluate(() => window.__hfAdapter.init());++let fails = 0;+const say = (ok, label, detail = "") => { if (!ok) fails++; console.log(` ${ok ? "PASS" : "FAIL"} ${label}${detail ? " " + detail : ""}`); };++const shape = await page.evaluate(() => ({ id: window.__hfAdapter.id, types: ["init","getDurationFrames","seekFrame","destroy"].map(k => typeof window.__hfAdapter[k]), hf: [typeof window.__hf.duration, typeof window.__hf.seek] }));+say(shape.id === film, "the adapter carries the film's id", shape.id);+say(shape.types.every(t => t === "function"), "init, getDurationFrames, seekFrame, destroy are all functions", shape.types.join(", "));+say(shape.hf.every(t => t === "function"), "window.__hf exposes duration and seek too", shape.hf.join(", "));++const dur = await page.evaluate(() => window.__hfAdapter.getDurationFrames());+say(Number.isFinite(dur) && dur > 0 && Number.isInteger(dur), "getDurationFrames() is finite and non-negative", String(dur));+say(dur === built.meta.durationFrames, "it agrees with the film", `${dur} vs ${built.meta.durationFrames}`);++const seek = async (n) => page.evaluate((f) => { window.__hfAdapter.seekFrame(f); return window.FILM.hash(); }, n);+const order = [0, 900, 45, 1409, 300, 1409, 45, 0, 900, 300]; // forward, backward and random, with repeats+const seen = new Map(), mismatch = [];+for (const n of order) { const h = await seek(n); if (seen.has(n) && seen.get(n) !== h) mismatch.push(n); seen.set(n, h); }+say(mismatch.length === 0, "the same frame gives the same state however it is reached", mismatch.length ? `drifted at ${mismatch.join(", ")}` : `${order.length} seeks, ${seen.size} distinct frames, forward + backward + random`);+say(new Set(seen.values()).size === seen.size, "different frames are genuinely different pixels", `${new Set(seen.values()).size}/${seen.size} distinct hashes`);+say(errs.length === 0, "no page error while seeking", errs.slice(0, 2).join("; ") || "none");++// The real proof: a seek-driven hash must equal what the plain player draws cold for that frame.+const fresh = await (await browser.newContext({ viewport: { width: 640, height: 640 } })).newPage();+await fresh.goto(pathToFileURL(out).href + "?adapter=check");+await fresh.evaluate(async () => { await window.FILM.ready; window.FILM.mount(1); });+const bad = [];+for (const [n, h] of seen) { const c = await fresh.evaluate((f) => { window.FILM.seek(f); return window.FILM.hash(); }, n); if (c !== h) bad.push(n); }+say(bad.length === 0, "seeked frames match the same frames drawn by the plain player", bad.length ? `differ at ${bad.join(", ")}` : `${seen.size} frames`);++await browser.close();+console.log(`\nPAGE-SIDE FRAME ADAPTER: ${fails ? `FAIL (${fails})` : "PASS"} engine itself: ${probe().ok ? "installed" : `NOT RUN (${ENGINE} absent, ${INSTALL})`}`);+process.exit(fails ? 1 : 0);diff --git a/engine/tsconfig.json b/engine/tsconfig.jsonnew file mode 100644index 0000000..1fe1ad9--- /dev/null+++ b/engine/tsconfig.json@@ -0,0 +1,7 @@+{+ "compilerOptions": {+ "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", "jsx": "react-jsx",+ "strict": true, "noEmit": true, "skipLibCheck": true, "esModuleInterop": true, "lib": ["DOM", "ES2022"]+ },+ "include": ["src"]+}diff --git a/example/README.md b/example/README.mdnew file mode 100644index 0000000..6096b4d--- /dev/null+++ b/example/README.md@@ -0,0 +1,50 @@+# MECHANICAL LEPIDOPTERA — the worked example++1410 frames, 47.0 s at 30 fps, 1080x1080. A clockwork butterfly is drawn on a blueprint sheet,+comes alive, and leaves its blueprint behind in the grass. Every pixel and every audio sample is+drawn by code. No images, no fonts, no samples.++`butterfly-film-spec.md` is the spec it was built from — the story, the shot list, the cue grid,+the realism section, the music. Read that first; it is what a good spec looks like.++## Study it. Do not copy it.++This is here as proof of craft, not as a template. Copying it gets you somebody else's film with+your title on it, and none of the craft bar in `SKILL.md` is satisfied by inheritance.++What is worth opening, and why:++| File | What it shows |+|---|---|+| `src/canvas-core/mechanicalLepidoptera.ts` | a whole film as data: meta, shots tiling `[0, duration)`, the score attached |+| `src/canvas-core/butterfly/act1cues.ts` | ONE cue table holding every frame number, with a checker that runs at load |+| `src/canvas-core/butterfly/alive/anatomy.ts` | realism as code: a closed discal cell, veins that fork and never cross, a scalloped margin — and a header naming the four reference images actually opened |+| `src/canvas-core/butterfly/alive/lateral.ts` | the second AUTHORED view. A closed wing is the same wing stood up, not a folded one |+| `src/canvas-core/butterfly/surface.ts` | a cache key that names everything its pixels depend on |+| `src/canvas-core/butterfly/plate.ts` | `live()` vs `still()`: two kits, so a surface drawn at some boil cannot be given a key that omits it |+| `src/canvas-core/butterfly/alive/score.ts` | the music recipe as arithmetic, with every onset asserted onto the frame grid |+| `src/canvas-core/butterfly/kit.ts` | the draftsman's marks: a ruling pen that is never quite straight |++## Running it++The example is not a project on its own — its modules import `../core`, which lives in the+engine. Put the two together:++```bash+node <skill>/engine/tools/scaffold.mjs ~/study --example+cd ~/study && npm install+node tools/still.mjs mechanicalLepidoptera --out out/look.png+node tools/gate.mjs mechanicalLepidoptera --mp4 out/mechanical-lepidoptera.mp4+node tools/emit.mjs mechanicalLepidoptera --out out/mechanical-lepidoptera.html+```++The dead-air check needs a rendered MP4 to measure; without one it reports that and the other two+bars still run. `node tools/render.mjs mechanicalLepidoptera` makes it (it takes a while: 1410+frames).++## One honest note about Act 1++Act 1 (frames 0-540) is LOCKED on the original film and it fails the dead-air bar at its open —+there are 49 identical consecutive frames in it, all inside that act. The gate reports them+separately rather than laundering them. That is the right behaviour to copy: a gate that hides a+known failure to keep a green light is worth nothing.diff --git a/example/butterfly-film-spec.md b/example/butterfly-film-spec.mdnew file mode 100644index 0000000..b28342a--- /dev/null+++ b/example/butterfly-film-spec.md@@ -0,0 +1,273 @@+# MECHANICAL LEPIDOPTERA: film spec, Revision 4 (BUILT, then ALIVE)++Roles: an art director authors and reviews this spec, a builder implements it, a client approves.+Project: this skill's `example/` (a worked reference to study, not a template).+Read before building, in this order: this file, whole; `../references/determinism-and-contract.md` for the rules every frame obeys; then the modules beside this spec in `src/canvas-core/butterfly/` (geom, kit, parts, plate, surface, linkage, act1cues, and the finale world in act4*). Render the approved destination still yourself before you change anything that reaches it.++This revision REPLACES Revision 3. Lines marked DIRECTOR are the art director's own calls, vetoable by the client in one line.++---++## 0. The story (the client)++A mechanical butterfly is BUILT on a blueprint. Then it comes ALIVE, leaves the blueprint, and the world opens around it.++| # | Movement | Medium | Frames | Beats | Bars | Status |+|---|---|---|---|---|---|---|+| 1 | BLUEPRINT: the plate drafts itself, with camera | cyanotype, ruling pen | 540 | 36 | 9 | DONE, APPROVED, LOCKED |+| 2 | ALIVE: one continuous coming-to-life, macro to wide | pencil + watercolour | 1260 | 84 | 21 | this spec |+| | **Film** | | **1800** | **120** | **30** | **60.0 s** |++1080x1080, 30 fps, 120 bpm.++**Cut from the film (the client):** the editorial cutaway. **Cut (DIRECTOR, my call on the question the client left open):** the riso wake. Reason: the story is two states, a drawing and a living thing. A third medium in the middle is a detour, and there is no honest device that turns printer's ink into watercolour. There IS one that turns a cyanotype into watercolour: water. Cyanotypes are developed in water and the blue lifts when wet. So the bridge is a single drop of water landing on the blueprint (section 5, beat 1). The cut acts are not part of this film and do not ship with it. What survives from them: `linkage.ts` (flap driven by the crank), the stir vocabulary (gears catch, antennae quiver, first twitch), `tools/deadair.mjs`, the camera/view engine, per-part cached surfaces.++**The one idea that makes it one story (DIRECTOR):** the blueprint of Act 1 and the ghost blueprint lying in the grass on the approved finale still are THE SAME SHEET. Movement 2 starts pressed against that sheet in macro and never cuts again: one stepped pull-back carries us from a wing panel, to the whole creature, to the sheet it leaves behind, to the ranunculus, to the meadow, and the last thing to come back into frame is the sheet, with a butterfly-shaped blank where the drawing used to be and the key it no longer needs. The ending's meaning is set up by the first frame.++### 0.1 Hard rules++1. **NO DEAD AIR.** Something visibly moves in every second. No blank starts, no static holds. Checked by `tools/deadair.mjs` (gate G-AIR). "Hold" in this document always means the camera slows to a creep while the subject keeps moving.+2. **EVERY ELEMENT MEANS SOMETHING.** Decoration is the machine tell.+3. **ONE SHOT.** Movement 2 contains no cuts. Every change of scale is a camera move, and every big move is MOTIVATED BY A TAKE-OFF (the client).++---++## 1. The grid (binding)++One beat = 15 frames. Bars = 60. Movement boundaries on bar lines.+- **Events** (a drop lands, a panel floods, a landing, a take-off, a stroke begins): multiples of **5**.+- **Landings and take-offs: on BEATS** (multiples of 15). Take-offs that trigger a camera step: on BAR lines where the table says so.+- Motion inside a move is continuous; its start and arrival are on the grid.+- Every frame number lives in `act2cues.ts` (new file for this movement; retire the riso table to `legacy/`) and nowhere else. `gridProblems()` at module load.++## 2. Craft bar (binding)++The client's test: would a proud human illustrator ship this. Never mechanical shape-assembly.++| The tell (rejected) | What passes |+|---|---|+| Things fade or scale in | Marks are MADE: water spreads, a wash floods out from where the brush touched, a line is drawn on |+| Symmetry in time | One side leads. Always lopsided |+| Mechanical easing on a living thing | After it wakes: ease in AND out, overlap, follow-through, the body bobbing against the wings |+| Canvas-scaled parts | Transform CONTROL POINTS, then paint. Never scale a bitmap up |+| Even scatter | Hand-placed DRIFTS with bare rests between |+| One flower stamped many times | 5 hand-authored views per species (section 6), seeded petal variation, no view above 25 percent of a clump |+| Concentric scalloped circles for a ranunculus | Petals painted from the centre out as overlapping C-strokes with paper left between them (6.1) |+| Grass swaying in unison | Wind as a GUST FRONT crossing the field; blades lean on arrival, spring back lopsided |+| Flat bands of one green | Three greens by temperature, wet-in-wet, dry-brush on top, cast shadows, cloud shadows |+| Gradient sky, disc sun | Graded granulating wash; the sun is where the paper was left lightest |+| Outline round everything | Lost-and-found pencil on near planes only. Far planes are paint alone |+| A sheet of paper that looks like a sticker | A rectangle in perspective, one corner curled, grass blades OVER its edges, a cast shadow under the curl, flattened grass round it |++## 3. Contract (unchanged)++`renderFrame` pure in `(frame, env)`. Randomness only from `rng(seed)`. No `Math.random`, `Date`, `performance.now`, `ctx.filter`, `document`, `window`, `new OffscreenCanvas`, `new Image`, or imports of `react`, `remotion` or any host/component module in the core. Surfaces from `env.canvas()`. Seeded tile textures. `g.touch()` for raw drawing in groups. Cache keys name everything the pixels depend on. `/* */` when patching one-liners. Never touch the locked deliverables (the finished film and Act 1's source and MP4). Install nothing without your own security gate. Budget 150 ms draw per frame, one page, warm.++## 4. Camera model (binding)++A true DOLLY over depth planes (already built for the finale world): camera distance `D`, plane depth `z_i`, plane scale `s_i = 1 / (D + z_i)`. The HERO plane is `z = 0`, so hero scale `S = 1 / D`. **S is "screen px per sheet unit"**: at S = 1 the creature (wingspan 780 units) is 780 px wide.++- `S(frame)` is a monotone cubic through `log2(S)` keys (table 5.1). It never increases. After frame 0 its velocity is never zero: between steps it CREEPS.+- The camera centre follows the creature with critically damped lag (about 25 frames) in stages M to R, then hands over to an authored path keyed on bars that ends on the approved still's composition.+- Never scale a bitmap UP. Static washes per plane are cached at LOD steps of sqrt 2 and only downscaled, by at most 1.41x. Everything that moves is drawn live from control points, culled to frame, LOD-reduced by screen size.+- Line weight `w = w_authored * S^0.35`. All texture anchored to the world. Finer tile octave comes up with S. Max S = 4.0 (raised from 3.4 for the macro; watercolour has no hairlines to fatten).++---++## 5. MOVEMENT 2, ALIVE (1260 frames). The client's six beats, on the grid.++Local frames `[start, end)`. Film frame = local + 540.++### 5.1 Camera scale at each stage++| Stage | Frames | S (hero scale) | D | Creature wingspan on screen | What the frame holds |+|---|---|---|---|---|---|+| **M, macro wings** | 0-120 | 4.0 creeping to 3.4 | 0.25-0.29 | 3100 px, far bigger than frame | One forewing root, panel 2, the edge of the thorax window. Extreme close |+| M2, still macro | 120-240 | 3.4 to 1.6 | 0.29-0.63 | 2650 to 1250 px | Thorax and all four wing roots; by 240 most of the creature |+| **T1, take-off pull** | 240-345 | 1.6 to 0.55 | 0.63-1.82 | 1250 to 430 px | The whole creature, then the whole SHEET with its blank, then grass over the sheet's edges, then stems |+| **R, close ranunculus** | 345-720 | 0.55 stepping down to 0.45 | 1.82-2.22 | 430 to 350 px | Three to five ranunculus heads fill the frame; each head about 385 to 315 px. THE HOLD: 6 bars, 12.5 s |+| **F, mid flight** | 720-870 | 0.45 to 0.18 | 2.22-5.56 | 350 to 140 px | Drifts of flowers, grass, the footpath, the first hills at the top of frame by about 800 |+| **W, wide meadow** | 870-1080 | 0.18 to 0.118 | 5.56-8.47 | see 5.7 (it flies TOWARD us) | Field, hills, sky, sun, clouds. The sheet comes back into frame lower left |+| Settle + signature | 1080-1260 | 0.118 to 0.115 | 8.47-8.70 | 290 px (as the approved still) | The approved still's composition, alive, signed |++`S` keys for the cubic: f0 4.0 · f120 3.4 · f240 1.6 · f345 0.55 · f420 0.545 · f450 0.52 · f525 0.515 · f555 0.49 · f630 0.485 · f660 0.47 · f720 0.45 · f810 0.24 · f870 0.18 · f1080 0.118 · f1260 0.115. Between steps the camera creeps (about 1 percent per bar); the drops that start at 420, 525 and 630 are the "steps": each is released by a take-off and takes 30 frames. The big moves start on the take-offs at 240, 720 and 855.++### 5.2 BEAT 1. It turns into a real butterfly (0-240, bars 1-4). Stage M.++The join to Act 1 is a CUT on the bar line (the only cut in the film after Act 1's own match cut): from Act 1's held wide plate to a macro of the SAME plate, same state, same ticking train. View M0: centred on the starboard forewing root so that lifted PANEL 2 on its projection lines sits right of centre and the edge of the thorax window, wheels stepping, sits in the left third. Gate: frame 0 must equal Act 1's final state drawn at view M0 (hash or above 45 dB).++| Frames | Camera | What happens |+|---|---|---|+| 0-5 | M0, S 4.0, creeping | Blueprint macro. White line on Prussian ground. The train steps on 0. The tick continues from Act 1 |+| **5** | | **A drop of water lands** on panel 2. A clear bead: darker blue under it, one paper-white highlight, a tiny crown splash of 4 droplets |+| 5-60 | creep | **The water runs, and a REAL WING comes up behind it.** It does not spread as a circle: it follows the drawing by capillary, along the spars toward the hinge, one spar per 5 frames (water does not care about the draftsman's order). Behind the wet front, on the creature only, every mechanical part becomes the piece of anatomy it always stood for (mapping in 5.7): the ruled SPAR softens, tapers and forks into a VEIN; the membrane PANEL becomes a wing CELL, first a pale warm wash, then scale colour and markings dropped in wet-on-damp (basal dusting, the dark apical patch with its pale spots, the marginal band); each RIVET becomes a submarginal SPOT; the ruled margin becomes a scalloped edge with a fine fringe. The Prussian ground lifts to bare cold-press under the wing only. The front itself is a dark blue rim of displaced pigment. By 60 the starboard forewing in frame is unmistakably a butterfly's wing, of naturalist-plate quality, and the sheet AROUND the creature is still a blueprint, for ever. **Rejected: a frame that reads as gears on one side and colour on the other. At every frame the painted part must already be anatomy, never an abstract colour field** |+| 45-60 | creep | **Panel 2 comes home.** It floods CORNFLOWER blue (it keeps the blueprint's colour, with a ghost of the ruled grid lifted in it) and slides down its projection lines, dashes shrinking, seating on 60 with the last mechanical overshoot in the film. The flaw is healed, and it becomes the mark of the individual: that blue panel is on the approved still |+| 60-120 | slow drift left across the thorax to the port wing roots, S to 3.4 | **Water crosses the body, and the body becomes an insect.** The housing takes a warm umber-grey wash turned as a form (light upper right, core shadow, reflected light below). The wheels in the window keep stepping on the tick while thoracic FUR is dry-brushed in from the window's edge, stroke by stroke, 75-120, closing over them: the mechanism is not removed, it is grown over. Abdomen rings become true segments with paler bands and fine hair. The stippled eyes become compound eyes with one lifted highlight each. Port wings come up 75-120, vein by vein, as the starboard did. Dimension lines, leaders and balloons that cross the frame stay hard white on blue: furniture does not change |+| 120-180 | ease back, S 3.4 to 2.4 | **First movement, and it is the movement of a newly emerged butterfly.** 120: the last of the mechanism, felt not seen: one stall, a recoil held for 2 ticks, a double step on 130, as a shudder through the thorax. 125: port antenna (now a finely ringed shaft with a true club) quivers, starboard answers on 130. 135-150: the six LEGS unfold from under the thorax, one pair per 5 frames, thin and jointed, and take the weight; the body lifts a hair off the sheet. 150-180: a BREATH, flap 1 to 0.86 and back, port first, starboard a triplet later. Motion is still STEPPED on the tick: it moves like a mechanism wearing a butterfly |+| 180-240 | S 2.4 to 1.6 | **It softens into a living thing: the slow fanning of wet wings.** Real butterflies do exactly this after emerging, pumping and fanning until the wings are dry enough to fly, so the wet paint IS the wet wings. Three fans, wider each time: down-strokes at 180 (30 frames, to flap 0.6), 210 (20 frames, to 0.5), 230 (10 frames). As the wings rise we see, for the first time, the paler UNDERSIDE pattern (5.7). Across this bar the motion blends from tick-stepped to continuous (`motion = lerp(stepped, smooth, u)`, u 0 to 1 over 180-240), easing changes from hard-out to in-and-out, the body bobs against the wings, the abdomen curls, the antennae trail, the proboscis uncoils once and recoils (200-220). A soft painted SHADOW separates beneath it on the blue sheet, offset 0 to (14, 20). From 180 the paint lags the pencil by up to 9 px on fast strokes. **By 240 nothing mechanical is visible. What takes off is a real butterfly.** Sound: the tick thins across this bar and a felt wing-flutter takes each down-stroke (section 8) |++### 5.3 BEAT 2. It takes off; the camera begins to zoom out (240-345, bars 5-6). Stage T1.++| Frames | Camera | What happens |+|---|---|---|+| **240** | the pull-back STARTS here, motivated by the take-off | **Take-off on the bar line.** Wing cycle drops to 10 frames. It rises off the sheet; its shadow slides away down-left and shrinks |+| 240-285 | S 1.6 to 0.95 | **What it leaves behind:** a butterfly-shaped BLANK in the blueprint, bare unexposed paper where the drawing was, because the drawing went with it. The furniture is all still there, now dimensioning nothing: WINGSPAN 184 across an empty shape, leaders pointing at paper. The KEY stays on the sheet. At about 270 the whole sheet is in frame: border, cartouche, MECHANICAL LEPIDOPTERA, and the hole |+| 285-345 | S 0.95 to 0.55, centre following the creature up and right | **Scenery appears.** Grass blades lie OVER the sheet's edges; one corner is curled with a shadow under it. The camera rises and tilts with the creature: the sheet foreshortens (control points, y-scale 1 to 0.45 about its centre, slight keystone) as it slides out lower left, gone by 335. Stems rise through frame: tall, slender, curving. Out-of-focus colour behind them resolves into petals. Big soft foreground blades (plane z -0.2) whip out of frame |+| **345** | arrives S 0.55 | It is hovering over a clump of RANUNCULUS |++### 5.4 BEATS 3 and 4. The ranunculus close-up; flower to flower, sipping (345-720, bars 6-12). Stage R.++This is the heart of the film and it is held long enough to read: six bars. The camera only creeps and drifts sideways with the creature, stepping back slightly on each take-off.++| Frames | Beat | Action |+|---|---|---|+| **360** | 24 | **Lands on R1** (coral, facing us). The head DIPS (stem bends 6 degrees, one settle). Wings open flat, then fan slowly (30-frame cycle, amp 0.35): it is never still |+| 375-410 | | **Sips.** The proboscis, the blueprint's hairspring, uncoils into the tight centre (375-385). Abdomen pulses once per beat: the tick has become a heartbeat. Recoils 405-410 |+| **420** | 28 | Take-off. R1 rebounds. Camera step 0.55 to 0.52 over 420-450 |+| 420-450 | | Short hop right, a bob on every down-stroke (6 to 10 units), one playful overshoot past R2 and back |+| **450** | 30 | **Lands on R2** (blush white with a pink picotee edge, three-quarter view). Sips 465-510 |+| **525** | 35 | Take-off. Step to 0.49 over 525-555 |+| 525-555 | | Crosses LEFT behind a stem (it passes BEHIND: overlap sells depth), first gust of wind arrives 540 and pushes it sideways; it recovers |+| **555** | 37 | **Lands on R3** (butter yellow, profile cup, lower in frame, with a nodding bud on the same stem). Sips 570-615. A petal it disturbs falls (585-630, tumbling) |+| **630** | 42 | Take-off. Step to 0.47 over 630-660 |+| **660** | 44 | **Lands on R4** (deep magenta, half-open, highest in frame). Sips 675-705 |+| **720** | 48 | **Take-off on the bar line.** This one does not hop: it climbs. It releases BEAT 5 |++Through the whole stage: every head nods on its own period (50 to 80 frames, never shared), leaves turn, the gust front at 540 crosses in 60 frames, sunlight flickers as a cloud shadow slides over the clump (600-690), two seed-fluffs drift through the foreground.++### 5.5 BEAT 5. The camera zooms out more; it takes off again (720-870, bars 13-15). Stage F.++| Frames | Camera | Action |+|---|---|---|+| 720-810 | S 0.45 to 0.24 | Mid flight: up and away over the ranunculus, a loop at 750, low over a daisy drift, then right along the footpath. The ranunculus clump shrinks into one drift among many. Hills enter the top of frame at about 800 |+| **810** | S 0.24, creeping | **Touch-down on a field poppy**, far right, deeper in the field (plane z 2.2). A short sip, 820-845. Two small WHITE butterflies lift out of the grass nearby at 825 (DIRECTOR): real ones |+| **855** | beat 57 | **Take-off again.** Second gust arrives 855. This take-off releases the final pull-back |+| 855-870 | S to 0.18 | It climbs with the two whites spiralling round it |++### 5.6 BEAT 6. Final wide: the meadow (870-1260, bars 15-21). Stage W, settle, signature.++| Frames | Camera | Action |+|---|---|---|+| 870-1080 | S 0.18 to 0.118, authored path, horizon settling at y 410 | The meadow opens: far field in bands, two ridges with a hedgerow and one lone tree, the big warm sky, the sun upper right, three lifted clouds drifting left, cloud shadows sliding over the far field from 900. **At about 930 the blueprint sheet re-enters, lower left**: small, in perspective, its corner lifting in the gust (on 945 and 1005), the butterfly-shaped blank and the key on it. It is never pointed at |+| 900-1080 | | **It flies TOWARD us.** From the poppy it turns and comes up the field to the foreground, growing as the world shrinks (its depth goes z 2.2 to z -5.8, so its scale goes 0.13 to 0.37). The whites peel away at 990. It arrives at the approved still's position (440, 590), wingspan about 290 px, on 1080, and HOVERS: a slow figure of eight, 60-frame period, wings on a 10-frame beat |+| 1080-1140 | S creeping 0.118 to 0.116 | The picture is the approved still, alive: grass idling, heads nodding, clouds, the creature hovering |+| 1140-1155 | | A clean damp brush LIFTS the lower right corner: one soft swipe about 250 x 60 px (see 7) |+| 1155-1185 | | **The signature is written**, last stroke finishing on **1185 with the DING** (film frame 1725) |+| 1185-1260 | creep to 0.115 | Five beats to read it. Ink dries 0.75 to 0.60. The creature drifts a little higher. Last frame: the approved still's composition. THE END |++### 5.7 The creature, painted++**The client's note: MORE REALISTIC, less abstract. A naturalist watercolour plate, NOT colour fields.** The medium, the warmth and the ranunculus stay. My earlier "wings as stained glass" direction is withdrawn: it produced flat panels and it was wrong.++**The bar:** a plate from a natural-history folio (Merian, the 19th-century lepidoptera atlases) painted by someone who has had the specimen under a lens. A lepidopterist should be able to name every part. It stays an ORIGINAL species (borrow the medium, never the content): no copying a real butterfly's pattern, but every structure is true. Look at real reference for anatomy and venation before moving a point, and say which you used.++**What each mechanical part becomes (this mapping IS the transform beat, 5.2):**++| Blueprint | Living butterfly |+|---|---|+| Wing spars radiating from the hinge | VEINS. They keep their positions, so the silhouette and rhythm carry over, but they become true venation: a closed DISCAL CELL from the base to about half the wing, veins leaving the cell and running to the margin, forking, never crossing, thinning toward the edge |+| Membrane panels | Wing CELLS between veins, covered in scales |+| Rivets along the spars | The row of SUBMARGINAL SPOTS |+| Ruled wing margin | A margin gently SCALLOPED between vein ends, with a fine pale/dark FRINGE |+| Thorax housing and its window | A furred THORAX (the fur grows over the window) |+| Abdomen rings | 7 to 8 visible abdominal SEGMENTS, tapering, paler bands at the joints, fine hair |+| Stippled eyes | Two large COMPOUND EYES, one lifted highlight each, and a pair of small furry PALPS between them |+| Coiled-wire antennae | Slender, finely ringed ANTENNAE ending in true CLUBS |+| Proboscis hairspring | The PROBOSCIS, coiled at rest between the palps, a fine double tube when extended |+| (not on the blueprint) | SIX LEGS, thin and jointed: femur, tibia, a tarsus with a tiny claw. They unfold at 135-150, grip the petal when perched, tuck back in flight |+| Lifted panel 2 | The one mark no real butterfly has: a CORNFLOWER BLUE cell in the starboard forewing, painted as an iridescent scale patch. The blueprint it carries with it |++**Wings, two true pairs.** Forewing roughly triangular (leading edge, apex, outer margin, inner margin), hindwing rounder with the short TAIL the geometry already has. The forewing OVERLAPS the hindwing's leading third, and that double layer is darker. Left and right are never mirror images (keep the seeded asymmetry).+- **Pattern (original, plausible, warm):** ground of rose running to peach toward the margin. Warm grey-umber DUSTING at the base, hairy near the body. A dark umber APICAL PATCH on the forewing holding three pale spots. A dark MARGINAL BAND, narrowing toward the rear corner, carrying the row of pale submarginal spots. A small dark DISCAL SPOT at the end of the cell. On the hindwing, the marginal spot row again and, at the base of the tail, a small blue-and-orange EYESPOT.+- **Underside (seen whenever the wings rise or close):** different and quieter, as in life: pale cream-peach with soft grey-olive marbling, the spot row repeated small, veins a touch darker. A butterfly with the same pattern on both faces reads as a cut-out.+- **How to paint it:** a pale first wash over the whole wing; pattern dropped in WET-ON-DAMP so its edges soften the way scales do (no hard-edged shapes except the eyespot's pupil); veins LAST with a fine rigger in umber, broken, tapering, heavier near the base, never a uniform line; the fringe as tiny alternating ticks; a lifted paper-white rim on the sunward margins.+- **Volume and translucency:** the wing is not flat: a slight camber, so a soft shadow runs behind each main vein and the cell between catches light. The body casts a shadow onto the wing bases; the wings cast a shadow onto the flower. Wings are TRANSLUCENT: where a wing overlaps a petal or the sky, 15 to 20 percent of that colour warms through it; backlit (wings raised against the sun, upper right) the ground glows and the veins read darker.+- **Body:** painted as a form, not a capsule: light upper right, core shadow, reflected light from below, fur dry-brushed along the thorax in the direction it grows, the segment bands wrapping round the cylinder.++**Two authored views (DIRECTOR, needed for realism at the ranunculus):**+- **DORSAL** (existing control points): the transform beat, basking with wings flat, all flight.+- **LATERAL, wings closed or half open over the back** (new hand-authored control points: body in profile, six legs gripping, forewing and hindwing undersides overlapped). This is how most butterflies actually sip, and it is what a plate shows beside the dorsal figure. Used at stage R, where the creature is 350 to 430 px and realism matters most: at least two of the four ranunculus visits are lateral. The switch between views happens inside the landing flutter, at the instant the wings pass through closed. Below about 150 px on screen, dorsal with the pose transform is enough.++**Pose and flight.** `Pose = { flap, sweep, heading, pitch, bank }`, all on control points: `heading` rotates about the thorax, `pitch` foreshortens along the body axis (1 to 0.55), `bank` offsets port against starboard flap by up to 0.2. `flap` comes from `linkage.ts`; after frame 240 the crank runs free and smooth. Flight is a butterfly's: hand-authored paths with detours, a bob on every down-stroke, never a straight line or a clean sine. It is the most saturated thing in every frame, with the wash behind its path kept a value lighter. Never under 46 px wingspan. LOD: above 300 px everything above; 120 to 300 px veins, main markings, legs when perched; 46 to 120 px silhouette, two-tone wings, dark margin, the blue cell.++**Rejected on sight:** wings as flat colour fields or stained-glass panels; spars left as straight ruled lines; mirror-image wings; one pattern on both faces; a capsule body; antennae as a line with a dot; no legs; uniform-weight veins; any frame of the transform that reads as "gears here, colour there".++---++## 6. The world++Light from the upper right, always: lit side, shadow side, a cast-shadow dab to the lower left of every plant and of the creature when it is low. Paper white is the brightest value and is LEFT: highlights, cloud tops, the rim of petals. Three greens by temperature. Aerial perspective: farther is paler, bluer, softer, no pencil.++### 6.1 RANUNCULUS, rendered true (the client)++Persian buttercup, *Ranunculus asiaticus*. Study real photographs before moving a point, and say which you used.++- **The head:** dozens of tissue-thin petals in tight, overlapping, concentric layers: a cupped rosette, rose-like but flatter and more orderly than a rose, never a pompom. Petals are smallest and most upright at the centre, largest, palest and slightly ruffled at the rim. Layers are OFFSET from each other, so no petal sits directly behind another.+- **The centre:** a tight green-yellow button. In a half-open bloom it is green and clasped; fully open it shows a small dark eye ringed with yellow.+- **How to paint it (this is the craft):** from the centre OUT, as short overlapping C-strokes circling the button, each ring larger and looser than the last. LEAVE SLIVERS OF BARE PAPER between strokes: those slivers are the petal edges, and they are what makes it read as layered tissue instead of a disc. Drop darker pigment into the gaps near the centre while wet (depth), let the outer petals stay pale with a hard dried rim, add one cool shadow wash over the side away from the sun. No outline round the head.+- **Rejected on sight:** concentric circles with regular scallops; a mathematical spiral; identical heads; petals as separate ovals arranged on a ring; straight stems.+- **Five views, hand-authored:** facing; three-quarter (an oval cup, inner layers seen as stacked crescents); profile (a cup on its stem, green sepals reflexed beneath); half-open; tight round BUD, nodding, clasped by sepals.+- **Stems:** tall, slender, faintly hairy, each with its own S-curve and thickness, often one main bloom plus a side bud. **Leaves:** low and basal, deeply cut, parsley-like, painted as a dark ferny mass at the foot of the clump.+- **Colours:** coral, blush white with a pink picotee edge, butter yellow, deep magenta, peach. They are the creature's own wing colours, which is why it goes to them (DIRECTOR).+- **The clump:** 9 heads and 5 buds, hand-placed at three heights and three depths, R1 to R4 chosen so the flight zig-zags right, left-behind-a-stem, down, up. Size: a full head is 700 units across, a little smaller than the creature.+- **LOD:** above 120 px everything above; 40 to 120 px three rings of strokes and the button; 14 to 40 px two tones and a centre dab; under 14 px one dab.++### 6.2 Everything else (as the approved still, with its open craft fixes)++Planes: P0 foreground fringe z -0.2 · P1 hero z 0 (the sheet, the ranunculus clump) · P2 z 1.0 (daisy drift) · P3 z 2.2 (poppies, cosmos, the touch-down poppy) · P4 z 3.5 (buttercups along the footpath) · P5 far field z 8 · P6 hills z 20 · P7 sky.++Supporting flowers, each with 4 views and LOD as above: oxeye daisy (paper white), field poppy, cosmos, buttercup (the ranunculus's wild cousin). About 14 hand-placed drift centres, seeded scatter inside each with falloff, three bare rests of plain grass.++**Changes to the approved still, flagged for the client:** the near flowers at about (540, 700), (440, 790), (815, 680), (920, 750) become RANUNCULUS so the clump we spent six bars on is recognisably in the last frame. Everything else in the still's composition stands: creature (440, 590), sheet lower left, sun upper right, signature lower right, horizon about y 410.++**Craft fixes already listed against the still, all still owed before motion:** (1) value range: the greens sit in one narrow band, push the hollows darker and the sunlit crests lighter; (2) drifts read as dot clouds, give near drifts real flower forms; (3) the sheet reads as a sticker or a lily pad: make it a rectangle in perspective with a curled corner, grass over its edges, a shadow under the curl; (4) the foreground is empty flat colour: P0/P1 grass clumps with thickness and cast shadows; (5) the signature letterforms (section 7).++**What moves, always:** gust fronts enter left on 540 and 855 and cross in 60 to 90 frames; idle sway between, per-clump periods 50 to 80 frames; clouds drift left; cloud shadows over the clump 600-690 and over the far field from 900; seed fluff from 345; the two whites 825-990; every visited flower dips and rebounds; wet paint spreading 5-120.++---++## 7. The signature (the client)++`alexgreenshpun.com`, signed like a watercolourist signs a corner. A signature, never a caption.+- Hand-authored brush strokes in `butterfly/finale/signature.ts` (control points, about 8 strokes), lowercase, connected, slight forward slant, baseline rising 2 degrees, uneven letter widths, loose descenders on g and p. LEGIBLE FIRST: it is a URL, the dot must read as a dot. The still's current letterforms do not pass this.+- Rigger brush, dilute warm grey-brown about `#5b5148`, width 1.3 to 2.2 px with pressure, pigment pooled at stroke ends, opacity 0.75 wet drying to 0.60.+- SCREEN space. Right edge of the last letter x = 1036, baseline y = 1034 at its left end, width 190 px, x-height 12 px, ascenders 19 px.+- Damp-brush lift 1140-1155 to make room (about 250 x 60 px, lightens the wash about 45 percent, faint backrun at its end). Written on, never faded: `alex` 1155-1160, `green` 1160-1170, `shpun` 1170-1175, the dot on 1175, `com` 1175-1185. Last stroke ends on **1185, with the DING**. Then 75 frames to read it.+- Check: readable at 100 percent, vanishes into the painting at thumbnail size. No underline, no flourish, no glow.++## 8. Score (pure JS, same shape as `score.ts`)++12/8. Act 1: music box, asks the question, ends unresolved on the fifth. Movement 2: the drop on local 5 is a single water-note; the motif returns slowed and warm under 5-240; from 240 (take-off) a bowed pad and a second voice; the answer resolves to the root as the meadow opens at 870; DING on local 1185.+**The tick becomes a pulse:** tick every 5 frames through 0-180, thinning across 180-240 as a felt wing-flutter takes each down-stroke; gone by 240. While it sips, one soft low pulse per beat (the heartbeat). Landings get a pluck on their beat. Every onset is a cue; assert sample index = `round(frame / 30 * 48000)`.++## 9. Engine work++1. `act2cues.ts` for this movement; riso/editorial tables retired to `legacy/`, nothing imports them.+2. **The water front:** progress along spars (arc length, reuse `nib()`), per-panel flood on arrival, ground lift clipped to the creature's silhouette plus a 6 px bleed, blue pigment rim at the front. Drop and crown splash.+3. **The sheet as a world object:** the Act 1 plate drawn into plane P1 via the existing view engine, cached at LOD steps, downscale only; a `blank` state that knocks the creature's silhouette out to bare paper; foreshortening on control points.+4. **Stepped-to-smooth motion blend** on the crank (5.2, 180-240).+5. Ranunculus: 5 views x colour variants, LOD, stems, leaves, dip and rebound.+6. Pose extension, flight paths, landing/sip/take-off states, proboscis.+7. Reuse as built: dolly planes, flora LOD, gusts, clouds, creature paint, signature, `deadair.mjs`.+If the macro (huge wet washes) or the last bars break 150 ms, cut blade and stroke counts before touching the look, and tell me.++## 10. Gates (stills first, I review each; under the no-collision protocol I review COPIES and return numbered fix lists through the client)++| Gate | Deliverable | Pass |+|---|---|---|+| **G-R ranunculus** (FIRST) | One sheet: the 5 views in 3 colours at full LOD, plus the clump composed at stage R with the creature perched on R1 | Craft review against 6.1. No motion before this passes |+| **G-M metamorphosis** | 6 stills: local 0, 5, 30, 60, 120, 210 | Frame 0 equals Act 1's final state at view M0. The water reads as water. Panel 2 home and blue. Realism per 5.7: every painted part is nameable anatomy at every sampled frame, never "gears here, colour there"; by 210 it is a complete, recognizable real butterfly with legs, clubbed antennae, venation, markings and an underside. Plus one PLATE still: the finished creature, dorsal and lateral side by side, as a naturalist plate |+| **G-S sheet** | 3 stills: local 270 (whole sheet with the blank), 320 (grass over its edges, foreshortening), 1080 (in the wide) | It is a sheet of paper, not a sticker. The blank reads as the absence of THIS butterfly |+| G-W wide | The approved still re-rendered with the five fixes and the ranunculus swap | The client re-approves the destination |+| G-MOTION | Contact sheet at one tile per beat (84) + MP4 | Tables 5.1 to 5.6 on the frame; landings and take-offs on their beats; camera keys within 2 percent |+| G-AIR | `tools/deadair.mjs` on the movement and the film | No identical consecutive frames; no 15-frame window under 0.5 percent changed area |+| G-FILM | `out/butterfly.mp4`, `dist/butterfly.html` | h264 + aac, 1800 frames, clean decode, draw median under 150 ms and p95 under 200 on one page, determinism on probe frames (hash, else above 45 dB) |++## 11. Open for the client (none blocks the build)++- O1. No riso wake (section 0). If you want one back, it costs a second bridge device and I would argue against it.+- O2. The join from Act 1 is a CUT to macro on the bar line. The alternative is a 30-frame push-in over the finished plate, which costs a full-plate redraw per frame.+- O3. Four near flowers on the approved still become ranunculus (6.2).+- O4. The two white butterflies, and the creature flying toward us at the end so it lands at the still's size.+- Act 1 is locked and approved, and it fails the dead-air check at its open (43 identical frames in the first seconds, per the gate). Two cue changes would fix it. The client's call whether to unlock it for that.+- O6. Length: 42 s for the coming-to-life, 60 s film. If it must be shorter, trim stage F and one ranunculus landing, never the macro or the ending.diff --git a/example/src/canvas-core/butterfly/act1cues.ts b/example/src/canvas-core/butterfly/act1cues.tsnew file mode 100644index 0000000..8f768ca--- /dev/null+++ b/example/src/canvas-core/butterfly/act1cues.ts@@ -0,0 +1,127 @@+// ACT 1, THE BLUEPRINT: 540 frames, 18 s, 36 beats at 120 bpm. A bare cyanotype sheet draws+// itself into PLATE I, the key goes in, the train starts, and for two beats the drawing is+// alive. Every frame number in the act is in this table and nowhere else: cuts on multiples of+// 15, events on multiples of 5 (triplet eighths, which is what an escapement sounds like).+import { EMPTY, Parts, PlateState } from "./plate";+import { BUBBLE } from "./parts";+import { View } from "./surface";+import { Train } from "./parts";++export type Ease = "linear" | "out" | "outBack" | "flick" | "inout";+export type Cue = { at: number; dur: number; id: string; ease?: Ease; amp?: number };++export const DURATION = 540, TICK0 = 240, TICK = 5;+export const SHOTS: [string, number, number][] = [+ ["sheet", 0, 60], /* the ground, the printed grid, the border rules itself */+ ["layout", 60, 120], /* construction: centre line, wing envelopes, thorax ellipse, then the title block is RULED */+ ["thorax", 120, 180], /* the housing, the broken-out window, the head and its coiled antennae */+ ["push", 180, 240], /* the camera moves in on the thorax while the going train seats inside it */+ ["detail", 240, 270], /* MATCH CUT: the bubble on the thorax becomes Detail B, full frame, and it ticks */+ ["pull", 270, 315], /* back out to the sheet */+ ["spars", 315, 360], /* four wing frames radiate from their hinges, port leading */+ ["skin", 360, 405], /* membrane panels fly home along their projection lines and are veined */+ ["notes", 405, 420], /* dimensions, balloons, notes, and MECHANICAL LEPIDOPTERA written last */+ ["wind", 420, 495], /* the key rides up the centre line and winds seven turns, then comes out */+ ["alive", 495, 525], /* it moves, and lifts off its own paper */+ ["plate", 525, 540], /* the finished plate, held */+];++// THE CAMERA. Keyframes of (frame, centre, zoom); two keys on the same frame are a CUT. The view+// is applied to control points through the transform stack, and line weight is compensated for+// the zoom in plate.ts, so a close shot is redrawn at size, never a magnified bitmap.+type Key = { at: number; cx: number; cy: number; z: number; ease: Ease };+const [BX, BY, BR] = BUBBLE(), DBX = 392, DBY = 898, DBR = 100, SCREEN = 330; /* the bubble and the Detail B circle land on the SAME screen circle: that is the cut */+export const CAM: Key[] = [+ { at: 0, cx: 540, cy: 540, z: 1, ease: "linear" },+ { at: 195, cx: 540, cy: 540, z: 1, ease: "inout" },+ { at: 240, cx: BX, cy: BY, z: SCREEN / BR, ease: "linear" }, /* slow push in on the thorax as the wheels seat */+ { at: 240, cx: DBX, cy: DBY, z: SCREEN / DBR, ease: "linear" }, /* CUT */+ { at: 270, cx: DBX, cy: DBY, z: (SCREEN / DBR) * 1.045, ease: "out" }, /* it breathes in while the train runs */+ { at: 315, cx: 540, cy: 500, z: 1.12, ease: "linear" }, /* held here while the wings and the body are drawn: a still camera lets the drawing work */+ { at: 405, cx: 540, cy: 500, z: 1.12, ease: "inout" },+ { at: 420, cx: 540, cy: 540, z: 1, ease: "linear" }, /* wide again, on the frame the key starts to rise */+ { at: 540, cx: 540, cy: 540, z: 1, ease: "linear" },+];++export const CUES: Cue[] = [+ { at: 15, dur: 30, id: "grid", ease: "out" }, /* printed paper, so it may fade: the only fade in the act */+ { at: 30, dur: 30, id: "border" },+ { at: 60, dur: 45, id: "construct" }, { at: 300, dur: 30, id: "erase" }, /* construction is UN-drawn, because a construction line is erased and never faded */+ { at: 105, dur: 45, id: "cartouche" }, { at: 355, dur: 65, id: "lettering" }, /* the box is ruled early, the lettering is the last job: MECHANICAL LEPIDOPTERA is written just before the key goes in */+ { at: 120, dur: 45, id: "shell" }, { at: 160, dur: 40, id: "head" },+ { at: 165, dur: 60, id: "detailPlate" }, { at: 180, dur: 45, id: "detail" }, { at: 200, dur: 35, id: "window" }, { at: 185, dur: 30, id: "bubble" }, /* the bubble is rung on the thorax before the camera goes in, and it is the circle the cut matches */ { at: 385, dur: 25, id: "detail.notes" }, /* the tooth counts are notes, so they wait for the notes phase */+ { at: 300, dur: 45, id: "wing.LF" }, { at: 315, dur: 45, id: "wing.LH" }, { at: 330, dur: 45, id: "wing.RF" }, { at: 345, dur: 45, id: "wing.RH" }, /* port leads, starboard follows: a right-handed draftsman works left to right */+ { at: 340, dur: 40, id: "skin.LF" }, { at: 355, dur: 40, id: "skin.LH" }, { at: 370, dur: 40, id: "skin.RF" },+ { at: 350, dur: 50, id: "abdomen" },+ { at: 365, dur: 45, id: "key.draw" }, { at: 360, dur: 20, id: "axis" }, { at: 370, dur: 50, id: "furniture" }, { at: 365, dur: 30, id: "section" }, { at: 375, dur: 20, id: "scale" }, { at: 380, dur: 15, id: "note" }, { at: 380, dur: 30, id: "list" },+ { at: 420, dur: 15, id: "key.rise", ease: "outBack" }, { at: 435, dur: 35, id: "key.wind", ease: "linear" }, { at: 475, dur: 10, id: "key.out", ease: "out" },+ { at: 485, dur: 10, id: "twitch", ease: "flick", amp: 0.14 },+ { at: 495, dur: 15, id: "flap1", ease: "flick", amp: 0.55 }, { at: 510, dur: 10, id: "flap2", ease: "flick", amp: 0.62 }, { at: 520, dur: 5, id: "flap3", ease: "flick", amp: 0.45 },+ { at: 495, dur: 15, id: "shadow.out", ease: "out" }, { at: 510, dur: 15, id: "shadow.in", ease: "out" },+ { at: 495, dur: 30, id: "boil" },+];++const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (p: number, e: Ease = "linear") => (e === "inout" ? (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2) : e === "out" ? 1 - (1 - p) ** 3 : e === "outBack" ? 1 + 1.7 * (p - 1) ** 3 + 0.7 * (p - 1) ** 2 : e === "flick" ? (p < 0.35 ? Math.sin((p / 0.35) * Math.PI / 2) : Math.cos(((p - 0.35) / 0.65) * Math.PI / 2)) : p);+const byId = new Map(CUES.map((c) => [c.id, c]));+const cue = (id: string) => { const c = byId.get(id); if (!c) throw new Error(`no cue '${id}'`); return c; };+export const at = (frame: number, id: string): number => { const c = cue(id); return ease(clamp((frame - c.at) / c.dur), c.ease); };+export const raw = (frame: number, id: string): number => { const c = cue(id); return clamp((frame - c.at) / c.dur); };++// the going train: one tooth of the escape wheel per tick, snapped over two frames with a+// one-frame recoil, and every other wheel geared off it by its tooth count+const STEP = [14 / 24, 26 / 24, 1, 1, 1];+export const advance = (frame: number): number => { if (frame < TICK0 + TICK) return 0; const t = Math.floor((frame - TICK0) / TICK), s = (frame - TICK0) % TICK; return t - 1 + STEP[s]; };+export const trainAt = (frame: number): Train => {+ const a = advance(frame), w = (Math.PI * 2) / 96, t = Math.floor((frame - TICK0) / TICK), s = (frame - TICK0) % TICK;+ const rocking = frame >= TICK0 + TICK && s === 0 ? 0 : 0.085 * (t % 2 ? 1 : -1); /* the fork passes through centre on the tick frame */+ return { centre: a * w, third: -a * w * (24 / 14), pinion: a * w * (24 / 8), escape: a * ((Math.PI * 2) / 15), fork: frame < TICK0 + TICK ? 0 : rocking };+};++// the camera at a frame: the last key at or before it, eased into the next+export const viewAt = (frame: number): View => {+ let i = 0; for (let j = 0; j < CAM.length; j++) if (CAM[j].at <= frame) i = j;+ const a = CAM[i], b = CAM[Math.min(CAM.length - 1, i + 1)];+ if (b.at <= a.at) return { cx: a.cx, cy: a.cy, zoom: a.z };+ const t = ease(clamp((frame - a.at) / (b.at - a.at)), a.ease), lz = Math.exp(Math.log(a.z) + (Math.log(b.z) - Math.log(a.z)) * t); /* zoom moves geometrically, or a push looks like it stalls at the end */+ const cx = a.cx + (b.cx - a.cx) * t, cy = a.cy + (b.cy - a.cy) * t;+ if (Math.abs(lz - 1) < 0.004 && Math.abs(cx - 540) < 2 && Math.abs(cy - 540) < 2) return { cx: 540, cy: 540, zoom: 1 }; /* snap the last hair of the move to true wide, or every finished part redraws for nothing */+ return { cx, cy, zoom: lz };+};++export const stateAt = (frame: number): PlateState => {+ const flap = ["twitch", "flap1", "flap2", "flap3"].reduce((f, id) => f - (cue(id).amp ?? 0) * at(frame, id), 1);+ const sh = 1 - at(frame, "shadow.in"), out = at(frame, "shadow.out") * sh, wind = raw(frame, "key.wind");+ const p: Parts = {+ ...EMPTY,+ grid: at(frame, "grid"), border: at(frame, "border"), construct: at(frame, "construct") * (1 - at(frame, "erase")),+ shell: at(frame, "shell"), head: at(frame, "head"), window: at(frame, "window"),+ detail: at(frame, "detail"), detailPlate: at(frame, "detailPlate"),+ wing: [at(frame, "wing.LH"), at(frame, "wing.RH"), at(frame, "wing.LF"), at(frame, "wing.RF")],+ skin: [at(frame, "skin.LH"), 0, at(frame, "skin.LF"), at(frame, "skin.RF")], /* starboard hindwing keeps its membrane omitted */+ abdomen: at(frame, "abdomen"), axis: at(frame, "axis"), key: at(frame, "key.draw"), note: at(frame, "note"), bubble: at(frame, "bubble"),+ furniture: at(frame, "furniture"), section: at(frame, "section"), scale: at(frame, "scale"), list: at(frame, "list"), cartouche: at(frame, "cartouche"), lettering: at(frame, "lettering"), detailNotes: at(frame, "detail.notes"),+ };+ return {+ wings: { flap, sweep: -0.2 * (1 - flap) }, /* a raised wing also rakes forward: the 57o sweep the plate dimensions */+ lift: 1, /* the starboard forewing panel that never comes home: the act ends on the approved plate */+ keyY: at(frame, "key.rise") * (1 - at(frame, "key.out")),+ keyTurn: wind >= 1 || wind <= 0 ? 0 : wind * 7 * Math.PI * 2, /* seven turns, one every five frames */+ train: trainAt(frame),+ shadow: [out * 10, out * 14],+ boil: at(frame, "boil") > 0 && raw(frame, "boil") < 1 ? 0.25 : 0,+ inkedBoil: 0, /* at the desk the finished furniture is dead still (spec 4): only the hero line breathes */+ boilIndex: Math.floor(frame / 5) % 4,+ p,+ view: viewAt(frame),+ };+};++// The grid is a rule, so it is checked, not trusted (spec 9, G1).+export const gridProblems = (): string[] => {+ const p: string[] = [];+ CUES.forEach((c) => { if (c.at % 5) p.push(`cue '${c.id}' starts on frame ${c.at}, not a multiple of 5`); if ((c.at + c.dur) % 5) p.push(`cue '${c.id}' ends on frame ${c.at + c.dur}, not a multiple of 5`); if (c.at + c.dur > DURATION) p.push(`cue '${c.id}' ends after the act`); });+ SHOTS.forEach(([id, a, b]) => { if (a % 15 || b % 15) p.push(`shot '${id}' cuts off the beat grid (${a}..${b})`); });+ if (TICK0 % 5) p.push(`the train starts on frame ${TICK0}, not a multiple of 5`);+ return p;+};diff --git a/example/src/canvas-core/butterfly/act2art.ts b/example/src/canvas-core/butterfly/act2art.tsnew file mode 100644index 0000000..fb19d92--- /dev/null+++ b/example/src/canvas-core/butterfly/act2art.ts@@ -0,0 +1,94 @@+// ACT 2, RISOGRAPH. The same creature, built a completely different way: no ruling pen, no+// section lines, no drafting furniture. Three spot inks on cream stock, each laid by its own+// drum pass. Volume is a halftone SCREEN whose dots change size with a tone function, edges are+// torn rather than ruled, and the plates never quite register, which is the charm of the machine.+//+// BLUE plate = the machine: body segments, head, wing ribs, rivets, the key, the imprint.+// PINK plate = the wings as screen gradients, the going train through the body, antennae, eyes.+// YELLOW plate = the sun behind it, and the lit side of the body. Overprints multiply.+import { Ctx, Gfx, P, oval, rng, tube } from "../core";+import { letter } from "../drafting";+import { INK, PAPER, cut, screen, smooth } from "../riso";+import { CX, CY, HEAD, K, KC, THORAX, Wing, cen, lerp } from "./geom";+import { Train } from "./parts";+import { inside } from "../riso";++const BLUE = INK.blue, PINK = INK.pink, YELLOW = INK.yellow;+export const SUN: [number, number, number] = [700, 290, 210]; // upper right, behind it, and it agrees with the finale's sun++// each abdominal segment is its own printed shape, with paper showing in the joints; `flex`+// is the ripple that runs down the body when it wakes+const seg = (i: number, flex = 0): P[] => { const segs = 7, y0 = 70, y1 = 238, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5, t0 = i / segs, t1 = (i + 1) / segs, g = 2.4, s = 1 + flex * 0.16, dy = flex * 5; /* FABLE review: 0.06 and 2.2 were invisible at viewing size, the wake second read as a still */+ return [[-hw(t0) * s + g, y0 + (y1 - y0) * t0 + g + dy], [hw(t0) * s - g, y0 + (y1 - y0) * t0 + g + dy], [hw(t1) * s - g, y0 + (y1 - y0) * t1 - g + dy], [-hw(t1) * s + g, y0 + (y1 - y0) * t1 - g + dy]].map(([x, y]) => [CX + x * K, CY + y * K] as P); };+const gearDisc = (cx: number, cy: number, r: number, teeth: number, ph: number, seed: number): P[] => { const rn = rng(seed), out: P[] = []; for (let i = 0; i < teeth * 2; i++) { const a = ph + (i / (teeth * 2)) * Math.PI * 2, rr = (i % 2 ? r * 0.82 : r) * (0.985 + rn() * 0.03); out.push([cx + Math.cos(a) * rr, cy + Math.sin(a) * rr]); } return out; };+const BODY: P[] = (() => { const segs = 7, y0 = 70, y1 = 238, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5, L: P[] = [], R: P[] = [];+ for (let i = 0; i <= 14; i++) { const t = i / 14, y = y0 + (y1 - y0) * t; L.push([CX - hw(t) * K, CY + y * K]); R.push([CX + hw(t) * K, CY + y * K]); }+ return [...THORAX.slice(0, 7), ...R, ...L.reverse(), ...THORAX.slice(7)]; })();+const antenna = (sd: number, q: number): P[] => { const a0: P = [CX + sd * 8 * K, CY - 127 * K], c = Math.cos(sd * q), s = Math.sin(sd * q), R = (p: P): P => [a0[0] + (p[0] - a0[0]) * c - (p[1] - a0[1]) * s, a0[1] + (p[0] - a0[0]) * s + (p[1] - a0[1]) * c];+ const a1 = R([CX + sd * 56 * K, CY - 206 * K]), a2 = R([CX + sd * 124 * K, CY - 246 * K]);+ return Array.from({ length: 9 }, (_, i) => { const t = i / 8; return lerp(lerp(a0, a1, t), lerp(a1, a2, t), t); }); };++export type BlueS = { key: number; flex: number[]; imprint: number };+export const bluePlate = (g: Gfx, w: Wing[], s: BlueS) => {+ const c = g.cur, fill = (pts: P[], col = BLUE, a = 1) => { g.mark(pts, 3); c.globalAlpha = a; c.fillStyle = col; g.path(c, pts); c.fill(); c.globalAlpha = 1; };+ w.forEach((wg) => { /* the wing frame: three ribs carry it, and they stay inside the membrane */+ const n = wg.ends.length, inset = smooth(wg.out.map((p) => lerp(p, cen(wg.out), 0.045))), ribs = [0, Math.max(1, (n - 1) >> 1), n - 2].filter((v, i, a) => a.indexOf(v) === i);+ c.save(); g.path(c, inset); c.clip();+ ribs.forEach((j, r) => { const a0 = r === 0 ? 0.04 : 0.1, a1 = r === 0 ? 0.95 : 0.82, line = Array.from({ length: 7 }, (_, q) => wg.spar(j, a0 + (q / 6) * (a1 - a0))); fill(cut(tube(line, r === 0 ? 6.5 : 5, 1.5))); });+ ribs.forEach((j, r) => { for (let q = 1; q <= (r === 0 ? 4 : 2); q++) { const t = r === 0 ? 0.16 + q * 0.19 : 0.3 + q * 0.2, p = wg.spar(j, t); fill(oval(p[0], p[1], r === 0 ? 3.6 : 2.8, r === 0 ? 3.6 : 2.8, 9), PAPER); } }); /* rivets are holes in the ink: riso cannot print white, it leaves the sheet */+ c.restore();+ fill(cut(oval(wg.h[0], wg.h[1], 13, 13, 12))); fill(oval(wg.h[0], wg.h[1], 4.5, 4.5, 9), PAPER);+ });+ for (let i = 0; i < 7; i++) fill(cut(seg(i, s.flex[i] ?? 0)));+ fill(cut(THORAX.map((p) => lerp(p, cen(THORAX), -0.06))));+ fill(cut(HEAD.map((p) => lerp(p, cen(HEAD), -0.08))));+ const sp: P = [CX, CY + 244 * K], sq: P = [CX, CY + 272 * K]; fill(cut(tube([sp, sq], 5, 5)));+ const dy = -38 * s.key; fill(cut(tube([[KC[0], KC[1] - 36 + dy], [KC[0], KC[1] + dy]], 4.6, 4.6))); [-1, 1].forEach((sd) => { fill(cut(oval(KC[0] + sd * 21, KC[1] + 3 + dy, 16, 21, 12))); fill(oval(KC[0] + sd * 21, KC[1] + 3 + dy, 7, 10, 10), PAPER); });+ if (s.imprint > 0) { letter(g, "MECHANICAL LEPIDOPTERA", 92, 966, { cap: 15, seed: 900, color: BLUE, w: 2.2, opacity: 0.92, progress: Math.min(1, s.imprint * 1.6) }); letter(g, "PLATE II - RISOGRAPH, THREE PASSES ON CREAM", 92, 992, { cap: 8.4, seed: 901, color: BLUE, w: 1.1, opacity: 0.8, progress: Math.max(0, s.imprint * 1.6 - 0.6) }); }+ c.save(); g.path(c, smooth(BODY)); c.clip(); /* the shadow lives INSIDE the body, or it is a smear */+ screen(g, { x0: CX - 70, y0: CY - 150, x1: CX + 70, y1: CY + 250 }, 5.2, 22, (x, y) => 0.9 * Math.max(0, (CX + 4 - x) / 34) * Math.max(0, 1 - Math.abs(y - CY - 30) / 260), BLUE); /* the sun is upper right, so the body's shadow side is to port */+ c.restore();+};++export type PinkS = { train: Train; wheels: number; panel2: number; quiver: [number, number]; proboscis: number; vel: number[] };+export const pinkPlate = (g: Gfx, w: Wing[], s: PinkS) => {+ const c = g.cur, fill = (pts: P[], col = PINK, a = 1) => { g.mark(pts, 3); c.globalAlpha = a; c.fillStyle = col; g.path(c, pts); c.fill(); c.globalAlpha = 1; };+ w.forEach((wg, i) => {+ const b = { x0: Math.min(...wg.out.map((p) => p[0])) - 6, y0: Math.min(...wg.out.map((p) => p[1])) - 6, x1: Math.max(...wg.out.map((p) => p[0])) + 6, y1: Math.max(...wg.out.map((p) => p[1])) + 6 };+ const R = Math.hypot(b.x1 - b.x0, b.y1 - b.y0) * 0.66, spars = wg.ends.map((_, j) => Array.from({ length: 7 }, (_, q) => wg.spar(j, q / 6)));+ const near = (x: number, y: number) => { let d = 1e9; for (const line of spars) for (const p of line) { const q = (p[0] - x) * (p[0] - x) + (p[1] - y) * (p[1] - y); if (q < d) d = q; } return Math.sqrt(d); };+ const swell = 1 + Math.min(0.55, (s.vel[i] ?? 0) * 3.2); /* dots SWELL with wing velocity: the riso answer to a smear frame */+ const hole = i === 3 && s.panel2 < 1 ? wg.panels[2] : null; /* panel 2 does not print with this pass */+ screen(g, b, 5.6, i < 2 ? 75 : 15, (x, y) => { if (hole && inside(hole, x, y)) return 0; const t = Math.min(1, Math.hypot(x - wg.h[0], y - wg.h[1]) / R), lead = Math.min(1, Math.max(0, (near(x, y) - 6) / 26)); return Math.min(1, (1 - t * 0.97) ** 1.25 * 1.15 * swell) * (0.4 + 0.6 * lead); }, PINK, smooth(wg.out));+ fill(cut(tube([...wg.out, wg.out[0]], 5.5, 5.5, false))); /* the margin: one heavy printed band */+ if (hole) { c.save(); c.globalCompositeOperation = "destination-out"; g.path(c, smooth(hole.map((q) => lerp(q, cen(hole), -0.06)))); c.fill(); c.globalCompositeOperation = "source-over"; c.restore(); } /* the sheet shows through where panel 2 has not printed yet */+ if (i === 3 && s.panel2 > 0) { const pn = wg.panels[2], pb = { x0: Math.min(...pn.map((p) => p[0])) - 4, y0: Math.min(...pn.map((p) => p[1])) - 4, x1: Math.max(...pn.map((p) => p[0])) + 4, y1: Math.max(...pn.map((p) => p[1])) + 4 };+ c.save(); g.path(c, smooth(pn)); c.clip(); screen(g, pb, 5.6, 15, (x, y) => 0.8 * s.panel2 * Math.min(1, Math.max(0, (near(x, y) - 6) / 22)), PINK); c.restore(); fill(cut(tube([...pn, pn[0]], 3.4, 3.4, false)), PINK, s.panel2); } /* it prints alone, a beat late, with no blue under it */+ });+ c.save(); c.globalCompositeOperation = "destination-out"; g.path(c, smooth(BODY)); c.fill(); g.path(c, smooth(HEAD)); c.fill(); c.globalCompositeOperation = "source-over"; c.restore(); /* knock the body out of the wing screens so the inks stay clean */+ if (s.wheels > 0) { const o = cen(THORAX), t = s.train; /* the going train printed straight through the body: two inks, so you can see inside the machine */+ ([[o[0] + 1, o[1] + 10, 27, 14, 0.2 + t.centre], [o[0] - 19, o[1] - 34, 16, 10, 0.5 + t.third], [o[0] + 22, o[1] - 24, 11, 8, 0.1 + t.pinion]] as number[][]).forEach(([x, y, r, teeth, ph], i) => { const q = Math.min(1, Math.max(0, s.wheels * 3 - i)); if (q <= 0) return; fill(gearDisc(x, y, r * q, teeth, ph, 700 + i)); fill(oval(x, y, r * q * 0.3, r * q * 0.3, 10), PAPER); fill(oval(x, y, r * q * 0.1, r * q * 0.1, 8)); }); }+ [-1, 1].forEach((sd, i) => { const a = antenna(sd, s.quiver[i]); fill(cut(tube(a, 3.6, 1.6))); fill(cut(oval(a[8][0], a[8][1], 9, 9, 10))); });+ if (s.proboscis > 0) { const pr: P = [CX, CY - 150 * K], turns = 3.2 - s.proboscis * 1.4, pts: P[] = []; for (let i = 0; i <= 40; i++) { const t = i / 40, a = 1.4 + t * turns * Math.PI * 2, rr = 1.5 + 10 * t * (1 + s.proboscis * 0.6); pts.push([pr[0] + Math.cos(a) * rr, pr[1] + Math.sin(a) * rr * 0.97]); } fill(cut(tube(pts, 2.6, 1.4, false))); } /* the hairspring uncoils to taste the air */+ [-1, 1].forEach((sd) => { fill(cut(oval(CX + sd * 17 * K, CY - 112 * K, 8, 10.5, 10))); fill(oval(CX + sd * 17 * K, CY - 113 * K, 3.4, 4.2, 9), PAPER); });+};++export const yellowPlate = (g: Gfx, w: Wing[], s: { sun: number; lit: number }) => {+ const c = g.cur, fill = (pts: P[], a = 1) => { g.mark(pts, 3); c.globalAlpha = a; c.fillStyle = YELLOW; g.path(c, pts); c.fill(); c.globalAlpha = 1; };+ if (s.sun > 0) { const [sx, sy, sr] = SUN, r = sr * (0.35 + 0.65 * s.sun); fill(cut(oval(sx, sy, r, r, 22)), 0.78); c.globalCompositeOperation = "destination-out"; c.fillStyle = "#000"; [smooth(BODY), smooth(HEAD)].forEach((k) => { g.path(c, k); c.fill(); }); c.globalCompositeOperation = "source-over"; } /* hand-cut sun disc, behind the creature, transparent ink so it prints last and reads first. FABLE review: the disc is KNOCKED OUT under the body, or blue x yellow turns the whole machine green and the pink train goes black */+ if (s.lit <= 0) return;+ c.save(); g.path(c, smooth(BODY)); c.clip();+ screen(g, { x0: CX - 70, y0: CY - 160, x1: CX + 70, y1: CY + 250 }, 5.2, 68, (x, y) => s.lit * 0.85 * Math.max(0, 1 - Math.abs(x - (CX + 14)) / 15) * Math.max(0, 1 - Math.abs(y - CY - 20) / 250), YELLOW); /* the sun is upper right, so the lit edge is a band, and the body stays the machine's colour */+ c.restore();+ c.save(); g.path(c, smooth(HEAD)); c.clip(); screen(g, { x0: CX - 40, y0: CY - 140, x1: CX + 40, y1: CY - 80 }, 5, 68, (x) => s.lit * 0.8 * Math.max(0, 1 - Math.abs(x - (CX + 12)) / 13), YELLOW); c.restore();+};++export const stock = (g: Gfx, W: number, H: number) => { const c = g.main, e = g.env, dw = Math.round(W * e.scale), dh = Math.round(H * e.scale); c.save(); c.setTransform(1, 0, 0, 1, 0, 0); c.fillStyle = PAPER; c.fillRect(0, 0, dw, dh); c.restore(); g.paper("coldpress", 0.3); };+export const marks = (g: Gfx, W: number, H: number, p: number, bars: number) => {+ if (p > 0) g.group("plain", () => { const c = g.cur, n = 4; g.touch(0, 0, W, H); c.strokeStyle = "#2a2a2a"; c.lineWidth = 1.1; [[30, 30], [W - 30, 30], [30, H - 30], [W - 30, H - 30]].forEach(([x, y], i) => { if (p * n < i) return; const q = Math.min(1, p * n - i); c.beginPath(); c.arc(x, y, 7 * q, 0, Math.PI * 2); c.moveTo(x - 13 * q, y); c.lineTo(x + 13 * q, y); c.moveTo(x, y - 13 * q); c.lineTo(x, y + 13 * q); c.stroke(); }); }, { alpha: 0.85 });+ [BLUE, PINK, YELLOW].forEach((col, i) => { const q = Math.min(1, Math.max(0, bars * 3 - i)); if (q <= 0) return; g.group("plain", () => { const c = g.cur, x = W / 2 - 52 + i * 36, y = H - 42; g.touch(x, y, x + 28, y + 16); c.fillStyle = col; c.fillRect(x, y, 28 * q, 16); }, { blend: "multiply", textures: ["risoSpeck"] }); });+};+export const grain = (g: Gfx) => { g.paper("paper", 0.3); g.paper("coldpress", 0.18); };+// the drum sweeps the sheet: everything above the roller line has been printed+export const rollerPath = (c: Ctx, W: number, H: number, r: number) => { const y = -50 + r * (H + 100); c.beginPath(); c.moveTo(-10, -10); c.lineTo(W + 10, -10); c.lineTo(W + 10, y); for (let x = W + 10; x >= -10; x -= 30) c.lineTo(x, y + Math.sin(x * 0.021 + 1.3) * 3.5 + Math.sin(x * 0.006) * 2.5); c.closePath(); return y; };+export const wetEdge = (c: Ctx, W: number, H: number, r: number, col: string) => { if (r <= 0 || r >= 1) return; const y = -50 + r * (H + 100); c.save(); c.globalAlpha = 0.5; c.strokeStyle = col; c.lineWidth = 6; c.beginPath(); for (let x = -10; x <= W + 10; x += 30) { const yy = y + Math.sin(x * 0.021 + 1.3) * 3.5 + Math.sin(x * 0.006) * 2.5; x === -10 ? c.moveTo(x, yy) : c.lineTo(x, yy); } c.stroke(); c.restore(); }; /* the ink is still wet at the roller line */diff --git a/example/src/canvas-core/butterfly/act2cues.ts b/example/src/canvas-core/butterfly/act2cues.tsnew file mode 100644index 0000000..c231001--- /dev/null+++ b/example/src/canvas-core/butterfly/act2cues.ts@@ -0,0 +1,116 @@+// ACT 2, RISOGRAPH: 360 frames, 12 s, 24 beats. It STIRS. Frame 0 is Act 1's last frame; the+// first drum pass wipes the blueprint off the sheet and replaces it with ink. Then three passes,+// a train that stalls and catches, a first twitch, a body that wakes, and full flutter.+// Nothing is ever still: there is no blank stock and no end hold.+import { P } from "../core";+import { RisoState } from "./act2plate";+import { Pose } from "./geom";+import { Train } from "./parts";+import { View } from "./surface";++export type Ease = "linear" | "out" | "inout" | "flick";+export type Cue = { at: number; dur: number; id: string; ease?: Ease; amp?: number };+export const DURATION = 360, TICK = 5, TRAIN0 = 60; // the train takes its first step when the pink plate lands+export const SHOTS: [string, number, number][] = [+ ["blue", 0, 30], /* the blue drum wipes the blueprint off the sheet */+ ["pink", 30, 60], /* the second pass lands badly out of register */+ ["jog", 60, 90], /* the operator nudges the sheet twice, and panel 2 prints alone and late */+ ["yellow", 90, 120], /* the sun, and the lit side of the body */+ ["catch", 120, 150], /* the gears stall, hang for two ticks, and catch with a double step */+ ["twitch", 150, 180], /* first wing twitch, port alone, starboard answering */+ ["wake", 180, 210], /* the body wakes: a ripple down the abdomen, both antennae sweeping */+ ["flaps", 210, 270], /* first real flaps, all four wings */+ ["lift", 270, 330], /* sustained flutter, and it lifts off the stock leaving a ghost */+ ["flutter", 330, 360],/* full amplitude, cut on the top of an up-stroke */+];++export const CUES: Cue[] = [+ { at: 0, dur: 25, id: "pass.blue", ease: "linear" }, { at: 0, dur: 25, id: "marks" }, { at: 10, dur: 25, id: "imprint" }, { at: 5, dur: 10, id: "bar1" },+ { at: 30, dur: 25, id: "pass.pink", ease: "linear" }, { at: 45, dur: 10, id: "wheels" }, { at: 45, dur: 10, id: "bar2" },+ { at: 60, dur: 15, id: "jog1", ease: "out" }, { at: 80, dur: 10, id: "jog2", ease: "out" }, { at: 75, dur: 10, id: "panel2", ease: "out" },+ { at: 90, dur: 25, id: "pass.yellow", ease: "linear" }, { at: 90, dur: 20, id: "sun", ease: "out" }, { at: 95, dur: 20, id: "lit" }, { at: 110, dur: 10, id: "bar3" },+ { at: 135, dur: 10, id: "quiver.port", ease: "flick", amp: 1 }, { at: 140, dur: 10, id: "quiver.star", ease: "flick", amp: 1 },+ { at: 150, dur: 10, id: "twitch.port", ease: "flick", amp: 0.14 }, { at: 165, dur: 10, id: "twitch.star", ease: "flick", amp: 0.14 },+ { at: 170, dur: 10, id: "proboscis", ease: "out" },+ { at: 180, dur: 35, id: "ripple" }, { at: 180, dur: 35, id: "sweep", ease: "flick", amp: 1 },+ { at: 210, dur: 15, id: "flap1", ease: "flick", amp: 0.4 }, { at: 225, dur: 15, id: "flap2", ease: "flick", amp: 0.55 }, { at: 240, dur: 10, id: "flap3", ease: "flick", amp: 0.62 },+ { at: 250, dur: 10, id: "flap4", ease: "flick", amp: 0.62 }, { at: 260, dur: 10, id: "flap5", ease: "flick", amp: 0.62 },+ { at: 270, dur: 10, id: "f1", ease: "flick", amp: 0.55 }, { at: 280, dur: 10, id: "f2", ease: "flick", amp: 0.55 }, { at: 290, dur: 10, id: "f3", ease: "flick", amp: 0.55 },+ { at: 300, dur: 10, id: "f4", ease: "flick", amp: 0.55 }, { at: 310, dur: 10, id: "f5", ease: "flick", amp: 0.55 }, { at: 320, dur: 10, id: "f6", ease: "flick", amp: 0.55 },+ { at: 330, dur: 10, id: "f7", ease: "flick", amp: 0.62 }, { at: 340, dur: 10, id: "f8", ease: "flick", amp: 0.62 }, { at: 350, dur: 10, id: "f9", ease: "inout", amp: 0.55 }, /* the last up-stroke, still rising when we cut */+ { at: 285, dur: 20, id: "lift", ease: "inout" }, { at: 285, dur: 15, id: "ghost" }, { at: 330, dur: 30, id: "ghost.shrink", ease: "out" },+];++const CAM: { at: number; cx: number; cy: number; z: number; ease: Ease }[] = [+ { at: 0, cx: 540, cy: 540, z: 1, ease: "linear" }, { at: 25, cx: 540, cy: 540, z: 1, ease: "linear" }, { at: 30, cx: 540, cy: 537, z: 1.012, ease: "inout" },+ { at: 60, cx: 540, cy: 470, z: 1.15, ease: "linear" }, { at: 120, cx: 540, cy: 466, z: 1.18, ease: "inout" }, /* creep */+ { at: 150, cx: 540, cy: 440, z: 1.22, ease: "linear" }, { at: 240, cx: 540, cy: 436, z: 1.25, ease: "inout" }, /* FABLE review: at 1.3 the resting wingtips kissed the frame edge (my spec's number, corrected there too) */+ { at: 270, cx: 540, cy: 420, z: 1.45, ease: "linear" }, { at: 330, cx: 540, cy: 416, z: 1.48, ease: "inout" },+ { at: 360, cx: 540, cy: 400, z: 1.6, ease: "linear" },+];++const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (p: number, e: Ease = "linear") => (e === "inout" ? (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2) : e === "out" ? 1 - (1 - p) ** 3 : e === "flick" ? (p < 0.35 ? Math.sin((p / 0.35) * Math.PI / 2) : Math.cos(((p - 0.35) / 0.65) * Math.PI / 2)) : p);+const byId = new Map(CUES.map((c) => [c.id, c]));+const cue = (id: string) => { const c = byId.get(id); if (!c) throw new Error(`no cue '${id}'`); return c; };+export const at = (frame: number, id: string) => { const c = cue(id); return ease(clamp((frame - c.at) / c.dur), c.ease); };++// THE TRAIN. It steps on the tick from 60, stalls at 120 with a 3 degree recoil, hangs for two+// ticks, and catches up with a double step at 130.+const STEP = [14 / 24, 26 / 24, 1, 1, 1];+const teeth = (f: number): number => { if (f < TRAIN0 + TICK) return 0; const g = f >= 120 && f < 130 ? 119 : f, t = Math.floor((g - TRAIN0) / TICK), s = (g - TRAIN0) % TICK; return t - 1 + STEP[s]; };+export const trainAt = (f: number): Train => {+ const a = teeth(f), w = (Math.PI * 2) / 96, stalled = f >= 120 && f < 130, recoil = stalled ? -(3 * Math.PI) / 180 : 0;+ const t = Math.floor((f - TRAIN0) / TICK), s = (f - TRAIN0) % TICK, tremble = stalled ? ((f % 2) - 0.5) * 0.02 : 0;+ const rocking = f >= TRAIN0 + TICK && s === 0 ? 0 : 0.085 * (t % 2 ? 1 : -1);+ return { centre: a * w, third: -a * w * (24 / 14), pinion: a * w * (24 / 8), escape: a * ((Math.PI * 2) / 15) + recoil, fork: (f < TRAIN0 + TICK ? 0 : rocking) + tremble };+};++const viewAt = (frame: number): View => {+ let i = 0; for (let j = 0; j < CAM.length; j++) if (CAM[j].at <= frame) i = j;+ const a = CAM[i], b = CAM[Math.min(CAM.length - 1, i + 1)];+ if (b.at <= a.at) return { cx: a.cx, cy: a.cy, zoom: a.z };+ const t = ease(clamp((frame - a.at) / (b.at - a.at)), a.ease);+ return { cx: a.cx + (b.cx - a.cx) * t, cy: a.cy + (b.cy - a.cy) * t, zoom: Math.exp(Math.log(a.z) + (Math.log(b.z) - Math.log(a.z)) * t) };+};++// per-wing flap. Port leads starboard by 5 frames, and only the forewings twitch at first.+const FLAPS = ["flap1", "flap2", "flap3", "flap4", "flap5", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"];+const flapOf = (frame: number, wing: number): number => {+ const star = wing === 1 || wing === 3, f = frame - (star ? 2 : 0), fore = wing >= 2; /* FABLE review: a 5-frame lag on a 10-frame beat is ANTIPHASE, one side folded while the other is spread. 2 frames keeps it lopsided and together */+ let v = 1;+ if (fore) v -= (cue(star ? "twitch.star" : "twitch.port").amp ?? 0) * at(frame, star ? "twitch.star" : "twitch.port");+ FLAPS.forEach((id) => { v -= (cue(id).amp ?? 0) * at(f, id); });+ return clamp(v, 0.25, 1);+};+export const poseAt = (frame: number, wing: number): Pose => { const flap = flapOf(frame, wing); return { flap, sweep: -0.2 * (1 - flap) }; };++export const stateAt = (frame: number): RisoState => {+ const poses = [0, 1, 2, 3].map((i) => poseAt(frame, i));+ const vel = [0, 1, 2, 3].map((i) => Math.abs(flapOf(frame, i) - flapOf(frame - 1, i)));+ const j1 = at(frame, "jog1"), j2 = at(frame, "jog2");+ const OFF0: P = [17, -12], OFF1: P = [9.5, -6.5], OFF2: P = [4.5, -3];+ const lagN = Math.max(...vel) * 60; /* misregistration as follow-through: the pink plate lags a fast move and catches up */+ const reg: P = [OFF0[0] + (OFF1[0] - OFF0[0]) * j1 + (OFF2[0] - OFF1[0]) * j2 + lagN * 0.6, OFF0[1] + (OFF1[1] - OFF0[1]) * j1 + (OFF2[1] - OFF1[1]) * j2 + lagN * 0.4];+ const lift = at(frame, "lift"), sway = ((frame - 285) / 60) * Math.PI * 2;+ const L: P = lift > 0 ? [Math.sin(sway) * 7 * lift, -14 * lift + Math.sin(sway * 2) * 4 * lift] : [0, 0]; /* a slow figure of eight, the way a thing that has just learned to fly holds itself */+ const rip = at(frame, "ripple"), flex = Array.from({ length: 7 }, (_, i) => { const t = clamp((rip * 7 - i) * 1.6); return Math.sin(t * Math.PI) * (1 - i * 0.06); });+ const q = at(frame, "quiver.port"), qs = at(frame, "quiver.star"), sw = at(frame, "sweep");+ return {+ poses, view: viewAt(frame),+ blue: at(frame, "pass.blue"), pink: at(frame, "pass.pink"), yellow: at(frame, "pass.yellow"),+ reg, lift: L, ghost: at(frame, "ghost") * (1 - 0.6 * at(frame, "ghost.shrink")),+ marks: at(frame, "marks"), bars: (at(frame, "bar1") + at(frame, "bar2") + at(frame, "bar3")) / 3, imprint: at(frame, "imprint"),+ train: trainAt(frame), wheels: at(frame, "wheels"), panel2: at(frame, "panel2"),+ quiver: [q * 0.1 + sw * 0.26, qs * 0.1 + sw * 0.2], /* FABLE review: 3 to 5 degrees did not read; antennae are the first thing that says alive */ proboscis: at(frame, "proboscis"), key: 0,+ flex, vel, sun: at(frame, "sun"), lit: at(frame, "lit"),+ };+};+export const END_POSE = (): Pose[] => [0, 1, 2, 3].map((i) => poseAt(DURATION - 1, i)); // Act 3 opens on exactly this+export const gridProblems = (): string[] => {+ const p: string[] = [];+ CUES.forEach((c) => { if (c.at % 5) p.push(`cue '${c.id}' starts on frame ${c.at}, not a multiple of 5`); if ((c.at + c.dur) % 5) p.push(`cue '${c.id}' ends on frame ${c.at + c.dur}, not a multiple of 5`); if (c.at + c.dur > DURATION) p.push(`cue '${c.id}' ends after the act`); });+ CAM.forEach((k) => { if (k.at % 5) p.push(`camera key at frame ${k.at} is not a multiple of 5`); });+ SHOTS.forEach(([id, a, b]) => { if (a % 15 || b % 15) p.push(`shot '${id}' cuts off the beat grid (${a}..${b})`); });+ return p;+};diff --git a/example/src/canvas-core/butterfly/act2plate.ts b/example/src/canvas-core/butterfly/act2plate.tsnew file mode 100644index 0000000..1588627--- /dev/null+++ b/example/src/canvas-core/butterfly/act2plate.ts@@ -0,0 +1,48 @@+// THE PRESS. Three plates, one sheet, and the sheet underneath is still Act 1. Each plate is+// drawn on its own surface and printed with MULTIPLY at its own registration offset, so the+// offset can lag, jog and be corrected without redrawing a dot, and each drum pass is revealed+// by its own roller line at composite time.+import { Ctx, Env, Gfx, Medium, P } from "../core";+import { INK, LITHO } from "../riso";+import { FW, FW_H, FW_T, HW, HW_H, HW_T, Pose, REST, Wing, wingGeom } from "./geom";+import { BlueS, PinkS, bluePlate, grain, marks, pinkPlate, rollerPath, stock, wetEdge, yellowPlate } from "./act2art";+import { Train } from "./parts";+import { View, WIDE, blit, kk, part, slotOf } from "./surface";+import { stateAt as act1StateAt } from "./act1cues";+import { drawPlate } from "./plate";++export type RisoState = {+ poses: Pose[]; view: View;+ blue: number; pink: number; yellow: number; /* roller pass progress, 0 = not printed */+ reg: P; lift: P; ghost: number; marks: number; bars: number; imprint: number;+ train: Train; wheels: number; panel2: number; quiver: [number, number]; proboscis: number; key: number;+ flex: number[]; vel: number[]; sun: number; lit: number;+};+const nibFor = (z: number): Medium => (z === 1 ? LITHO : { ...LITHO, nib: (LITHO.nib * Math.pow(z, 0.35)) / z }); // weight tracks zoom^0.35, never the transform++export const drawRiso = (ctx: Ctx, env: Env, s: RisoState) => {+ const W = env.W, H = env.H, v = s.view, vk = kk(v.cx, v.cy, v.zoom), med = nibFor(v.zoom);+ const P4 = (p: Pose[]): Wing[] => [wingGeom(-1, HW, HW_H, HW_T, 2000, p[0]), wingGeom(1, HW, HW_H, HW_T, 2600, p[1]), wingGeom(-1, FW, FW_H, FW_T, 1000, p[2]), wingGeom(1, FW, FW_H, FW_T, 1600, p[3])];+ const w = P4(s.poses), pk = kk(...s.poses.flatMap((p) => [p.flap, p.sweep]));+ const pt = (name: string, key: string, fn: (g: Gfx) => void) => part(env, med, name, key + "|" + vk, 0, fn, v);++ const sheet = pt("stock", "stock", (g) => stock(g, W, H));+ const blueS: BlueS = { key: s.key, flex: s.flex, imprint: s.imprint };+ const blue = s.blue > 0 ? pt("blue", kk("b", pk, s.key, s.imprint, ...s.flex), (g) => bluePlate(g, w, blueS)) : null;+ const pinkS: PinkS = { train: s.train, wheels: s.wheels, panel2: s.panel2, quiver: s.quiver, proboscis: s.proboscis, vel: s.vel };+ const pink = s.pink > 0 ? pt("pink", kk("p", pk, s.wheels, s.panel2, s.train.centre, s.train.escape, s.quiver[0], s.quiver[1], s.proboscis, ...s.vel.map((x) => Math.round(x * 40) / 40)), (g) => pinkPlate(g, w, pinkS)) : null;+ const yellow = s.yellow > 0 ? pt("yellow", kk("y", s.sun, s.lit), (g) => yellowPlate(g, w, { sun: s.sun, lit: s.lit })) : null;+ const furn = pt("marks", kk(s.marks, s.bars), (g) => marks(g, W, H, s.marks, s.bars));+ /* the sheet underneath is Act 1's last frame: the transition is a drum pass over the blueprint */+ const under = s.blue < 1 ? part(env, med, "blueprint", "act1-539", 0, (g) => drawPlate(g.main, env, act1StateAt(539)), WIDE) : null;++ const pass = (r: number, draw: () => void) => { if (r <= 0) return; ctx.save(); if (r < 1) { ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); rollerPath(ctx, W, H, r); ctx.clip(); } draw(); ctx.restore(); };+ const L: P = s.lift, sc = env.scale;+ blit(ctx, under);+ pass(s.blue, () => { blit(ctx, sheet); if (s.ghost > 0 && blue) blit(ctx, blue, 0, 0, 0.3 * s.ghost, "multiply"); blit(ctx, blue, Math.round(L[0] * sc), Math.round(L[1] * sc), 1, "multiply"); }); /* the ghost is the print it left on the stock where it sat */+ pass(s.pink, () => blit(ctx, pink, Math.round((L[0] + s.reg[0]) * sc), Math.round((L[1] + s.reg[1]) * sc), 1, "multiply"));+ pass(s.yellow, () => blit(ctx, yellow, Math.round(L[0] * sc), Math.round(L[1] * sc), 1, "multiply"));+ ctx.save(); ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); wetEdge(ctx, W, H, s.blue, INK.blue); wetEdge(ctx, W, H, s.pink, INK.pink); wetEdge(ctx, W, H, s.yellow, INK.yellow); ctx.restore();+ blit(ctx, furn); /* register crosses and colour bars stay exactly where they were struck */+ if (s.blue > 0) { ctx.save(); if (s.blue < 1) { ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); rollerPath(ctx, W, H, s.blue); ctx.clip(); } grain(new Gfx(ctx, env, 0, LITHO)); ctx.restore(); } /* the cream stock only has tooth where the cream stock is: frame 0 must still be Act 1 exactly */+};diff --git a/example/src/canvas-core/butterfly/act3art.ts b/example/src/canvas-core/butterfly/act3art.tsnew file mode 100644index 0000000..9f17d15--- /dev/null+++ b/example/src/canvas-core/butterfly/act3art.ts@@ -0,0 +1,121 @@+// ACT 3, EDITORIAL CUTAWAY. The fourth construction: a page from a technical magazine. One+// confident thick-thin contour, flat limited colour laid with a swipe, paper cut faces with a+// hard section edge, and ONE accent, vermilion, on every part that MOVES and on nothing else.+// Force arrows and the travelling pulse are in the riso yellow, so the colour carries over.+import { Ctx, Gfx, P, arc, oval, rng, tube } from "../core";+import { letter, width } from "../drafting";+import { CX, CY, HEAD, K, THORAX, Wing, cen, lerp } from "./geom";+import { ARBOR, RC, armEnd, bellAngle, crankPin, outEnd, pivot } from "./linkage";+import { Train } from "./parts";++export const PAGE = "#f6f1e7", INK = "#2b2a28", HOUSE = "#8ca0a2", HOUSE2 = "#7a9092", FACE = "#e7e0d2", ACCENT = "#e2452b", PULSE = "#f2b705";+const swipeClip = (c: Ctx, g: Gfx, pts: P[], t: number, axis: "x" | "y" = "x") => { /* flat colour is LAID along the shape's long axis, never faded up */+ const xs = pts.map((p) => p[0]), ys = pts.map((p) => p[1]), x0 = Math.min(...xs) - 6, x1 = Math.max(...xs) + 6, y0 = Math.min(...ys) - 6, y1 = Math.max(...ys) + 6;+ c.beginPath(); if (axis === "x") c.rect(x0, y0, (x1 - x0) * t, y1 - y0); else c.rect(x0, y0, x1 - x0, (y1 - y0) * t); c.clip(); g.touch(x0, y0, x1, y1);+};+const flat = (g: Gfx, pts: P[], col: string, t = 1, axis: "x" | "y" = "x", alpha = 1) => { if (t <= 0) return; const c = g.cur; c.save(); swipeClip(c, g, pts, t, axis); c.globalAlpha = alpha; c.fillStyle = col; g.path(c, pts); c.fill(); c.restore(); };+// one brush-pen contour: thick where the form turns away from the light, thin on the lit side+export const contour = (g: Gfx, pts: P[], w0: number, w1: number, seed: number, t = 1, col = INK) => { if (t <= 0) return; const n = Math.max(2, Math.round(pts.length * Math.min(1, t))), s = pts.slice(0, n); if (s.length < 2) return; g.fill(tube(s, w0, w1, false), col, 0.96); };+export const hatchFace = (g: Gfx, pts: P[], seed: number, t = 1) => { /* a cut face is paper, with sparse section lines so it reads as CUT and not as a hole */+ if (t <= 0) return; const c = g.cur, r = rng(seed), b = { x0: Math.min(...pts.map((p) => p[0])), y0: Math.min(...pts.map((p) => p[1])), x1: Math.max(...pts.map((p) => p[0])), y1: Math.max(...pts.map((p) => p[1])) };+ c.save(); g.path(c, pts); c.clip(); g.touch(b.x0, b.y0, b.x1, b.y1);+ c.strokeStyle = INK; c.globalAlpha = 0.33; c.lineWidth = 1.1; const span = b.x1 - b.x0 + (b.y1 - b.y0), n = Math.floor((span / 13) * t);+ for (let i = 0; i < n; i++) { const o = b.x0 - (b.y1 - b.y0) + i * 13 + r() * 2; c.beginPath(); c.moveTo(o, b.y1 + 4); c.lineTo(o + (b.y1 - b.y0) + 8, b.y0 - 4); c.stroke(); }+ c.globalAlpha = 1; c.restore();+};+export const page = (g: Gfx, W: number, H: number) => { const c = g.main, e = g.env, dw = Math.round(W * e.scale), dh = Math.round(H * e.scale); c.save(); c.setTransform(1, 0, 0, 1, 0, 0); c.fillStyle = PAGE; c.fillRect(0, 0, dw, dh); c.restore(); g.paper("paper", 0.1); };++// ---------------------------------------------------------------- the creature, in section+export type A3 = { th: number; shell: number; faces: number; accent: number; wings: number; lift: P; bleed: number; ghostRod: number; arc: number; ghostSpar: number };+export const creature = (g: Gfx, w: Wing[], s: A3) => {+ const c = g.cur, acc = (i: number) => Math.min(1, Math.max(0, s.accent * 6 - i)); /* vermilion is laid part by part, in the order the force travels */+ w.forEach((wg, i) => { /* wings: flat pale colour, then the contour, then the leading spar in accent because it MOVES */+ flat(g, wg.out, "#dfe4e2", s.wings, i % 2 ? "x" : "x", 0.95);+ contour(g, [...wg.out, wg.out[0]], 3.4, 2.2, 400 + i, s.wings);+ const ribs = [0, Math.max(1, (wg.ends.length - 1) >> 1)];+ c.save(); g.path(c, wg.out); c.clip(); /* the frame belongs to the wing: never a ray across the page */+ ribs.forEach((j, r) => { const line = Array.from({ length: 7 }, (_, q) => wg.spar(j, 0.05 + (q / 6) * 0.9)), driven = r === 0 && i >= 2; g.fill(tube(line, driven ? 4.2 : 3, 1.3), driven ? ACCENT : INK, driven ? Math.max(0.15, acc(5)) : 0.85); }); /* the bell-crank drives the FOREWING leading spar: that is the part that moves */+ c.restore();+ });+ if (s.ghostSpar > 0) { const wg = w[2], gq = (t: number) => Array.from({ length: 7 }, (_, q) => wg.spar(0, 0.05 + (q / 6) * 0.9)).map((p) => [p[0], p[1] + t] as P); [-46, 0, 46].forEach((dy, i) => { if (s.ghostSpar * 3 < i) return; const pts = gq(dy); c.save(); c.setLineDash([7, 5]); c.strokeStyle = ACCENT; c.globalAlpha = 0.45; c.lineWidth = 1.6; c.beginPath(); pts.forEach(([x, y], k) => (k ? c.lineTo(x, y) : c.moveTo(x, y))); c.stroke(); c.setLineDash([]); c.globalAlpha = 1; c.restore(); g.touch(pts[0][0] - 10, pts[0][1] - 10, pts[6][0] + 10, pts[6][1] + 10); }); } /* where the spar is at the top, the middle and the bottom of its stroke */+ /* body: the housing slides off up-left on two projection dashes, leaving the section open */+ const off: P = [-72 * s.shell, -58 * s.shell], shell = THORAX.map(([x, y]) => [x + off[0], y + off[1]] as P);+ if (s.shell > 0.02) [2, 8].forEach((k, i) => { const a = THORAX[k], b: P = [a[0] + off[0], a[1] + off[1]]; c.save(); c.setLineDash([6, 5]); c.strokeStyle = INK; c.globalAlpha = 0.5; c.lineWidth = 1.2; c.beginPath(); c.moveTo(a[0], a[1]); c.lineTo(b[0], b[1]); c.stroke(); c.setLineDash([]); c.globalAlpha = 1; c.restore(); g.touch(Math.min(a[0], b[0]) - 4, Math.min(a[1], b[1]) - 4, Math.max(a[0], b[0]) + 4, Math.max(a[1], b[1]) + 4); });+ flat(g, shell, HOUSE, 1, "y"); contour(g, [...shell, shell[0]], 3.2, 2.4, 410);+ const inner = THORAX.map((p) => lerp(p, cen(THORAX), 0.1));+ flat(g, inner, FACE, s.faces, "x"); hatchFace(g, inner, 411, s.faces); contour(g, [...inner, inner[0]], 2.6, 1.8, 412, s.faces); /* the cut face, hard-edged */+ const abd: P[] = [];+ for (let i = 0; i <= 10; i++) { const t = i / 10, y = 70 + 168 * t, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push([CX + hw * K, CY + y * K]); }+ for (let i = 10; i >= 0; i--) { const t = i / 10, y = 70 + 168 * t, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push([CX - hw * K, CY + y * K]); }+ flat(g, abd, HOUSE2, 1, "y"); contour(g, [...abd, abd[0]], 3, 2.2, 413);+ flat(g, HEAD, HOUSE, 1, "x"); contour(g, [...HEAD, HEAD[0]], 3, 2.2, 414);+};++// ---------------------------------------------------------------- the mechanism, all of it true+export const mechanism = (g: Gfx, s: A3, t: Train, show: number) => {+ if (show <= 0) return;+ const c = g.cur, acc = (i: number) => Math.min(1, Math.max(0, s.accent * 6 - i));+ const wheel = (cx: number, cy: number, r: number, teeth: number, ph: number, seed: number, a: number) => { if (a <= 0) return; const pts: P[] = []; for (let i = 0; i < teeth * 2; i++) { const an = ph + (i / (teeth * 2)) * Math.PI * 2, rr = i % 2 ? r * 0.84 : r; pts.push([cx + Math.cos(an) * rr, cy + Math.sin(an) * rr]); } g.fill(pts, ACCENT, a); g.fill(oval(cx, cy, r * 0.68, r * 0.68, 14), PAGE, a); g.fill(tube([...oval(cx, cy, r * 0.68, r * 0.68, 14), [cx + r * 0.68, cy]], 1.5, 1.5, false), INK, a * 0.8); for (let k = 0; k < 4; k++) { const an = ph + (k / 4) * Math.PI * 2; g.fill(tube([[cx + Math.cos(an) * r * 0.12, cy + Math.sin(an) * r * 0.12], [cx + Math.cos(an) * r * 0.64, cy + Math.sin(an) * r * 0.64]], 2.4, 1.8), ACCENT, a); } g.fill(oval(cx, cy, r * 0.13, r * 0.13, 9), INK, a); }; /* a wheel is a rim, a web and four spokes, not a red disc */+ const br: P = [ARBOR[0] - 44, ARBOR[1] - 10];+ g.fill(oval(br[0], br[1], 26, 26, 18), ACCENT, acc(0) * 0.92); g.fill(oval(br[0], br[1], 21, 21, 16), PAGE, acc(0)); /* mainspring barrel */+ { const pts: P[] = []; for (let i = 0; i <= 56; i++) { const q = i / 56, a = 0.6 - t.centre * 0.25 + q * 4.2 * Math.PI * 2, rr = 3 + 17 * q; pts.push([br[0] + Math.cos(a) * rr, br[1] + Math.sin(a) * rr]); } g.fill(tube(pts, 1.9, 1.3, false), ACCENT, acc(0)); }+ wheel(ARBOR[0], ARBOR[1], 25, 16, 0.2 + t.centre, 420, acc(1)); /* centre wheel */+ wheel(ARBOR[0] + 34, ARBOR[1] - 30, 13, 10, 0.5 + t.third, 421, acc(1) * 0.9);+ wheel(ARBOR[0] + 52, ARBOR[1] + 4, 10, 8, 0.1 + t.pinion, 422, acc(1) * 0.9); /* escapement end of the train */+ const P0 = crankPin(s.th);+ g.fill(tube([ARBOR, P0], 3.6, 3.6), ACCENT, acc(2)); g.fill(oval(P0[0], P0[1], 4.6, 4.6, 10), ACCENT, acc(2)); /* the crank */+ [-1, 1].forEach((side) => {+ const Q = pivot(side), R = armEnd(side, s.th), S = outEnd(side, s.th), i = side < 0 ? 4 : 5;+ if (s.ghostRod > 0 && side < 0) [0, Math.PI / 2, Math.PI].forEach((ph, k) => { if (s.ghostRod * 3 < k) return; const gp = crankPin(ph), gr = armEnd(side, ph); c.save(); c.setLineDash([6, 4]); c.strokeStyle = ACCENT; c.globalAlpha = 0.4; c.lineWidth = 1.5; c.beginPath(); c.moveTo(gp[0], gp[1]); c.lineTo(gr[0], gr[1]); c.stroke(); c.setLineDash([]); c.globalAlpha = 1; c.restore(); g.touch(Math.min(gp[0], gr[0]) - 6, Math.min(gp[1], gr[1]) - 6, Math.max(gp[0], gr[0]) + 6, Math.max(gp[1], gr[1]) + 6); }); /* onion skin: the rod at three crank angles */+ g.fill(tube([P0, R], 3.2, 3.2), ACCENT, acc(3)); /* connecting rod */+ g.fill(tube([R, Q, S], 4.2, 4.2), ACCENT, acc(i)); g.fill(oval(Q[0], Q[1], 4.2, 4.2, 10), PAGE, acc(i)); /* bell-crank, pivot left as paper */+ });+ if (s.arc > 0) { const Q = pivot(-1), a0 = bellAngle(-1, 0), a1 = bellAngle(-1, Math.PI), pts = arc(Q[0], Q[1], 54, 54, a0, a0 + (a1 - a0) * s.arc, 12); g.fill(tube(pts, 1.8, 1.8, false), PULSE, 0.9); for (let i = 0; i <= 4; i++) { const a = a0 + (a1 - a0) * s.arc * (i / 4), p: P = [Q[0] + Math.cos(a) * 54, Q[1] + Math.sin(a) * 54], q: P = [Q[0] + Math.cos(a) * 61, Q[1] + Math.sin(a) * 61]; g.fill(tube([p, q], 1.5, 1.5), PULSE, 0.9); } } /* the stroke, measured */+};++// the pulse hops along the train, one wheel per tick: the force, made visible+export const pulse = (g: Gfx, s: { at: number; on: number }) => {+ if (s.on <= 0) return;+ const stops: P[] = [[ARBOR[0] - 44, ARBOR[1] - 10], ARBOR, crankPin(0), [ARBOR[0] + 34, ARBOR[1] - 30]];+ const i = Math.floor(s.at) % stops.length, j = (i + 1) % stops.length, f = s.at - Math.floor(s.at), p = lerp(stops[i], stops[j], f * f * (3 - 2 * f));+ g.fill(oval(p[0], p[1], 7.5, 7.5, 12), PULSE, 0.95 * s.on); g.fill(oval(p[0], p[1], 3.4, 3.4, 10), "#fff6d8", 0.9 * s.on);+};++// ---------------------------------------------------------------- the annotation+export type Label = { n: string; text: string; at: P; to: P; p: number };+export const labels = (g: Gfx, ls: Label[]) => ls.forEach((l, i) => {+ if (l.p <= 0) return;+ const q = (k: number) => Math.min(1, Math.max(0, l.p * 3 - k)), x0 = l.at[0];+ g.fill(oval(x0 - 11, l.at[1] - 4, 8.6, 8.6, 12), ACCENT, q(0)); letter(g, l.n, x0 - 11, l.at[1] - 0.4, { cap: 8.4, align: "center", seed: 470 + i, color: PAGE, w: 1.3, progress: q(0) });+ letter(g, l.text, x0 + 2, l.at[1] - 4.5, { cap: 9.5, seed: 480 + i, color: INK, w: 1.25, progress: q(1) });+ const a: P = [x0 + 2, l.at[1] + 5], b = l.to, t = q(2); if (t <= 0) return;+ g.fill(tube([a, lerp(a, b, t)], 1.1, 1.1), INK, 0.7); if (t >= 1) g.fill([b, [b[0] - 7, b[1] - 3], [b[0] - 6, b[1]], [b[0] - 7, b[1] + 3]], INK, 0.8);+});+export const caption = (g: Gfx, text: string, v: { cx: number; cy: number; zoom: number }, p: number) => { if (p <= 0) return; letter(g, text, v.cx, v.cy + 430 / v.zoom, { cap: 19 / v.zoom, align: "center", seed: 495, color: INK, w: 2.4 / v.zoom, progress: p }); }; /* written across the foot of the FRAME, at whatever zoom the camera is */+// a force arrow in the riso yellow: where the push goes next+export const force = (g: Gfx, a: P, b: P, p: number) => { if (p <= 0) return; const e = lerp(a, b, p), d = Math.atan2(e[1] - a[1], e[0] - a[0]); g.fill(tube([a, e], 3.4, 3.4), PULSE, 0.9); if (p >= 1) g.fill([b, [b[0] - Math.cos(d - 0.4) * 15, b[1] - Math.sin(d - 0.4) * 15], [b[0] - Math.cos(d) * 11, b[1] - Math.sin(d) * 11], [b[0] - Math.cos(d + 0.4) * 15, b[1] - Math.sin(d + 0.4) * 15]], PULSE, 0.95); };+// the explainer's one intervention: panel 2, pressed home, in an inset+export const inset = (g: Gfx, wg: Wing, p: number, seat: number, v: { cx: number; cy: number; zoom: number }) => {+ if (p <= 0) return;+ const c = g.cur, C: P = [v.cx + 330 / v.zoom, v.cy - 330 / v.zoom], R = (90 * Math.min(1, p * 1.4)) / v.zoom;+ g.fill(oval(C[0], C[1], R, R, 22), PAGE, 1); g.fill(tube([...oval(C[0], C[1], R, R, 22), [C[0] + R, C[1]]], 2.6 / v.zoom, 2.6 / v.zoom, false), INK, 0.9);+ if (p < 0.5) return;+ const pn = wg.panels[2], pc = cen(pn), k = R / 150, T = (q: P): P => [C[0] + (q[0] - pc[0]) * k, C[1] + (q[1] - pc[1]) * k];+ c.save(); g.path(c, oval(C[0], C[1], R - 3, R - 3, 22)); c.clip();+ const lift = 1 - seat, up = pn.map(([x, y]) => T([x + 58 * lift, y - 60 * lift]));+ if (lift > 0.02) [0, 2, 4, 6].forEach((j) => { const a = T(pn[j]), b = up[j]; c.save(); c.setLineDash([5, 4]); c.strokeStyle = ACCENT; c.globalAlpha = 0.6; c.lineWidth = 1.3; c.beginPath(); c.moveTo(a[0], a[1]); c.lineTo(b[0], b[1]); c.stroke(); c.setLineDash([]); c.globalAlpha = 1; c.restore(); });+ g.fill(up, "#dfe4e2", 0.95); g.fill(tube([...up, up[0]], 2.2 / v.zoom, 2.2 / v.zoom, false), ACCENT, 0.9);+ c.restore(); g.touch(C[0] - R - 6, C[1] - R - 6, C[0] + R + 6, C[1] + R + 6);+};+export const cutLine = (g: Gfx, p: number) => { /* the dashed cut, struck across the body with a scissor mark */+ if (p <= 0) return; const c = g.cur, y = CY - 40, x0 = CX - 210, x1 = CX + 210, x = x0 + (x1 - x0) * p;+ c.save(); c.setLineDash([12, 7]); c.strokeStyle = INK; c.lineWidth = 1.8; c.globalAlpha = 0.8; c.beginPath(); c.moveTo(x0, y); c.lineTo(x, y); c.stroke(); c.setLineDash([]); c.globalAlpha = 1; c.restore(); g.touch(x0 - 6, y - 22, x1 + 6, y + 22);+ const sx = x; g.fill(tube([[sx - 9, y - 7], [sx + 7, y + 5]], 1.8, 1.8), INK, 0.9); g.fill(tube([[sx - 9, y + 7], [sx + 7, y - 5]], 1.8, 1.8), INK, 0.9); g.fill(oval(sx - 11, y - 9, 3.4, 3.4, 9), INK, 0.9); g.fill(oval(sx - 11, y + 9, 3.4, 3.4, 9), INK, 0.9);+};+// the accent starts to run wet at its edges: the watercolour arriving+export const bleed = (g: Gfx, w: Wing[], s: A3) => {+ if (s.bleed <= 0) return;+ const c = g.cur, r = 6 * s.bleed;+ [-1, 1].forEach((side) => { const Q = pivot(side), R = armEnd(side, s.th); c.globalAlpha = 0.3 * s.bleed; g.fill(tube([crankPin(s.th), R], 3.2 + r, 3.2 + r), ACCENT, 0.3 * s.bleed); g.fill(oval(Q[0], Q[1], 10 + r, 10 + r, 12), ACCENT, 0.22 * s.bleed); c.globalAlpha = 1; });+ g.fill(oval(ARBOR[0], ARBOR[1], 27 + r, 27 + r, 18), ACCENT, 0.2 * s.bleed);+};diff --git a/example/src/canvas-core/butterfly/act3cues.ts b/example/src/canvas-core/butterfly/act3cues.tsnew file mode 100644index 0000000..04c4925--- /dev/null+++ b/example/src/canvas-core/butterfly/act3cues.ts@@ -0,0 +1,113 @@+// ACT 3, EDITORIAL CUTAWAY: 360 frames, 12 s, 24 beats. UNDERSTOOD. The flight stops, the+// housing comes off, and the mechanism is run in slow motion, one crank step per tick, while+// the camera follows the force from the spring to the wing. Then it speeds back up and leaves.+import { P } from "../core";+import { EditState } from "./act3plate";+import { Pose, THORAX, cen } from "./geom";+import { ARBOR, crankFor, crankPin, flapOf, pivot } from "./linkage";+import { Train } from "./parts";+import { View } from "./surface";+import { END_POSE } from "./act2cues";++export type Ease = "linear" | "out" | "inout" | "outBack";+export type Cue = { at: number; dur: number; id: string; ease?: Ease };+export const DURATION = 360, TICK = 5, CRANK0 = 30;+export const SHOTS: [string, number, number][] = [+ ["freeze", 0, 30], /* the only silence in the film, and the housing comes off */+ ["spring", 30, 120], /* station A: mainspring and going train */+ ["crank", 120, 210], /* station B: round becomes back-and-forth */+ ["wing", 210, 285], /* station C: the wing answers, and panel 2 is pressed home */+ ["whole", 285, 315], /* cause and effect in one frame */+ ["speed", 315, 345], /* it speeds back up and lifts off its own diagram */+ ["leave", 345, 360], /* pushed in on the thorax, the accent bleeding wet: the watercolour arriving */+];+export const CUES: Cue[] = [+ { at: 0, dur: 10, id: "cut" }, { at: 10, dur: 20, id: "shell", ease: "outBack" }, { at: 10, dur: 20, id: "faces" }, { at: 15, dur: 30, id: "accent" },+ { at: 45, dur: 10, id: "l1" }, { at: 50, dur: 10, id: "rot" }, { at: 75, dur: 10, id: "l2" }, { at: 90, dur: 10, id: "l3" }, { at: 105, dur: 10, id: "l4" },+ { at: 150, dur: 30, id: "ghostRod" }, { at: 165, dur: 10, id: "l5" }, { at: 180, dur: 10, id: "l6" }, { at: 190, dur: 10, id: "cap" },+ { at: 240, dur: 20, id: "arc" }, { at: 240, dur: 20, id: "ghostSpar" }, { at: 255, dur: 10, id: "l7" }, { at: 265, dur: 10, id: "l8" },+ { at: 270, dur: 15, id: "inset" }, { at: 275, dur: 10, id: "seat", ease: "outBack" },+ { at: 300, dur: 15, id: "shellBack", ease: "out" },+ { at: 330, dur: 15, id: "lift", ease: "out" }, { at: 330, dur: 15, id: "shadow", ease: "out" }, { at: 350, dur: 10, id: "bleed" },+ { at: 60, dur: 60, id: "pulse" }, { at: 120, dur: 90, id: "pulse2" },+];+const ARB = ARBOR, PV = pivot(-1), TC = cen(THORAX);+const CAM: { at: number; cx: number; cy: number; z: number; ease: Ease }[] = [+ { at: 0, cx: 540, cy: 400, z: 1.6, ease: "inout" }, { at: 30, cx: 540, cy: 400, z: 1.68, ease: "inout" }, /* the freeze still creeps: nothing in this film is nailed down */+ { at: 60, cx: ARB[0], cy: ARB[1] + 8, z: 3.2, ease: "inout" }, { at: 120, cx: ARB[0] + 4, cy: ARB[1] + 10, z: 3.4, ease: "inout" },+ { at: 135, cx: (ARB[0] + PV[0]) / 2, cy: (ARB[1] + PV[1]) / 2 + 6, z: 3.2, ease: "inout" }, { at: 210, cx: (ARB[0] + PV[0]) / 2 - 4, cy: (ARB[1] + PV[1]) / 2 + 8, z: 3.32, ease: "inout" },+ { at: 225, cx: PV[0] - 6, cy: PV[1] + 4, z: 3.0, ease: "inout" }, { at: 285, cx: PV[0] - 10, cy: PV[1] + 2, z: 3.1, ease: "inout" },+ { at: 315, cx: 540, cy: 440, z: 1.15, ease: "out" }, { at: 345, cx: 540, cy: 434, z: 1.19, ease: "inout" },+ { at: 360, cx: TC[0], cy: TC[1] - 6, z: 3.2, ease: "inout" }, /* the thorax again, the film's rhyme with Act 1 */+];+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (p: number, e: Ease = "linear") => (e === "inout" ? (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2) : e === "out" ? 1 - (1 - p) ** 3 : e === "outBack" ? 1 + 1.7 * (p - 1) ** 3 + 0.7 * (p - 1) ** 2 : p);+const byId = new Map(CUES.map((c) => [c.id, c]));+const cue = (id: string) => { const c = byId.get(id); if (!c) throw new Error(`no cue '${id}'`); return c; };+export const at = (frame: number, id: string) => { const c = cue(id); return ease(clamp((frame - c.at) / c.dur), c.ease); };++// THE CRANK. Slow motion is one twenty-fourth of a revolution per tick, snapped over two frames+// like the escapement that drives it. It doubles at 315, again at 325, and runs free from 335.+const STEP = [14 / 24, 26 / 24, 1, 1, 1], TH0 = crankFor(END_POSE()[2].flap);+const REV = Math.PI * 2, TH: number[] = (() => {+ const out: number[] = []; let th = TH0;+ const stepped = (f: number, from: number, per: number) => { const t = Math.floor((f - from) / TICK), s = (f - from) % TICK; return t < 1 ? 0 : (t - 1 + STEP[s]) * per; };+ let base = TH0, b315 = 0, b325 = 0, b335 = 0;+ for (let f = 0; f < DURATION; f++) {+ if (f < CRANK0) th = TH0;+ else if (f < 315) th = base + stepped(f, CRANK0, REV / 24);+ else if (f < 325) { if (!b315) b315 = base + stepped(315, CRANK0, REV / 24); th = b315 + stepped(f, 315, REV / 12); }+ else if (f < 335) { if (!b325) b325 = b315 + stepped(325, 315, REV / 12); th = b325 + stepped(f, 325, REV / 6); }+ else { if (!b335) b335 = b325 + stepped(335, 325, REV / 6); th = b335 + ((f - 335) * REV) / 10; } /* life speed: a beat every ten frames */+ out.push(th);+ }+ return out;+})();+export const thAt = (f: number) => TH[Math.max(0, Math.min(DURATION - 1, f))];+const trainAt = (f: number): Train => { const th = thAt(f) - TH0, a = th / REV; return { centre: th, third: -a * REV * (24 / 14) * 0.25, pinion: a * REV * (24 / 8) * 0.25, escape: a * REV * 1.2, fork: 0.085 * (Math.floor(f / TICK) % 2 ? 1 : -1) }; };++const viewAt = (frame: number): View => {+ let i = 0; for (let j = 0; j < CAM.length; j++) if (CAM[j].at <= frame) i = j;+ const a = CAM[i], b = CAM[Math.min(CAM.length - 1, i + 1)];+ if (b.at <= a.at) return { cx: a.cx, cy: a.cy, zoom: a.z };+ const t = ease(clamp((frame - a.at) / (b.at - a.at)), a.ease);+ return { cx: a.cx + (b.cx - a.cx) * t, cy: a.cy + (b.cy - a.cy) * t, zoom: Math.exp(Math.log(a.z) + (Math.log(b.z) - Math.log(a.z)) * t) };+};+const poseAt = (frame: number): Pose[] => {+ if (frame < CRANK0) return END_POSE(); /* the freeze holds Act 2's last frame exactly */+ const th = thAt(frame), fp = flapOf(-1, th), fs = flapOf(1, th);+ return [-1, 1, -1, 1].map((side, i) => { const f = side < 0 ? fp : fs; return { flap: f, sweep: -0.2 * (1 - f) }; });+};+export const stateAt = (frame: number): EditState => {+ const th = thAt(frame), P0 = crankPin(th), R = pivot(-1);+ const L = (n: string, text: string, at: P, to: P, id: string): { n: string; text: string; at: P; to: P; p: number } => ({ n, text, at, to, p: at2(frame, id) });+ const shell = at(frame, "shell") * (1 - at(frame, "shellBack"));+ const lift = at(frame, "lift"), sh = at(frame, "shadow");+ return {+ view: viewAt(frame), poses: poseAt(frame), th, train: trainAt(frame), mech: at(frame, "accent") > 0 ? 1 : 0,+ art: { th, shell, faces: at(frame, "faces") * (1 - at(frame, "shellBack")), accent: at(frame, "accent"), wings: 1, lift: [0, 0], bleed: at(frame, "bleed"), ghostRod: at(frame, "ghostRod"), arc: at(frame, "arc"), ghostSpar: at(frame, "ghostSpar") },+ cut: at(frame, "cut"),+ labels: [+ L("1", "MAINSPRING", [ARB[0] - 158, ARB[1] - 22], [ARB[0] - 62, ARB[1] - 16], "l1"),+ L("2", "GOING TRAIN", [ARB[0] + 72, ARB[1] - 102], [ARB[0] + 32, ARB[1] - 34], "l2"),+ L("3", "ESCAPEMENT", [ARB[0] + 88, ARB[1] + 74], [ARB[0] + 54, ARB[1] + 8], "l3"),+ L("4", "24 : 8", [ARB[0] + 112, ARB[1] + 10], [ARB[0] + 40, ARB[1] - 6], "l4"),+ L("5", "CRANK", [ARB[0] - 152, ARB[1] + 74], [P0[0], P0[1]], "l5"),+ L("6", "CONN. ROD", [ARB[0] - 44, ARB[1] + 136], [(P0[0] + R[0]) / 2, (P0[1] + R[1]) / 2 + 6], "l6"),+ L("7", "BELL-CRANK", [R[0] - 152, R[1] - 84], [R[0] - 14, R[1] - 8], "l7"),+ L("8", "WING ROOT", [R[0] + 34, R[1] + 100], [R[0] + 14, R[1] + 18], "l8"),+ ],+ caption: ["ROUND BECOMES BACK-AND-FORTH", at(frame, "cap")],+ pulseAt: (at(frame, "pulse") * 4 + at(frame, "pulse2") * 12) % 4, pulseOn: frame >= 60 && frame < 215 ? 1 : 0,+ forceP: at(frame, "rot"), inset: at(frame, "inset"), seat: at(frame, "seat"),+ lift: [0, -30 * lift], shadow: [10 * sh, 14 * sh],+ };+};+const at2 = (frame: number, id: string) => at(frame, id);+export const gridProblems = (): string[] => {+ const p: string[] = [];+ CUES.forEach((c) => { if (c.at % 5) p.push(`cue '${c.id}' starts on frame ${c.at}, not a multiple of 5`); if ((c.at + c.dur) % 5) p.push(`cue '${c.id}' ends on frame ${c.at + c.dur}, not a multiple of 5`); if (c.at + c.dur > DURATION) p.push(`cue '${c.id}' ends after the act`); });+ CAM.forEach((k) => { if (k.at % 5) p.push(`camera key at frame ${k.at} is not a multiple of 5`); });+ SHOTS.forEach(([id, a, b]) => { if (a % 15 || b % 15) p.push(`shot '${id}' cuts off the beat grid (${a}..${b})`); });+ return p;+};diff --git a/example/src/canvas-core/butterfly/act3plate.ts b/example/src/canvas-core/butterfly/act3plate.tsnew file mode 100644index 0000000..900c858--- /dev/null+++ b/example/src/canvas-core/butterfly/act3plate.ts@@ -0,0 +1,38 @@+// THE PAGE. Editorial cutaway: the art on one surface, the annotation on another, so labels can+// be written while the mechanism runs without redrawing the mechanism, and the camera can push+// in on either without a bitmap ever being scaled up.+import { Ctx, Env, Gfx, Medium, P, PENCIL } from "../core";+import { FW, FW_H, FW_T, HW, HW_H, HW_T, Pose, Wing, wingGeom } from "./geom";+import { A3, Label, bleed, caption, creature, cutLine, force, inset, labels, mechanism, page, pulse } from "./act3art";+import { Train } from "./parts";+import { View, blit, kk, part } from "./surface";++export type EditState = {+ view: View; poses: Pose[]; th: number; train: Train; art: A3;+ cut: number; labels: Label[]; caption: [string, number]; pulseAt: number; pulseOn: number;+ forceP: number; inset: number; seat: number; lift: P; shadow: [number, number]; mech: number;+};+const BRUSH: Medium = { nib: 1, taper: 0.5, pressure: 0.5, retrace: false, wobble: 0.35, rough: 0.5 }; // a brush pen: it swells, it does not scratch+const nibFor = (z: number): Medium => (z === 1 ? BRUSH : { ...BRUSH, nib: (BRUSH.nib * Math.pow(z, 0.35)) / z });++export const drawEdit = (ctx: Ctx, env: Env, s: EditState) => {+ const W = env.W, H = env.H, v = s.view, vk = kk(v.cx, v.cy, v.zoom), med = nibFor(v.zoom), a = s.art;+ const w: Wing[] = [wingGeom(-1, HW, HW_H, HW_T, 2000, s.poses[0]), wingGeom(1, HW, HW_H, HW_T, 2600, s.poses[1]), wingGeom(-1, FW, FW_H, FW_T, 1000, s.poses[2]), wingGeom(1, FW, FW_H, FW_T, 1600, s.poses[3])];+ const pk = kk(...s.poses.flatMap((p) => [p.flap, p.sweep]));+ const pt = (name: string, key: string, fn: (g: Gfx) => void) => part(env, med, name, key + "|" + vk, 0, fn, v);++ const sheet = pt("page3", "page3", (g) => page(g, W, H));+ const art = pt("edit", kk(pk, a.th, a.shell, a.faces, a.accent, a.wings, a.bleed, a.ghostRod, a.arc, a.ghostSpar, s.mech, s.train.centre), (g) => { creature(g, w, a); mechanism(g, a, s.train, s.mech); bleed(g, w, a); });+ const note = pt("notes3", kk(s.cut, s.caption[1], s.inset, s.seat, s.forceP, s.pulseAt, s.pulseOn, a.th, pk, ...s.labels.map((l) => l.p), ...s.labels.flatMap((l) => l.to)), (g) => { /* two leaders point AT the crank, so the crank angle is part of what this surface is */+ cutLine(g, s.cut); labels(g, s.labels); if (s.caption[1] > 0) caption(g, s.caption[0], v, s.caption[1]);+ if (s.forceP > 0) { const from: P = [540 + 6, 380], to: P = [540 + 96, 330]; force(g, from, to, s.forceP); }+ pulse(g, { at: s.pulseAt, on: s.pulseOn }); inset(g, w[3], s.inset, s.seat, v);+ });++ blit(ctx, sheet);+ const sc = env.scale, L = s.lift;+ if (s.shadow[0] || s.shadow[1]) blit(ctx, art, Math.round((L[0] + s.shadow[0]) * sc), Math.round((L[1] + s.shadow[1]) * sc), 0.16); /* it lifts off the page, and the page keeps its diagram */+ blit(ctx, art, Math.round(L[0] * sc), Math.round(L[1] * sc));+ blit(ctx, note); /* every label and leader stays exactly where it was put, pointing at paper */+ const g = new Gfx(ctx, env, 0, PENCIL); g.paper("paper", 0.12);+};diff --git a/example/src/canvas-core/butterfly/act4art.ts b/example/src/canvas-core/butterfly/act4art.tsnew file mode 100644index 0000000..a39d2da--- /dev/null+++ b/example/src/canvas-core/butterfly/act4art.ts@@ -0,0 +1,106 @@+// ACT 3, WATERCOLOUR. The third construction: nothing is ruled and nothing is printed. A soft+// pencil underdrawing goes down FIRST and stays visible under the paint, then washes are laid+// wet-in-wet and allowed to misbehave: they bloom out from where the brush touched, they pool+// darker at the wet edge, they granulate as they dry, and they never stay inside the pencil.+// The medium is the motion. Water spreads on the beat, pigment settles after it.+import { Ctx, Env, GRAPHITE, Gfx, P, TINT, jitter, oval, rng } from "../core";+import { CX, CY, HEAD, K, KC, THORAX, Wing, cen, lerp } from "./geom";++export const PAPER3 = "#fbf7ee";+const ROSE = TINT.rose, BLUSH = TINT.blush, BUTTER = TINT.butter, SKY = TINT.sky, DENIM = TINT.denim, PEACH = TINT.peach;++// a wash does not appear, it SPREADS: every point of the shape reaches its edge at its own+// moment, out from the point the brush was put down+const spread = (pts: P[], from: P, t: number, seed: number): P[] => { const r = rng(seed); return pts.map((p) => { const lag = 0.55 + r() * 0.45, u = Math.max(0, Math.min(1, (t * 1.5 - (1 - lag)) / lag)); return lerp(from, p, u * u * (3 - 2 * u)); }); };+const bodyShape = (): P[] => { const segs = 7, y0 = 70, y1 = 250, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5, L: P[] = [], R: P[] = [];+ for (let i = 0; i <= 12; i++) { const t = i / 12, y = y0 + (y1 - y0) * t; L.push([CX - hw(t) * K, CY + y * K]); R.push([CX + hw(t) * K, CY + y * K]); }+ return [...THORAX.slice(0, 7), ...R, ...L.reverse(), ...THORAX.slice(7)]; };++// ---------------------------------------------------------------- the pencil under the paint+export const pencil = (g: Gfx, w: Wing[], p: number) => {+ if (p <= 0) return;+ const st = (i: number, n: number, dur = 0.45) => (p >= 1 ? 1 : Math.max(0, Math.min(1, (p - (i * (1 - dur)) / Math.max(1, n - 1)) / dur)));+ g.group("ink", () => {+ w.forEach((wg, i) => {+ g.pen(wg.out, { w: 2.2, color: GRAPHITE, seed: 1200 + i, closed: true, wobble: 1.4, boil: 0, opacity: 0.72, progress: st(i, 9) });+ [0, 2, 4].forEach((j, r) => { if (j >= wg.ends.length) return; const line = Array.from({ length: 6 }, (_, q) => wg.spar(j, 0.05 + (q / 5) * 0.88)); g.pen(line, { w: 1.5, color: GRAPHITE, seed: 1220 + i * 4 + r, wobble: 1.1, boil: 0, opacity: 0.55, progress: st(4 + i, 9) }); });+ });+ g.pen(bodyShape(), { w: 2.4, color: GRAPHITE, seed: 1240, closed: true, wobble: 1.2, boil: 0, opacity: 0.75, progress: st(8, 9) });+ g.pen(HEAD, { w: 2, color: GRAPHITE, seed: 1241, closed: true, wobble: 1, boil: 0, opacity: 0.75, progress: st(8, 9) });+ const o = cen(THORAX); ([[o[0] + 2, o[1] + 8, 26], [o[0] - 18, o[1] - 32, 15], [o[0] + 22, o[1] - 24, 11]] as number[][]).forEach(([x, y, r], i) => g.pen(jitter(oval(x, y, r, r, 12), 1.4, 1260 + i), { w: 1.4, color: GRAPHITE, seed: 1260 + i, closed: true, wobble: 0.8, boil: 0, opacity: 0.8, progress: st(8, 9) })); /* it is still a clockwork butterfly: the train is drawn, then painted */+ g.pen(jitter(oval(KC[0], KC[1], 7, 7, 10), 0.8, 1270), { w: 1.6, color: GRAPHITE, seed: 1270, closed: true, wobble: 0.7, boil: 0, opacity: 0.6, progress: st(8, 9) });+ [-1, 1].forEach((sd) => g.pen(jitter(oval(KC[0] + sd * 21, KC[1] + 3, 16, 21, 11), 1.1, 1272 + sd), { w: 1.5, color: GRAPHITE, seed: 1272 + sd, closed: true, wobble: 0.9, boil: 0, opacity: 0.55, progress: st(8, 9) }));+ g.pen([[KC[0], KC[1] - 36], [KC[0], KC[1] - 4]], { w: 1.6, color: GRAPHITE, seed: 1274, wobble: 0.6, boil: 0, opacity: 0.6, progress: st(8, 9) });+ [-1, 1].forEach((sd) => { const a0: P = [CX + sd * 8 * K, CY - 127 * K], a1: P = [CX + sd * 56 * K, CY - 206 * K], a2: P = [CX + sd * 124 * K, CY - 246 * K]; g.pen(Array.from({ length: 9 }, (_, i) => { const t = i / 8; return lerp(lerp(a0, a1, t), lerp(a1, a2, t), t); }), { w: 1.6, color: GRAPHITE, seed: 1250 + sd, wobble: 0.9, boil: 0, opacity: 0.65, progress: st(8, 9) }); });+ }, { alpha: 0.9 });+};++// ---------------------------------------------------------------- the washes+export const washes = (g: Gfx, w: Wing[], s: { wet: number; settle: number; slip: P }) => {+ if (s.wet <= 0) return;+ const st = (i: number, n: number, dur = 0.5) => Math.max(0, Math.min(1, (s.wet - (i * (1 - dur)) / Math.max(1, n - 1)) / dur));+ const off = (pts: P[]): P[] => pts.map(([x, y]) => [x + s.slip[0], y + s.slip[1]] as P); /* the paint slides off its own drawing */+ const shrunk = (pts: P[], k: number): P[] => { const c = cen(pts); return pts.map((q) => lerp(q, c, k)); };+ // pigment does not dry flat: it pools where the water sat longest and lifts where it ran out+ const pools = (pts: P[], col: string, seed: number, n: number, a: number) => {+ const c0 = cen(pts), r = rng(seed);+ for (let i = 0; i < n; i++) { const k = 0.3 + r() * 0.45, dx = (r() - 0.5) * 46, dy = (r() - 0.5) * 40; g.wash(shrunk(pts, k).map(([x, y]) => [x + dx, y + dy] as P), col, { alpha: a * (0.55 + r() * 0.6), seed: seed + i * 3, dx: (r() - 0.5) * 8, dy: (r() - 0.5) * 8, shrink: 0.86 + r() * 0.2, rim: r() > 0.45 }); }+ };+ g.group("paint", () => {+ const c = g.cur;+ w.forEach((wg, i) => {+ const t = st(i, 6), root = wg.h, tip = wg.ends[Math.max(0, wg.ends.length - 3)];+ if (t <= 0) return;+ const shape = off(wg.out.map((p) => lerp(p, cen(wg.out), -0.02))), pig = i < 2 ? BLUSH : ROSE;+ c.globalCompositeOperation = "source-over";+ g.wash(spread(shape, root, t, 1300 + i), pig, { alpha: 0.3, seed: 1300 + i, dx: 3, dy: 2, shrink: 0.97, rim: t > 0.55 }); /* the first pass is thin: watercolour is built, never filled */+ if (t > 0.35) { c.globalCompositeOperation = "multiply";+ const q = Math.min(1, (t - 0.35) / 0.4);+ pools(spread(shape, root, t, 1300 + i), pig, 1310 + i * 7, 4, 0.22 * q); /* uneven drying, the whole charm of the medium */+ g.wash(spread(shrunk(shape, 0.1), lerp(root, tip, 0.3), q, 1316 + i), pig, { alpha: 0.2 * q, seed: 1316 + i, dx: -3, dy: 4, shrink: 0.9, rim: true });+ }+ if (t > 0.45) { c.globalCompositeOperation = "multiply"; /* a second pigment dropped into the first while it is still wet */+ const second = shrunk(off(wg.out.map((p) => lerp(p, wg.h, 0.22))), 0.12); /* the drop runs toward the root, it does not fill a panel */+ g.wash(spread(second, lerp(root, tip, 0.45), (t - 0.45) / 0.55, 1320 + i), i < 2 ? BUTTER : PEACH, { alpha: 0.26, seed: 1320 + i, dx: -4, dy: 3, shrink: 0.88 });+ pools(second, i < 2 ? BUTTER : PEACH, 1330 + i * 5, 2, 0.14);+ }+ if (t > 0.7 && s.settle > 0.2) { c.globalCompositeOperation = "multiply"; /* pigment walks to the wet edge and dries as a dark rim */+ g.wash(spread(off(wg.out.map((p) => lerp(p, cen(wg.out), 0.04))), lerp(root, tip, 0.6), 1, 1340 + i), SKY, { alpha: 0.1 * s.settle, seed: 1340 + i, dx: 2, dy: -3, shrink: 0.995, rim: true });+ g.wash(spread(off(wg.out.map((p) => lerp(p, cen(wg.out), 0.02))), lerp(root, tip, 0.8), 1, 1350 + i), pig, { alpha: 0.16 * s.settle, seed: 1350 + i, dx: 1, dy: 5, shrink: 1.0, rim: true });+ const edge = off(wg.out), inner = shrunk(edge, 0.055); g.mark(edge, 4); c.globalAlpha = 0.3 * s.settle; c.fillStyle = pig; c.beginPath(); edge.forEach(([x, y], q) => (q ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); [...inner].reverse().forEach(([x, y], q) => (q ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); c.fill("evenodd"); c.globalAlpha = 1; /* the hard wet edge: pigment stranded at the rim as the water left */+ }+ c.globalCompositeOperation = "source-over";+ });+ }, { alpha: 0.95 });+ const b = st(5, 6);+ if (b > 0) g.group("paint", () => {+ const c = g.cur, body = off(bodyShape());+ g.wash(spread(body, [CX, CY], b, 1360), DENIM, { alpha: 0.34, seed: 1360, dx: 2, dy: 3, shrink: 0.96 });+ c.globalCompositeOperation = "multiply";+ pools(body, DENIM, 1364, 3, 0.2);+ g.wash(spread(shrunk(body, 0.18), [CX + 9, CY + 30], b, 1366), DENIM, { alpha: 0.24, seed: 1366, dx: 5, dy: 2, shrink: 0.9, rim: true }); /* the shadow side of the body, wet into wet */+ g.wash(spread(off(HEAD.map((p) => lerp(p, cen(HEAD), -0.05))), [CX, CY - 110 * K], b, 1362), DENIM, { alpha: 0.4, seed: 1362, dx: -2, dy: 2, shrink: 0.94 });+ { const kb = [-1, 1].map((sd) => off(jitter(oval(KC[0] + sd * 21, KC[1] + 3, 16, 21, 11), 1.1, 1380 + sd))); kb.forEach((sh, i) => g.wash(spread(sh, KC, b, 1380 + i), DENIM, { alpha: 0.3, seed: 1380 + i, dx: 2, dy: 2, shrink: 0.9, rim: true })); } /* the key, painted where it lies */+ if (s.settle > 0.3) { const o = cen(THORAX), wheels: number[][] = [[o[0] + 2, o[1] + 8, 26], [o[0] - 18, o[1] - 32, 15], [o[0] + 22, o[1] - 24, 11]];+ c.globalCompositeOperation = "destination-out"; /* lift the pigment off the wheels with a damp brush, the way you would */+ wheels.forEach(([x, y, r], i) => g.wash(off(jitter(oval(x, y, r * 0.96, r * 0.96, 12), 1.4, 1366 + i)), "#000000", { alpha: 0.5 * s.settle, seed: 1366 + i, dx: 0, dy: 0, shrink: 0.98, rim: false }));+ c.globalCompositeOperation = "multiply";+ wheels.forEach(([x, y, r], i) => g.wash(off(jitter(oval(x, y, r, r, 12), 1.6, 1370 + i)), SKY, { alpha: 0.4 * s.settle, seed: 1370 + i, dx: 1, dy: 2, shrink: 0.92, rim: true })); } /* then drop a cooler pigment into the hollow: the train, seen through the body */+ c.globalCompositeOperation = "source-over";+ }, { alpha: 0.95 });+};++// a drop of clean water dropped into a drying wash pushes the pigment out in a ring+export const backrun = (g: Gfx, at: P, r: number, t: number, seed: number) => {+ if (t <= 0) return;+ const e = t * t * (3 - 2 * t), R = r * (0.25 + 0.75 * e), c = g.cur;+ c.globalCompositeOperation = "destination-out"; /* straight onto the paint: a group of its own would have nothing to lift */+ g.wash(jitter(oval(at[0], at[1], R, R * 0.86, 18), R * 0.2, seed), "#000000", { alpha: 0.6 * (1 - e * 0.2), seed, dx: 0, dy: 0, shrink: 1, rim: false });+ g.wash(jitter(oval(at[0] - R * 0.34, at[1] + R * 0.26, R * 0.44, R * 0.36, 14), R * 0.12, seed + 3), "#000000", { alpha: 0.5, seed: seed + 3, dx: 0, dy: 0, shrink: 1, rim: false });+ c.globalCompositeOperation = "multiply";+ g.wash(jitter(oval(at[0], at[1], R * 1.07, R * 0.94, 18), R * 0.24, seed + 7), TINT.rose, { alpha: 0.3 * e, seed: seed + 7, dx: 0, dy: 0, shrink: 1.02, rim: true }); /* and piles the pigment into a hard ring at the edge of the bloom */+ c.globalCompositeOperation = "source-over";+};++export const sheet3 = (g: Gfx, W: number, H: number) => { const c = g.main, e = g.env; c.setTransform(e.scale, 0, 0, e.scale, 0, 0); c.fillStyle = PAPER3; c.fillRect(0, 0, W, H); g.paper("coldpress", 0.17); };+export const dry = (g: Gfx) => { g.paper("washGran", 0.05); g.paper("coldpress", 0.11); g.vignette("rgba(120,96,64,0.055)"); }; /* the sheet keeps its light: three multiplies turned white paper into cardboard */diff --git a/example/src/canvas-core/butterfly/act4cues.ts b/example/src/canvas-core/butterfly/act4cues.tsnew file mode 100644index 0000000..c34bd98--- /dev/null+++ b/example/src/canvas-core/butterfly/act4cues.ts@@ -0,0 +1,43 @@+// ACT 3, WATERCOLOUR: 360 frames, 12 s, 24 beats. Pencil, water, pigment, and a drop of clean+// water in the middle of it. The motion is what the water does.+import { P } from "../core";+import { WaterState } from "./act4plate";++export type Ease = "linear" | "out" | "flick";+export type Cue = { at: number; dur: number; id: string; ease?: Ease; amp?: number };+export const DURATION = 360;+export const SHOTS: [string, number, number][] = [+ ["paper", 0, 45], /* cold-press stock, nothing on it yet */+ ["pencil", 45, 135], /* the underdrawing, loose and fast, and it stays visible for ever */+ ["wet", 135, 225], /* the washes go down wet-in-wet and spread out from the brush */+ ["settle", 225, 270], /* a drop of clean water blooms a backrun, pigment granulates and dries */+ ["alive", 270, 345], /* five flaps, and the paint lags behind the drawing */+ ["dry", 345, 360], /* the finished painting, held */+];+export const CUES: Cue[] = [+ { at: 45, dur: 80, id: "pencil", ease: "linear" },+ { at: 135, dur: 85, id: "wet", ease: "linear" },+ { at: 195, dur: 75, id: "settle", ease: "out" },+ { at: 225, dur: 40, id: "bloom", ease: "out" },+ { at: 270, dur: 10, id: "twitch", ease: "flick", amp: 0.14 },+ { at: 285, dur: 15, id: "flap1", ease: "flick", amp: 0.55 }, { at: 300, dur: 10, id: "flap2", ease: "flick", amp: 0.62 },+ { at: 310, dur: 10, id: "flap3", ease: "flick", amp: 0.5 }, { at: 320, dur: 10, id: "flap4", ease: "flick", amp: 0.32 }, { at: 330, dur: 10, id: "flap5", ease: "flick", amp: 0.16 },+ { at: 285, dur: 30, id: "slip.out", ease: "out" }, { at: 325, dur: 20, id: "slip.in", ease: "out" },+];+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (p: number, e: Ease = "linear") => (e === "out" ? 1 - (1 - p) ** 3 : e === "flick" ? (p < 0.35 ? Math.sin((p / 0.35) * Math.PI / 2) : Math.cos(((p - 0.35) / 0.65) * Math.PI / 2)) : p);+const byId = new Map(CUES.map((c) => [c.id, c]));+const cue = (id: string) => { const c = byId.get(id); if (!c) throw new Error(`no cue '${id}'`); return c; };+export const at = (frame: number, id: string) => { const c = cue(id); return ease(clamp((frame - c.at) / c.dur), c.ease); };++export const stateAt = (frame: number): WaterState => {+ const flap = ["twitch", "flap1", "flap2", "flap3", "flap4", "flap5"].reduce((f, id) => f - (cue(id).amp ?? 0) * at(frame, id), 1);+ const slip = at(frame, "slip.out") * (1 - at(frame, "slip.in"));+ return { pose: { flap, sweep: -0.2 * (1 - flap) }, pencil: at(frame, "pencil"), wet: at(frame, "wet"), settle: at(frame, "settle"), slip: [slip * 9, slip * 6], bloom: at(frame, "bloom") };+};+export const gridProblems = (): string[] => {+ const p: string[] = [];+ CUES.forEach((c) => { if (c.at % 5) p.push(`cue '${c.id}' starts on frame ${c.at}, not a multiple of 5`); if ((c.at + c.dur) % 5) p.push(`cue '${c.id}' ends on frame ${c.at + c.dur}, not a multiple of 5`); if (c.at + c.dur > DURATION) p.push(`cue '${c.id}' ends after the act`); });+ SHOTS.forEach(([id, a, b]) => { if (a % 15 || b % 15) p.push(`shot '${id}' cuts off the beat grid (${a}..${b})`); });+ return p;+};diff --git a/example/src/canvas-core/butterfly/act4plate.ts b/example/src/canvas-core/butterfly/act4plate.tsnew file mode 100644index 0000000..3a2e743--- /dev/null+++ b/example/src/canvas-core/butterfly/act4plate.ts@@ -0,0 +1,25 @@+// THE SHEET OF PAPER. Pencil first, washes over it, blooms and settling on top, and the paper's+// own tooth over everything. The washes are their own surface, so the paint can slide off the+// drawing while it flies without either being redrawn.+import { Ctx, Env, Gfx, P, PENCIL } from "../core";+import { FW, FW_H, FW_T, HW, HW_H, HW_T, Pose, REST, Wing, wingGeom } from "./geom";+import { backrun, dry, pencil, sheet3, washes } from "./act4art";+import { blit, kk, part } from "./surface";++export type WaterState = { pose: Pose; pencil: number; wet: number; settle: number; slip: P; bloom: number };+export const WATER_REST: WaterState = { pose: REST, pencil: 1, wet: 1, settle: 1, slip: [0, 0], bloom: 1 };++export const drawWater = (ctx: Ctx, env: Env, s: WaterState) => {+ const W = env.W, H = env.H;+ const wings = (pose: Pose): Wing[] => [wingGeom(-1, HW, HW_H, HW_T, 2000, pose), wingGeom(1, HW, HW_H, HW_T, 2600, pose), wingGeom(-1, FW, FW_H, FW_T, 1000, pose), wingGeom(1, FW, FW_H, FW_T, 1600, pose)];+ const w = wings(s.pose), pk = kk(s.pose.flap, s.pose.sweep);+ const paper = part(env, PENCIL, "sheet3", "sheet3", 0, (g) => sheet3(g, W, H));+ const draw = s.pencil > 0 ? part(env, PENCIL, "pencil", kk(pk, s.pencil), 0, (g) => pencil(g, w, s.pencil)) : null;+ const paint = s.wet > 0 ? part(env, PENCIL, "wash", kk(pk, s.wet, s.settle, s.slip[0], s.slip[1], s.bloom), 0, (g) => {+ washes(g, w, { wet: s.wet, settle: s.settle, slip: s.slip });+ if (s.bloom > 0) { const b = w[2], at: P = [b.spar(2, 0.55)[0] + s.slip[0], b.spar(2, 0.55)[1] + s.slip[1]]; backrun(g, at, 78, s.bloom, 1400); } /* one drop of clean water, into the port forewing */+ }) : null;++ blit(ctx, paper); blit(ctx, paint); blit(ctx, draw, 0, 0, 0.95); /* graphite reads THROUGH the paint, so it goes on top at low opacity */+ dry(new Gfx(ctx, env, 0, PENCIL));+};diff --git a/example/src/canvas-core/butterfly/alive/anatomy.ts b/example/src/canvas-core/butterfly/alive/anatomy.tsnew file mode 100644index 0000000..410484c--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/anatomy.ts@@ -0,0 +1,96 @@+// LEPIDOPTERAN ANATOMY, built on the plate's own control points. Spec 5.7:+// the stained-glass direction is withdrawn. A spar is no longer a ruled line between two panels,+// it is a VEIN, and the panel between two veins is a wing CELL covered in scales. The spars keep+// their positions, so Act 1's silhouette and rhythm carry over exactly; what changes is that the+// structure hanging off them is now true.+//+// REFERENCE ACTUALLY OPENED before a point was moved (5.7 asks which; these are the four):+// 1. "Veinspaces1" (butterfly-ID venation plate, forewing above, hindwing below, CELL labelled,+// veins v1a-v12 and spaces s1a-s12). It settles the topology this file implements: a closed+// DISCAL CELL running from the base to about half the wing; veins leaving the END of that+// cell and fanning to the outer margin; further veins branching off the cell's LOWER edge at+// intervals rather than from its end; above the cell a costal trunk that forks two or three+// times toward the apex; and one unbranched anal vein along the inner margin. Around twelve+// veins reach the forewing margin and around eight the hindwing.+// 2. bobs-bugs "Wing venation" (generic insect wing, trunks coloured by system). It settles the+// two rules that matter more than the count: veins BRANCH outward and NEVER cross, and every+// vein is thickest at the base and thins toward the margin.+// 3. Alamy monarch on a crown flower, lateral, wings closed. It settles what the underside does+// graphically: the venation is the dominant mark, the margin carries a dark band with a+// DOUBLE row of pale spots, and a fine alternating fringe sits outside that.+// 4. Shutterstock macro of a butterfly's head at a flower. It settles the head: the compound eye+// is a large dark dome with one soft highlight, the head and thorax are densely furred, the+// antenna is thick and finely ringed at its base, the PALPS are two furry forward projections+// below the eyes, and the proboscis leaves from BELOW the palps as a fine dark tube.+import { P, jitter, rng } from "../../core";+import { Wing, cen, lerp } from "../geom";++export type Vein = { pts: P[]; w: number; main: boolean }; // w is relative weight at the base; every vein thins to a point at the margin+export type Anatomy = { out: P[]; veins: Vein[]; cell: P[]; ends: P[]; span: number };++const push = (p: P, c: P, k: number): P => [p[0] + (p[0] - c[0]) * k, p[1] + (p[1] - c[1]) * k];+const bow = (a: P, b: P, k: number): P[] => { const nx = -(b[1] - a[1]), ny = b[0] - a[0], l = Math.hypot(nx, ny) || 1; return [a, [a[0] + (b[0] - a[0]) * 0.34 + (nx / l) * k * 0.7, a[1] + (b[1] - a[1]) * 0.34 + (ny / l) * k * 0.7], [a[0] + (b[0] - a[0]) * 0.7 + (nx / l) * k, a[1] + (b[1] - a[1]) * 0.7 + (ny / l) * k], b]; };++// The margin between two vein ends is gently SCALLOPED: the veins hold the margin out and the+// membrane between them falls away. A ruled or a smoothly swept margin is the tell.+export const scallop = (out: P[], ends: P[], c: P, depth: number): P[] => {+ const near = (q: P) => ends.reduce((best, e) => (Math.hypot(e[0] - q[0], e[1] - q[1]) < Math.hypot(best[0] - q[0], best[1] - q[1]) ? e : best), ends[0]);+ return out.map((q) => { const e = near(q), d = Math.hypot(e[0] - q[0], e[1] - q[1]), sp = Math.hypot(q[0] - c[0], q[1] - c[1]); return d < sp * 0.34 ? push(q, c, -depth * Math.sin((d / (sp * 0.34)) * Math.PI) ) : q; });+};++// One wing's venation. `fore` picks the forewing plan (a long cell, a forked costal trunk, twelve+// veins) from the hindwing's (a short cell near the base, eight veins, no apical fork).+export const venation = (wg: Wing, fore: boolean, seed: number): Anatomy => {+ const r = rng(seed), E = wg.ends, n = E.length, h = wg.h, c = cen(wg.out);+ const span = Math.max(...wg.out.map((q) => Math.hypot(q[0] - h[0], q[1] - h[1])));+ const veins: Vein[] = [];+ // a margin target: along the chord between two tips, pushed out onto the margin itself+ const M = (i: number, f: number): P => push(lerp(E[Math.min(i, n - 1)], E[Math.min(i + 1, n - 1)], f), c, 0.03);++ // ---- the CELL. Closed, from the base to about half the wing, bounded above by the subcostal+ // trunk and below by the cubital, and shut at its outer end by the DISCOCELLULAR vein.+ const up = fore ? 1 : 1, lo = fore ? 4 : Math.max(2, n - 3), tU = fore ? 0.5 : 0.42, tL = fore ? 0.43 : 0.36;+ const cellU = [0, 0.25, 0.5, 0.75, 1].map((t) => wg.spar(up, t * tU)), cellL = [0, 0.25, 0.5, 0.75, 1].map((t) => wg.spar(lo, t * tL));+ const C1 = cellU[4], C2 = cellL[4];+ const disco = bow(C1, C2, span * 0.012); /* the discocellular is a little concave: it was pulled in when the wing dried */+ const cell = [...cellU, ...disco.slice(1, 3), ...cellL.slice().reverse()];+ veins.push({ pts: cellU, w: 1, main: true }, { pts: cellL, w: 0.95, main: true }, { pts: disco, w: 0.5, main: false });++ // ---- above the cell: the costal trunk to the leading margin, forking toward the apex+ const costa = [0, 0.3, 0.62, 1].map((t) => wg.spar(0, 0.04 + t * 0.94));+ veins.push({ pts: costa, w: 1, main: true });+ if (fore) [0.5, 0.72].forEach((t, k) => { const from = wg.spar(0, t), to = lerp(wg.spar(0, 1), wg.spar(1, 1), 0.3 + k * 0.45); veins.push({ pts: bow(from, to, span * 0.008 * (r() - 0.5)), w: 0.58 - k * 0.1, main: false }); }); /* radial branches: they leave one trunk in sequence, toward the apex, and never cross */ /* radial branches: they leave one trunk in sequence and never cross */++ // ---- the fan that fills the outer half of the wing. These veins ARE the plate's spars, which+ // is what "they keep their positions" has to mean: a vein that leaves the cell and then strikes+ // off on a bearing of its own is a ruled line with a new colour. Each one starts where the cell+ // ends and runs out to the margin the spar already reaches.+ for (let k = 1; k < n - 1; k++) {+ if (k === up || k === lo) continue;+ const inCell = k > up && k < lo, t0 = inCell ? (tU + tL) / 2 : 0.05;+ veins.push({ pts: [0, 0.26, 0.56, 0.8, 1].map((t) => wg.spar(k, t0 + t * (0.99 - t0))), w: 0.9 - Math.abs(k - (up + lo) / 2) * 0.06, main: true });+ }+ // ---- and off the cell's LOWER edge, at intervals: the one piece of structure the blueprint+ // never had, and the detail that separates a real plan from a fan of spokes, because these+ // start part way along a trunk instead of at its end+ [0.58, 0.88].forEach((t, k) => { const from = wg.spar(lo, t * tL), to = M(n - 3 + k, 0.35 + r() * 0.3); veins.push({ pts: bow(from, to, span * 0.012), w: 0.6 - k * 0.08, main: false }); });+ // ---- the anal vein: unbranched, along the inner margin+ veins.push({ pts: [0, 0.4, 0.75, 1].map((t) => wg.spar(n - 1, 0.04 + t * 0.86)), w: 0.66, main: true });+ if (!fore) veins.push({ pts: bow(wg.spar(n - 1, 0.3), M(n - 2, 0.7), span * 0.01), w: 0.5, main: false }); /* the hindwing carries a second anal vein */++ const ends = veins.filter((v) => v.main).map((v) => v.pts[v.pts.length - 1]);+ return { out: scallop(jitter(wg.out, span * 0.004, seed + 3), ends, c, 0.018), veins, cell, ends, span };+};++// The membrane between two adjacent veins: a wing CELL. These are what carry the scales, the+// ground colour and the markings, and they are bounded by real veins rather than ruled apart.+export const cells = (a: Anatomy): P[][] => {+ const main = a.veins.filter((v) => v.main), c = cen(a.out), out: P[][] = [];+ const byAngle = main.slice().sort((p, q) => Math.atan2(p.pts[p.pts.length - 1][1] - c[1], p.pts[p.pts.length - 1][0] - c[0]) - Math.atan2(q.pts[q.pts.length - 1][1] - c[1], q.pts[q.pts.length - 1][0] - c[0]));+ for (let i = 0; i < byAngle.length - 1; i++) {+ const A = byAngle[i].pts, B = byAngle[i + 1].pts;+ const mid = lerp(A[A.length - 1], B[B.length - 1], 0.5);+ out.push([...A, push(mid, c, 0.015), ...B.slice().reverse()]);+ }+ return out;+};diff --git a/example/src/canvas-core/butterfly/alive/cues.ts b/example/src/canvas-core/butterfly/alive/cues.tsnew file mode 100644index 0000000..115edf6--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/cues.ts@@ -0,0 +1,98 @@+// MOVEMENT 2, "ALIVE": every frame number in the movement, and nothing else. Spec section 1 is+// binding: one beat = 15 frames, one bar = 60, events on multiples of 5, landings and take-offs+// on BEATS. gridProblems() runs at module load in every host that draws this movement, so a+// number that drifts off the grid is a build error and never something a reviewer catches by eye.+//+// FABLE, one deviation to veto in a line: the spec asks for this table in `butterfly/act2cues.ts`.+// That filename is taken by the CUT riso act, which is still on disk as the record you asked to+// keep and still compiles; moving it to legacy/ breaks `act2.ts` and `act3.ts` with it. The+// movement's table lives here instead. Nothing imports the riso tables from this movement.++export const LOCAL = 870; // frames in movement 2. Retimed from 1260 on review: the macro and the+// ending are untouched, stage F loses its poppy touch-down and stage R loses the fourth landing,+// which is exactly the trim spec O6 nominates. The whole film is now 1410 frames, 47.0 s.+export const FILM_OFFSET = 540; // film frame = local + 540 (Act 1 is frames 0-539)+export const BEAT = 15, BAR = 60;+export const filmFrame = (local: number) => local + FILM_OFFSET;++// ---------------------------------------------------------------- 5.1 the camera+// S is screen px per sheet unit. Monotone, never increasing, never at rest after frame 0.+export const S_KEYS: [number, number][] = [+ [0, 4.0], [120, 3.4], [240, 1.6], [345, 0.55],+ [420, 0.545], [450, 0.52], [525, 0.515], [555, 0.49], [585, 0.485],+ [660, 0.24], [720, 0.15], [780, 0.118], [870, 0.115],+];+// The three STEPS: a take-off releases each one and it takes 30 frames. The big moves start on+// the take-offs at 240, 720 and 855.+export const STEPS: [number, number][] = [[420, 450], [525, 555]];++// The camera spine: where the lens is pointed, in sheet units, keyed on bars. Stages M to R are+// authored here; once the flight paths land these become the TARGET of a critically damped+// follow (about 25 frames of lag, spec 4) rather than the centre itself.+export const M0: [number, number] = [665, 372]; // beat 1's view: starboard forewing root, panel 2 right of centre, thorax window and its wheels in the left third++// ---------------------------------------------------------------- 5.2 the water+// The drop lands on the LIFTED panel 2 and runs down its projection lines onto the wing; from+// there it follows the spars by capillary, one spar per 5 frames, and the draftsman's port-to-+// starboard order is abandoned because water does not care about the draftsman.+// Wing order everywhere in this movement: 0 port hind, 1 starboard hind, 2 port fore, 3 starboard fore.+export const DROP = 5; // a clear bead lands on panel 2+export const SPAR_WET: number[][] = [+ [85, 90, 95, 100, 105, 110, 115], // 0 port hind+ [40, 45, 50, 55, 60, 65, 70], // 1 starboard hind+ [75, 80, 85, 90, 95, 100], // 2 port fore+ [40, 25, 15, 10, 30, 50], // 3 starboard fore: the drop arrives at spar 3 and works outward and back, and the trailing spar is the LAST to take it, so at 60 the front is still crossing the wing in the middle of the frame+];+export const PANEL2_FLOOD = 45, PANEL2_HOME = 60; // it keeps the blueprint's cornflower and slides home on its projection lines+export const BODY_WET = { shell: 65, head: 75, window: 80, abdomen: 85 }; // water crosses the body 60-120++// ---------------------------------------------------------------- 5.2 to 5.6 the beats+export const STIR = { gears: 120, portAntenna: 125, starAntenna: 130, doubleStep: 130, breath: 135, breathStar: 140, breathEnd: 165 };+export const FANS: [number, number, number][] = [[180, 30, 0.6], [210, 20, 0.5], [230, 10, 0.45]]; // start, length, flap floor+export const SMOOTH = [180, 240] as const; // stepped motion blends to continuous across this bar+export const TAKEOFFS = [240, 420, 525, 585];+export const LANDINGS: { at: number; flower: string }[] = [+ { at: 360, flower: "R1" }, { at: 450, flower: "R2" }, { at: 540, flower: "R3" },+];+export const SIPS: [number, number][] = [[375, 410], [465, 510], [555, 575]];+export const PROBOSCIS = [375, 385] as const; // the hairspring uncoils into the tight centre+export const GUSTS = [480, 600]; // a gust FRONT enters left and crosses in 60 to 90 frames+export const CLOUD_SHADOW: [number, number][] = [[480, 540], [660, 870]];+export const PETAL_FALL = [555, 585] as const;+export const WHITES = [630, 750] as const; // two real white butterflies+export const SHEET_RETURNS = 700, SHEET_CORNER_LIFTS = [715, 745];+export const HOVER = 750, CORNER_LIFT = [780, 795] as const, SIGNATURE = [795, 825] as const, DING = 825;+// 5.6: from the poppy it turns and comes UP the field to the foreground, growing as the world+// shrinks. These are the keys of that approach, and the last one is the arrival at the approved+// still's position. Without them bar 18 owns no event, which is exactly what G-AIR would find.+export const APPROACH: [number, number][] = [[660, 2.2], [700, 0.9], [730, -2.1], [750, -5.8]]; // frame, the creature's depth z+// 1185-1260: five beats to read the signature. The ink is still drying and the creature is still+// drifting, so the last bar is authored too and is not a held frame.+export const INK_DRY: [number, number] = [825, 865];+export const SEED_FLUFF = 345;++// ---------------------------------------------------------------- the gate+export const gridProblems = (): string[] => {+ const p: string[] = [], ev = (n: number, what: string) => { if (n % 5) p.push(`${what} at ${n} is off the 5-frame event grid`); if (n < 0 || n > LOCAL) p.push(`${what} at ${n} is outside [0, ${LOCAL}]`); };+ const beat = (n: number, what: string) => { if (n % BEAT) p.push(`${what} at ${n} is not on a beat (${BEAT} frames)`); };+ ev(DROP, "the drop"); ev(PANEL2_FLOOD, "panel 2 flood"); ev(PANEL2_HOME, "panel 2 home");+ SPAR_WET.forEach((w, i) => w.forEach((n, j) => ev(n, `wing ${i} spar ${j}`)));+ Object.entries(BODY_WET).forEach(([k, n]) => ev(n, `body ${k}`));+ Object.entries(STIR).forEach(([k, n]) => ev(n, `stir ${k}`));+ FANS.forEach(([n], i) => ev(n, `fan ${i}`));+ TAKEOFFS.forEach((n) => { ev(n, `take-off ${n}`); beat(n, `take-off ${n}`); });+ LANDINGS.forEach((l) => { ev(l.at, `landing on ${l.flower}`); beat(l.at, `landing on ${l.flower}`); });+ SIPS.forEach(([a, b], i) => { ev(a, `sip ${i} start`); ev(b, `sip ${i} end`); if (b <= a) p.push(`sip ${i} ends before it starts`); });+ [...GUSTS, SEED_FLUFF, SHEET_RETURNS, ...SHEET_CORNER_LIFTS, HOVER, DING, ...INK_DRY].forEach((n) => ev(n, `event ${n}`));+ APPROACH.forEach(([n], i) => { ev(n, `approach key ${i}`); if (i && n <= APPROACH[i - 1][0]) p.push(`approach key ${i} at ${n} is out of order`); if (i && APPROACH[i][1] >= APPROACH[i - 1][1]) p.push(`approach key ${i} does not come toward the camera`); });+ [...CORNER_LIFT, ...SIGNATURE, ...PETAL_FALL, ...WHITES, ...PROBOSCIS].forEach((n) => ev(n, `event ${n}`));+ CLOUD_SHADOW.forEach(([a, b], i) => { ev(a, `cloud shadow ${i}`); ev(b, `cloud shadow ${i} end`); });+ STEPS.forEach(([a, b], i) => { if (!TAKEOFFS.includes(a)) p.push(`camera step ${i} at ${a} is not released by a take-off`); if (b - a !== 30) p.push(`camera step ${i} takes ${b - a} frames, the spec says 30`); });+ S_KEYS.forEach(([f], i) => { if (i && f <= S_KEYS[i - 1][0]) p.push(`S key ${i} at frame ${f} is out of order`); });+ S_KEYS.forEach(([, s], i) => { if (i && s > S_KEYS[i - 1][1]) p.push(`S rises at key ${i} (${S_KEYS[i - 1][1]} to ${s}): the camera never moves in`); });+ if (S_KEYS[S_KEYS.length - 1][0] !== LOCAL) p.push(`the last S key is at ${S_KEYS[S_KEYS.length - 1][0]}, the movement is ${LOCAL}`);+ // every bar of the movement must own at least one authored event, or something is holding still+ const all = [DROP, PANEL2_FLOOD, PANEL2_HOME, ...SPAR_WET.flat(), ...Object.values(BODY_WET), ...Object.values(STIR), ...FANS.map((f) => f[0]), ...TAKEOFFS, ...LANDINGS.map((l) => l.at), ...SIPS.flat(), ...GUSTS, SEED_FLUFF, SHEET_RETURNS, ...SHEET_CORNER_LIFTS, HOVER, ...CORNER_LIFT, ...SIGNATURE, DING, ...PETAL_FALL, ...WHITES, ...CLOUD_SHADOW.flat(), ...APPROACH.map((a) => a[0]), ...INK_DRY];+ for (let b = 0; b * BAR < LOCAL; b++) if (!all.some((n) => n >= b * BAR && n < (b + 1) * BAR)) p.push(`bar ${b + 1} (frames ${b * BAR}-${(b + 1) * BAR}) has no authored event: check it against section 5 before trusting G-AIR`);+ return p;+};diff --git a/example/src/canvas-core/butterfly/alive/lateral.ts b/example/src/canvas-core/butterfly/alive/lateral.tsnew file mode 100644index 0000000..83fcbb0--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/lateral.ts@@ -0,0 +1,161 @@+// THE LATERAL FIGURE (spec 5.7, FABLE): wings closed or half open over the back, body in profile,+// six legs gripping. This is how most butterflies actually sip, and it is the figure a natural+// history plate draws BESIDE the dorsal one. It is used at stage R, where the creature is 350 to+// 430 px across and realism matters most.+//+// It uses the SAME control points as the dorsal figure, which is the project's rule and also the+// honest thing: a closed wing is not a different wing, it is the same wing stood up over the back+// and seen from the side. So the forewing and hindwing outlines are posed rather than redrawn, the+// venation code runs on them unchanged, and what is genuinely new here is the profile body, the+// legs and the head, none of which the blueprint ever drew.+//+// From the Alamy monarch (reference 3 in `anatomy.ts`): the hindwing sits BEHIND and its rounded+// margin projects below and behind the forewing; the forewing's inner margin tucks down out of+// sight; the underside is quieter than the upperside and its VENATION is the dominant mark; the+// margin carries a dark band with a double row of pale spots; the legs reach forward and down to+// grip; and the antennae splay into a shallow V with the clubs at the top.+import { Gfx, P, oval, rng, tube } from "../../core";+import { CX, CY, FW, FW_H, FW_T, HW, HW_H, HW_T, REST, Wing, cen, lerp, wingGeom } from "../geom";+import { PAPER_W } from "../finale/world";+const PEACH = "#ef9a5c", ROSE = "#d96e80";+import { lift } from "../finale/paint";+import { venation } from "./anatomy";+import { BAND, DUST, EYE, EYE_HI, FUR, FUR_D, LEG, SPOT, UMBER, damp, dilate, mixc, ps, rigger } from "./wingpaint";++// The UNDERSIDE is a different picture from the upperside, as it is in life. A butterfly with the+// same pattern on both faces reads as a cut-out, so this is quieter, cooler and more marbled.+// richer than a pale underside would be in life, because the brief wants pigment depth: still+// quieter than the upperside, but with real weight in the marbling and the margin+const U_GROUND = "#f0b389", U_MARBLE = "#a8734f", U_VEIN = "#6b3b2a", U_SHADE = "#d98a6d";++export type Perch = {+ at: P; // the thorax, on screen+ scale: number; // px per plate unit, as everywhere in this movement+ face: number; // -1 the head points left, +1 right+ lean: number; // radians: the body's tilt, nose down into the flower+ open: number; // 0 wings shut over the back, 1 held half open+ proboscis: number; probTo?: P;+ grip: P[]; // where the feet are, on the petal+ seed?: number;+};++// Wings closed over the back. A closed wing is not a folded wing: you see its whole FACE, the+// underside, standing up over the body. So the outline is used exactly as authored and simply+// ROTATED about its own hinge until its long axis points up and back, with a little cross-wing+// foreshortening because the pair is not quite edge on to us. Folding the outline about its own+// midline instead (which is what an `abs()` in here would do) turns one wing into a symmetrical+// moth and is why the first attempt looked like a mosquito.+const stand = (wg: Wing, at: P, scale: number, face: number, lean: number, tipUp: number, off: P): ((p: P) => P) => {+ const a = -Math.PI / 2 - tipUp + lean, c = Math.cos(a), s = Math.sin(a);+ return (p: P): P => {+ const dx = (p[0] - wg.h[0]) * scale, dy = (p[1] - wg.h[1]) * scale * 0.84;+ return [at[0] + face * (dx * c - dy * s) + face * off[0] * scale, at[1] + (dx * s + dy * c) + off[1] * scale];+ };+};++export const drawLateral = (g: Gfx, pe: Perch) => {+ const { at, scale, face, lean, open } = pe, seed = pe.seed ?? 900, sc = scale * 90, r = rng(seed + 31);+ const lod = scale * 780;+ const HW_G = wingGeom(1, HW, HW_H, HW_T, 2600, REST), FW_G = wingGeom(1, FW, FW_H, FW_T, 1600, REST);++ // ---- the shadow it throws on the petal, before anything else+ g.fill(oval(at[0] - sc * 0.5 * face, at[1] + sc * 0.9, sc * 1.1, sc * 0.26, 10), "#6d7f55", 0.2);++ // ---- the far legs, then the wings, then the body, then the near legs: the stacking order is+ // the whole reason a lateral figure reads as a solid animal and not a sticker+ perchLegs(g, pe, sc, false);+ profileBody(g, pe, sc, lod, r); /* the body goes UNDER the wings: a closed pair covers most of the abdomen, and an abdomen left sticking out behind is a mosquito */+ wingFace(g, HW_G, false, stand(HW_G, at, scale, face, lean, -0.72 - open * 0.26, [-104, 16]), sc, lod, seed + 7, 0.9); /* the hindwing sits BEHIND, and its rounded margin projects below and behind the forewing */+ wingFace(g, FW_G, true, stand(FW_G, at, scale, face, lean, -0.42 + open * 0.3, [-66, -10]), sc, lod, seed + 11, 1);+ perchLegs(g, pe, sc, true);+ profileHead(g, pe, sc, lod);+};++// one wing, seen from UNDERNEATH, standing over the back+const wingFace = (g: Gfx, wg: Wing, fore: boolean, T: (p: P) => P, sc: number, lod: number, seed: number, front: number) => {+ const A = venation(wg, fore, seed), c0 = cen(wg.out), out = A.out.map(T);+ g.fill(dilate(A.out, 2).map(T), PAPER_W, 0.7); /* the paper is kept lighter under it */+ ps(g, out, U_GROUND, 0.92, seed + 1, sc * 1.3);+ ps(g, out.map((q) => lerp(q, cen(out), 0.2)), mixc(U_GROUND, PEACH, 0.5), 0.7, seed + 2, sc, false);+ ps(g, out.map((q) => lerp(q, T(wg.h), 0.3)), ROSE, 0.36, seed + 3, sc * 0.8, false); /* the rose of the upperside bleeds through at the wing root: one animal, two faces */+ // soft grey-olive marbling: the underside's whole character, and nothing on it has a hard edge+ for (let k = 0; k < 5; k++) { const rr = rng(seed + 20 + k), kk = 0.3 + rr() * 0.45, off: P = [(rr() - 0.5) * sc * 0.5, (rr() - 0.5) * sc * 0.5]; ps(g, out.map((z) => [cen(out)[0] + (z[0] - cen(out)[0]) * kk + off[0], cen(out)[1] + (z[1] - cen(out)[1]) * kk + off[1]] as P), rr() > 0.55 ? U_MARBLE : U_SHADE, 0.3 + rr() * 0.24, seed + 30 + k, sc * 0.7, false); }+ if (fore) { const apex = A.ends[Math.min(1, A.ends.length - 1)]; damp(g, [apex, lerp(apex, A.ends[0], 0.5), lerp(apex, c0, 0.34)].map(T), mixc(UMBER, U_MARBLE, 0.5), 0.3, seed + 40, sc * 0.5); }+ // the dark margin and the DOUBLE row of pale spots the reference shows on the underside+ if (lod > 120) {+ const inner = A.out.map((q) => lerp(q, c0, 0.11));+ damp(g, [...A.out, ...inner.slice().reverse()].map(T), mixc(BAND, U_SHADE, 0.05), 0.74, seed + 50, sc * 1.1);+ [0.14, 0.26].forEach((d, row) => A.ends.forEach((e, k) => { const q = T(lerp(e, c0, d)); ps(g, oval(q[0], q[1], sc * (0.026 - row * 0.006), sc * (0.022 - row * 0.005), 8), SPOT, 0.7 - row * 0.16, seed + 60 + row * 9 + k, sc * 0.09, false); }));+ }+ // the venation, which on an underside is the loudest thing on the wing+ A.veins.forEach((v, k) => rigger(g, v.pts.map(T), sc * 0.026 * v.w, U_VEIN, v.main ? 0.95 : 0.7, seed + 80 + k));+ if (lod > 120) A.out.forEach((q, k) => { const nx = q[0] - c0[0], ny = q[1] - c0[1], L = Math.hypot(nx, ny) || 1; g.fill(tube([T(q), T([q[0] + (nx / L) * A.span * 0.02, q[1] + (ny / L) * A.span * 0.02])], sc * 0.007, sc * 0.003, false), k % 2 ? SPOT : BAND, 0.55); }); /* the fringe */+ if (front > 0.95) lift(g, tube(out.slice(0, Math.ceil(out.length * 0.3)), sc * 0.045, sc * 0.025, false), seed + 90, 0.5);+};++// the body in profile: a furred thorax, a tapering segmented abdomen tucked down behind the wings+const profileBody = (g: Gfx, pe: Perch, sc: number, lod: number, r: () => number) => {+ const { at, face, lean, scale } = pe, c = Math.cos(lean), s = Math.sin(lean);+ const L = (x: number, y: number): P => [at[0] + face * (x * c - y * s) * scale, at[1] + (x * s + y * c) * scale];+ const thorax = [L(-34, -40), L(6, -46), L(38, -26), L(46, 8), L(30, 36), L(-4, 46), L(-38, 32), L(-52, -8)];+ ps(g, thorax, mixc(UMBER, "#4a3a2c", 0.3), 0.9, 421, sc * 0.5);+ ps(g, thorax.map((q) => lerp(q, L(14, -22), 0.5)), mixc(DUST, SPOT, 0.34), 0.42, 423, sc * 0.35, false); /* lit from the upper right */+ ps(g, thorax.map((q) => lerp(q, L(-12, 28), 0.55)), "#3b2f24", 0.34, 425, sc * 0.35, false); /* core shadow */+ ps(g, thorax.map((q) => lerp(q, L(-14, 38), 0.66)), mixc(DUST, "#8c7a63", 0.5), 0.24, 427, sc * 0.3, false); /* light bounced back up off the petal */+ const abd: P[] = []; for (let i = 0; i <= 6; i++) { const t = i / 6; abd.push(L(-36 - t * 104, 4 + t * 56)); } for (let i = 6; i >= 0; i--) { const t = i / 6; abd.push(L(-36 - t * 104, 58 + t * 26)); }+ ps(g, abd, mixc(UMBER, DUST, 0.26), 0.86, 430, sc * 0.4);+ for (let i = 1; i < 7; i++) { const t = i / 7; g.fill(tube([L(-36 - t * 104, 5 + t * 56), L(-36 - t * 104, 57 + t * 26)], sc * 0.012, sc * 0.012, false), mixc(DUST, SPOT, 0.45), 0.42); } /* the paler band at each joint, wrapping round the cylinder */+ ps(g, abd.map((q) => lerp(q, L(-110, 60), 0.42)), "#463628", 0.26, 432, sc * 0.35, false);+ if (lod > 120) for (let i = 0; i < 26; i++) { const t = r(), a = -1.5 + (r() - 0.5) * 1.4, p = L(-10 + (r() - 0.5) * 80, -40 + t * 84), len = sc * (0.09 + r() * 0.11); g.fill(tube([p, [p[0] + Math.cos(a) * len, p[1] + Math.sin(a) * len] as P], sc * 0.011, sc * 0.003, false), r() > 0.45 ? FUR : FUR_D, 0.4 + r() * 0.3); }+};++// the head in profile: one big compound eye, the palps in front of it, the antenna and the tube+const profileHead = (g: Gfx, pe: Perch, sc: number, lod: number) => {+ const { at, face, lean, scale } = pe, c = Math.cos(lean), s = Math.sin(lean);+ const L = (x: number, y: number): P => [at[0] + face * (x * c - y * s) * scale, at[1] + (x * s + y * c) * scale];+ ps(g, [L(40, -44), L(76, -34), L(86, -8), L(76, 16), L(46, 20), L(34, -14)], mixc(UMBER, "#493928", 0.35), 0.9, 440, sc * 0.3);+ if (lod > 120) {+ const e = L(66, -16);+ ps(g, oval(e[0], e[1], sc * 0.105, sc * 0.115, 13), EYE, 0.92, 442, sc * 0.22, false); /* one large compound eye, filling most of the head */+ ps(g, oval(e[0] - sc * 0.02, e[1] + sc * 0.025, sc * 0.072, sc * 0.078, 11), mixc(EYE, "#6a5a45", 0.42), 0.42, 444, sc * 0.16, false);+ g.fill(oval(e[0] + sc * 0.035, e[1] - sc * 0.04, sc * 0.024, sc * 0.02, 8), EYE_HI, 0.88);+ g.fill(tube([L(58, 14), L(84, 30), L(98, 50)], sc * 0.036, sc * 0.012, false), FUR, 0.9); /* the palps, forward and down, furry */+ g.fill(tube([L(74, 30), L(94, 46)], sc * 0.02, sc * 0.008, false), FUR_D, 0.7);+ }+ [0, 1].forEach((k) => { /* the antennae splay into a shallow V, finely ringed, clubbed */+ const a0 = L(64, -44), a1 = L(122, -116 - k * 18), a2 = L(196, -160 - k * 34);+ const pts = Array.from({ length: 9 }, (_, i) => { const t = i / 8; return lerp(lerp(a0, a1, t), lerp(a1, a2, t), t); });+ g.fill(tube(pts, sc * 0.024, sc * 0.01, false), mixc(EYE, UMBER, 0.3), 0.84);+ if (lod > 120) for (let i = 1; i < 8; i++) g.fill(tube([pts[i], lerp(pts[i], pts[i + 1], 0.45)], sc * 0.015, sc * 0.013, false), FUR, 0.4);+ const cl = pts[8], cb = pts[7];+ ps(g, oval(cl[0] + (cl[0] - cb[0]) * 0.3, cl[1] + (cl[1] - cb[1]) * 0.3, sc * 0.044, sc * 0.028, 9), mixc(EYE, UMBER, 0.2), 0.9, 450 + k, sc * 0.1, false);+ });+ // the proboscis: it leaves from BELOW the palps, and when it is out it is a fine curved tube+ const base = L(88, 38), tip: P = pe.probTo ?? [base[0], base[1] + sc * 0.9], p = pe.proboscis, spir: P[] = [];+ for (let i = 0; i <= 24; i++) {+ const t = i / 24, a = 1.2 + t * 2.4 * Math.PI * 2, rr = sc * (0.016 + 0.07 * t);+ const coiled: P = [base[0] + Math.cos(a) * rr, base[1] + Math.sin(a) * rr];+ const bw = Math.sin(t * Math.PI) * sc * 0.26;+ const straight: P = [base[0] + (tip[0] - base[0]) * t + face * bw * 0.5, base[1] + (tip[1] - base[1]) * t + bw * 0.5];+ spir.push([coiled[0] + (straight[0] - coiled[0]) * p, coiled[1] + (straight[1] - coiled[1]) * p]);+ }+ g.fill(tube(spir, sc * 0.02, sc * 0.01, false), mixc(EYE, UMBER, 0.25), 0.78);+ if (p > 0.4) g.fill(tube(spir.map((q) => [q[0] + sc * 0.011, q[1] + sc * 0.005] as P), sc * 0.008, sc * 0.004, false), FUR, 0.3 * p);+};++// Six legs, reaching forward and down to GRIP. The far three are drawn before the wings and the+// near three after, which is what makes the figure sit on the flower rather than in front of it.+const perchLegs = (g: Gfx, pe: Perch, sc: number, near: boolean) => {+ const { at, face, lean, grip, scale } = pe, c = Math.cos(lean), s = Math.sin(lean), r = rng((pe.seed ?? 900) + (near ? 3 : 5));+ const L = (x: number, y: number): P => [at[0] + face * (x * c - y * s) * scale, at[1] + (x * s + y * c) * scale];+ ([[34, 30], [2, 42], [-34, 46]] as number[][]).forEach(([hx, hy], k) => {+ const hip = L(hx, hy), foot = grip[k % grip.length] ?? [hip[0] + sc * 0.3, hip[1] + sc * 0.7];+ const off = near ? sc * 0.06 : -sc * 0.08, fo: P = [foot[0] + off + (r() - 0.5) * sc * 0.12, foot[1] + (r() - 0.5) * sc * 0.08];+ const knee: P = [lerp(hip, fo, 0.45)[0] + face * sc * 0.16, lerp(hip, fo, 0.45)[1] - sc * 0.2]; /* the femur goes forward and UP, the tibia comes back down: that kink is the leg */+ const col = near ? LEG : mixc(LEG, "#3b2f24", 0.45);+ g.fill(tube([hip, knee], sc * 0.021, sc * 0.014, false), col, near ? 0.84 : 0.6);+ g.fill(tube([knee, fo], sc * 0.015, sc * 0.008, false), col, near ? 0.82 : 0.58);+ g.fill(tube([fo, [fo[0] + face * sc * 0.07, fo[1] + sc * 0.03] as P], sc * 0.009, sc * 0.004, false), mixc(col, EYE, 0.5), near ? 0.85 : 0.6); /* tarsus and its claw, bent over the petal */+ for (let i = 0; i < 3; i++) { const p = lerp(hip, knee, 0.3 + i * 0.25); g.fill(tube([p, [p[0] + (r() - 0.5) * sc * 0.05, p[1] - sc * 0.028] as P], sc * 0.0045, sc * 0.002, false), FUR_D, near ? 0.5 : 0.3); }+ });+};diff --git a/example/src/canvas-core/butterfly/alive/meadow2.ts b/example/src/canvas-core/butterfly/alive/meadow2.tsnew file mode 100644index 0000000..fcfbd5d--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/meadow2.ts@@ -0,0 +1,106 @@+// THE CLUMP, AND WHAT IS BEHIND IT. Stage R holds for six bars, so this is the part of the film+// the eye has time to disbelieve. Nine heads and five buds, hand-placed at three heights and+// three depths, chosen so the flight zig-zags right, then left behind a stem, then down, then up+// (spec 6.1). Nothing is stamped: every plant has its own view, colour, size, nod and seed, and+// no view is used for more than a quarter of the clump. Nine heads over five views is two of+// each and one over, so every view sits at 22 percent and none of them reaches the 25 the spec+// allows: facing R1 and F3, three-quarter R2 and F1, profile R3 and F4, half-open R4 and F2, and+// one bud standing among them on its own tall stem.+//+// Behind them there is no sky yet. At S around 0.5 the camera is down among the stems, so the+// backdrop is the meadow itself thrown out of focus: a graded wash that runs cool and green at+// the bottom to warm and pale at the top where the light comes through, drifts of colour with no+// drawing in them at all, and two planes of grass that are only silhouette and value.+import { Gfx, P, jitter, oval, rng, tube } from "../../core";+import { GRASS_LIT, GRASS_MID, GRASS_SHADE } from "../finale/world";+import { Plant, Variety, View, basalLeaves, head, plant } from "./ranunculus";+import { Cam, projector } from "./view";++// world units, the same units as the plate: the ground the clump grows out of is at y = 1080+export const GROUND = 1080;+export const R_LOOK: P = [1760, 250]; // where the lens sits through stage R++// R1 to R4 are the four the creature visits, in order. The rest are the clump it visits them in.+export const CLUMP: (Plant & { id: string; z: number })[] = [+ { id: "R4", z: 0, at: [1965, -130], R: 310, v: "magenta", view: "half", tilt: -0.12, stemLen: 1180, seed: 2101 },+ { id: "R2", z: 0, at: [2210, 170], R: 330, v: "blush", view: "three", tilt: 0.16, stemLen: 980, seed: 2102, sideBud: -0.7 },+ { id: "F1", z: 0, at: [1145, 255], R: 300, v: "peach", view: "three", tilt: -0.22, stemLen: 900, seed: 2103 },+ { id: "R1", z: 0, at: [1720, 300], R: 350, v: "coral", view: "facing", tilt: 0.05, stemLen: 900, seed: 2104 },+ { id: "F2", z: 0, at: [2470, 520], R: 290, v: "coral", view: "half", tilt: 0.3, stemLen: 700, seed: 2105 },+ { id: "R3", z: 0, at: [1330, 640], R: 300, v: "butter", view: "profile", tilt: -0.3, stemLen: 620, seed: 2106, sideBud: 0.6 },+ { id: "F4", z: 0, at: [2345, 790], R: 260, v: "blush", view: "profile", tilt: 0.42, stemLen: 420, seed: 2107 },+ { id: "F3", z: 0, at: [1575, 810], R: 270, v: "butter", view: "facing", tilt: 0.1, stemLen: 400, seed: 2108 },+ { id: "F5", z: 0.3, at: [1380, 430], R: 150, v: "magenta", view: "bud", tilt: -0.08, stemLen: 760, seed: 2109 },+];+export const BUDS: (Plant & { z: number })[] = [+ { z: 0, at: [1450, 120], R: 90, v: "coral", view: "bud", tilt: -0.5, stemLen: 1100, seed: 2201 },+ { z: 0, at: [2120, 700], R: 80, v: "blush", view: "bud", tilt: 0.55, stemLen: 520, seed: 2202 },+ { z: 0.3, at: [1250, -60], R: 85, v: "magenta", view: "bud", tilt: -0.3, stemLen: 1300, seed: 2203 },+ { z: 0, at: [2600, 200], R: 75, v: "peach", view: "bud", tilt: 0.7, stemLen: 980, seed: 2204 },+ { z: 0, at: [1700, 900], R: 70, v: "butter", view: "bud", tilt: -0.62, stemLen: 300, seed: 2205 },+];+// Every head nods on its OWN period, 50 to 80 frames, never shared. A visited head also dips on+// the landing and rebounds on the take-off, which is the only synchronised motion in the clump.+export const nod = (seed: number, f: number) => { const per = 50 + (seed % 31); return Math.sin((f / per) * Math.PI * 2 + seed) * 0.12; };++// ---------------------------------------------------------------- the backdrop+const mixc = (a: string, b: string, t: number) => { const h = (x: string) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)]; const A = h(a), B = h(b); return "#" + A.map((v, i) => Math.round(v + (B[i] - v) * t).toString(16).padStart(2, "0")).join(""); };++export const backdrop = (g: Gfx, cam: Cam, W: number, H: number) => {+ const c = g.cur, gr = c.createLinearGradient(0, 0, 0, H);+ gr.addColorStop(0, "#eee9cd"); gr.addColorStop(0.34, "#cfd8a2"); gr.addColorStop(0.72, "#9cb375"); gr.addColorStop(1, "#6e8b5d");+ g.touch(-20, -20, W + 20, H + 20); c.fillStyle = gr; c.fillRect(-20, -20, W + 40, H + 40);+ const r = rng(4400); /* drifts of colour with no drawing in them: other flowers, far too far back to be flowers */+ ([["#e8b8c8", 260, 300, 190, 6], ["#f2dc9a", 760, 210, 220, 7], ["#d9a0b4", 900, 620, 170, 5], ["#eae2c2", 420, 120, 150, 5]] as [string, number, number, number, number][]).forEach(([col, cx, cy, rad, n], i) => {+ for (let j = 0; j < n; j++) { const a = r() * 6.283, d = Math.sqrt(r()) * rad; g.wash(oval(cx + Math.cos(a) * d, cy + Math.sin(a) * d * 0.7, 18 + r() * 26, 14 + r() * 20, 9), col, { alpha: 0.2 + r() * 0.18, seed: 4410 + i * 20 + j, shrink: 0.95, rim: false }); }+ });+};++// a plane of grass that is only silhouette and value: no blade is drawn sharply this far back+export const backGrass = (g: Gfx, cam: Cam, z: number, seed: number, n: number, fade: number, lean: number) => {+ const { at, k } = projector(cam, z), r = rng(seed);+ const air = (col: string) => mixc(col, "#dfe4d0", fade);+ for (let i = 0; i < n; i++) {+ const wx = R_LOOK[0] - 2600 + r() * 5200, wy = GROUND - 200 + r() * 900, p = at([wx, wy]), h = (260 + r() * 520) * k;+ if (p[0] < -160 || p[0] > 1240) continue;+ const ang = (r() - 0.5) * 0.5 + lean * 0.4, pts: P[] = [];+ for (let q = 0; q <= 5; q++) { const t = q / 5, a = ang + lean * t * t * 1.4; pts.push([p[0] + Math.sin(a) * h * t, p[1] - Math.cos(a) * h * t]); }+ g.fill(tube(pts, Math.max(0.8, h * 0.022), h * 0.004, false), air([GRASS_SHADE, GRASS_MID, GRASS_LIT][Math.floor(r() * 3)]), (0.2 + r() * 0.24) * (1 - fade * 0.4));+ }+};++// ---------------------------------------------------------------- the clump, composed+export const drawClump = (g: Gfx, cam: Cam, f: number, o: { dip?: Record<string, number>; lean?: number } = {}) => {+ const lean = o.lean ?? 0, dips = o.dip ?? {};+ const items = [...CLUMP.map((p) => ({ p, bud: false })), ...BUDS.map((p) => ({ p: p as typeof CLUMP[0], bud: true }))];+ const drawn = items.map((it) => { const pr = projector(cam, it.p.z), s = pr.at(it.p.at); return { ...it, s, k: pr.k, y: s[1] }; });+ const p0 = projector(cam, 0);+ g.group("plain", () => basalLeaves(g, p0.at([1780, GROUND + 130]), 1250 * p0.k, 2300, 11), { alpha: 0.9 }); /* the dark ferny mass at the foot of the clump */+ drawn.sort((a, b) => a.y - b.y).forEach((it) => {+ const dip = dips[(it.p as { id?: string }).id ?? ""] ?? 0, n = nod(it.p.seed, f);+ g.group("paint", () => plant(g, { ...it.p, at: it.s, R: it.p.R }, it.k, dip + n, lean + n * 0.4), { alpha: 0.99 }); /* a paint group softens the margin a hair and granulates it: the difference between cellophane and wet pigment */+ });+};++// ---------------------------------------------------------------- the near air+export const fringe = (g: Gfx, cam: Cam, lean: number) => {+ const { at, k } = projector(cam, -0.2), r = rng(4500);+ g.group("plain", () => {+ for (let i = 0; i < 7; i++) {+ const p = at([R_LOOK[0] - 1400 + r() * 2800, GROUND + 400 + r() * 300]), h = (900 + r() * 700) * k, a = (r() - 0.5) * 0.7;+ const pts: P[] = []; for (let q = 0; q <= 5; q++) { const t = q / 5, ang = a + (lean + 0.1) * t * t * 1.6; pts.push([p[0] + Math.sin(ang) * h * t, p[1] - Math.cos(ang) * h * t]); }+ g.fill(tube(pts, Math.max(2, h * 0.04), h * 0.006, false), [GRASS_SHADE, GRASS_MID, GRASS_LIT][i % 3], 0.34);+ }+ }, { alpha: 0.55, blur: 4.2 }); /* across the lens, huge and with no edge at all */+};+// seed fluff, from local 345: two of them, drifting, never crossing the creature's face+export const seedFluff = (g: Gfx, cam: Cam, f: number) => {+ const { k } = projector(cam, -0.05);+ ([[345, 120, 980, -0.9, 3110], [420, 860, 1120, -1.25, 3120]] as number[][]).forEach(([from, x0, y0, rise, seed]) => {+ if (f < from) return; const t = (f - from) / 300, r = rng(seed);+ const p: P = [x0 + t * 620 + Math.sin(t * 7 + seed) * 46, y0 + t * 560 * rise + Math.cos(t * 5.5) * 30], R = 17 * Math.max(0.6, k * 1.6);+ if (p[1] < -40 || p[0] > 1140) return;+ for (let i = 0; i < 11; i++) { const a = (i / 11) * Math.PI * 2 + t * 1.6; g.fill(tube([p, [p[0] + Math.cos(a) * R, p[1] + Math.sin(a) * R]], R * 0.09, R * 0.03, false), "#f6f1e2", 0.5); }+ g.fill(oval(p[0], p[1], R * 0.14, R * 0.14, 6), "#cdbfa2", 0.7);+ });+};diff --git a/example/src/canvas-core/butterfly/alive/movement2.ts b/example/src/canvas-core/butterfly/alive/movement2.tsnew file mode 100644index 0000000..29ab81b--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/movement2.ts@@ -0,0 +1,273 @@+// MOVEMENT 2, "ALIVE", all 1260 frames. One shot, no cuts: every change of scale is a camera+// move and every big move is released by a take-off. The whole movement is a pure function of the+// local frame, and every frame number it uses comes from `cues.ts`.+//+// The movement crosses two camera conventions. Stages M to R live in the NEAR world, in plate+// units, where the sheet is 1080 units across and the ranunculus clump grows beside it. Stages F+// and W live in the FINALE world, which is the approved destination's own coordinate system and+// carries the sky, the hills, the far field, the footpath and the signature. The handover is a+// 60-frame DISSOLVE under the climb out of the clump, which is the only place in the movement+// where two renderings of the same meadow are on screen at once. It is not a cut: nothing jumps,+// the camera keeps pulling back through it, and it is over before the hills arrive.+import { Ctx, Env, Gfx, Layer, P, PENCIL } from "../../core";+import { CX, CY, HEAD, THORAX, cen, lerp } from "../geom";+import { FULL, PlateState, drawPlate } from "../plate";+import { PAPER_F } from "../finale/compose";+import { Cam as FCam, projector as fprojector } from "../finale/world";+import { farField, footpath, grassBlades, grassWash, hills, sky } from "../finale/scene";+import { Drift, drift, flower } from "../finale/flora";+import { blueprintSheet } from "../finale/sheet";+import { clearCorner, signature } from "./sign";+import { clump as grassClump } from "../finale/paint";+import { GRASS_LIT, GRASS_MID, GRASS_SHADE } from "../finale/world";+import { APPROACH, CORNER_LIFT, DING, FANS, GUSTS, HOVER, LANDINGS, M0, PANEL2_HOME, SEED_FLUFF, SIGNATURE, SIPS, STIR, TAKEOFFS, WHITES } from "./cues";+import { Cam, projector, scaleOf } from "./view";+import { drop, frontRim, wetnessAt } from "./water";+import { ALL_WET, Flight, dilate, mapper, paintCreature, wingsOf } from "./wingpaint";+import { CLUMP, GROUND, R_LOOK, backGrass, backdrop, drawClump, fringe, nod, seedFluff } from "./meadow2";+import { PAINTS } from "./ranunculus";++const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (t: number) => t * t * (3 - 2 * t);+const ramp = (f: number, a: number, b: number) => ease(clamp((f - a) / (b - a)));+const HANDOVER: [number, number] = [575, 630]; // the dissolve out of the near world, under the climb++// ---------------------------------------------------------------- the camera spine (near world)+// Authored on bars. Stages M to R: it starts on the wing root, drifts across the thorax, then+// follows the creature off the sheet and over to the clump, where it settles and only creeps.+const LOOK: [number, P][] = [+ [0, M0], [120, [626, 382]], [200, [590, 440]], [240, [560, 500]], [270, [545, 535]],+ [285, [600, 520]], [320, [1080, 420]], [345, R_LOOK], [450, [1820, 262]], [540, [1700, 300]],+ [585, [1800, 220]], [640, [2400, 60]], [700, [3100, -140]],+];+const lookAt = (f: number): P => {+ let i = 0; while (i < LOOK.length - 2 && f > LOOK[i + 1][0]) i++;+ const [f0, a] = LOOK[i], [f1, b] = LOOK[i + 1], t = ease(clamp((f - f0) / (f1 - f0)));+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];+};+export const camAt = (f: number): Cam => ({ S: scaleOf(f), look: lookAt(f) });++// ---------------------------------------------------------------- the creature, beat by beat+// Stepped on the tick until 180, blending to continuous across the bar to 240, then free.+const poseAt = (f: number): Flight => {+ if (f < STIR.gears) return { pose: { flap: 1, sweep: 0 }, heading: 0, pitch: 1, bank: 0 };+ if (f < 180) { /* the gears catch, the antennae quiver, then a BREATH: one side leads */+ const n = Math.floor(f / 5), step = (n % 2 ? 0.012 : -0.008);+ const br = f >= STIR.breath ? Math.sin(((f - STIR.breath) / 30) * Math.PI) * 0.14 : 0;+ return { pose: { flap: 1 - br + step, sweep: step * 0.4 }, heading: 0, pitch: 1, bank: 0.03 + br * 0.4 };+ }+ if (f < 240) { /* three fans, opening wider each time, easing from hard-out to in and out */+ let flap = 1;+ FANS.forEach(([at, len, floor]) => { if (f >= at && f < at + len * 2) { const u = (f - at) / (len * 2); flap = Math.min(flap, 1 - (1 - floor) * Math.sin(u * Math.PI)); } });+ const u = clamp((f - 180) / 60), stepped = Math.floor(f / 5) % 2 ? 0.01 : -0.01;+ return { pose: { flap: flap + stepped * (1 - u), sweep: -0.02 * (1 - flap) }, heading: 0, pitch: 1 - 0.04 * (1 - flap), bank: 0.06 + 0.1 * (1 - flap) };+ }+ const cyc = f < 345 ? 10 : 30, ph = ((f - 240) % cyc) / cyc, flap = 0.62 + 0.38 * Math.cos(ph * Math.PI * 2);+ return { pose: { flap, sweep: -0.03 * (1 - flap) }, heading: 0, pitch: 0.92, bank: 0.07 + 0.05 * Math.sin(f * 0.11) };+};++// Where it is, in NEAR-WORLD units, from the take-off to the climb out of the clump. Hand-authored+// with detours: a butterfly never flies a straight line and never a clean sine.+const hostOf = (id: string) => CLUMP.find((c) => c.id === id)!;+const perchPoint = (id: string): P => { const h = hostOf(id); return [h.at[0] + h.R * 0.42, h.at[1] - h.R * 0.52]; };+const bob = (f: number, amp: number): number => Math.sin(f * 0.42) * amp;+export const whereAt = (f: number): { at: P; perched: boolean; on: string } => {+ if (f < 240) return { at: [CX, CY], perched: false, on: "" };+ if (f < 360) { /* off the sheet, up and right, with a detour: it is not going anywhere in particular yet */+ const t = ease(clamp((f - 240) / 120)), a: P = [CX, CY], b = perchPoint("R1");+ return { at: [a[0] + (b[0] - a[0]) * t + Math.sin(t * Math.PI * 1.6) * 210, a[1] + (b[1] - a[1]) * t - Math.sin(t * Math.PI) * 420 + bob(f, 12)], perched: false, on: "" };+ }+ const legs: [number, number, string, string][] = [[360, 420, "R1", "R1"], [420, 450, "R1", "R2"], [450, 525, "R2", "R2"], [525, 540, "R2", "R3"], [540, 585, "R3", "R3"], [585, 645, "R3", ""]];+ for (const [a, b, from, to] of legs) {+ if (f < a || f >= b) continue;+ if (from === to) return { at: perchPoint(from), perched: true, on: from };+ const t = ease(clamp((f - a) / (b - a))), p = perchPoint(from), q = to ? perchPoint(to) : [p[0] + 900, p[1] - 1400] as P;+ const detour = Math.sin(t * Math.PI) * (to === "R2" ? 180 : to === "R3" ? -260 : 150);+ return { at: [p[0] + (q[0] - p[0]) * t + detour, p[1] + (q[1] - p[1]) * t - Math.sin(t * Math.PI) * 170 + bob(f, 9)], perched: false, on: "" };+ }+ const t = clamp((f - 645) / 90), p = perchPoint("R3");+ return { at: [p[0] + 1400 * t, p[1] - 2100 * t], perched: false, on: "" };+};++// ---------------------------------------------------------------- the sheet, as a world object+// The plate is drawn ONCE at 1:1 into its own surface with the butterfly-shaped BLANK knocked out+// of it, and from then on it is only ever downscaled and foreshortened onto the frame. Never+// scaled up: that is the rule, and it is also why the blank keeps the drawing's own edge.+const BLANK = "#e8e3d2";+const sheetLayer = (env: Env, blank: boolean): Layer => {+ const key = `alive:sheet:${blank}`, dw = Math.round(env.W * env.scale), dh = Math.round(env.H * env.scale);+ let L = env.cache.get(key) as Layer | undefined;+ if (L) return L;+ L = env.canvas(dw, dh);+ const st: PlateState = { wings: { flap: 1, sweep: 0 }, lift: 0, keyY: 0, keyTurn: 0, train: { centre: 0, third: 0, pinion: 0, escape: 0, fork: 0 }, shadow: [0, 0], boil: 0, inkedBoil: 0, boilIndex: 0, p: FULL, view: { cx: 540, cy: 540, zoom: 1 } };+ drawPlate(L.ctx, env, st);+ if (blank) knockOut(new Gfx(L.ctx, env, 0, PENCIL), (p: P) => p);+ env.cache.set(key, L);+ return L;+};+// the creature's own silhouette, lifted clean out of the plate: the drawing went with it+export const knockOut = (g: Gfx, T: (p: P) => P) => {+ const W = wingsOf({ pose: { flap: 1, sweep: 0 }, heading: 0, pitch: 1, bank: 0 });+ W.forEach((wg) => g.fill(dilate(wg.out, 4).map(T), BLANK, 0.97));+ g.fill(dilate(THORAX, 5).map(T), BLANK, 0.97);+ g.fill(dilate(HEAD, 4).map(T), BLANK, 0.97);+ const abd: P[] = [];+ for (let i = 0; i <= 6; i++) { const t = i / 6, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push(T([CX + hw * 0.9, CY + (70 + 170 * t) * 0.9])); }+ for (let i = 6; i >= 0; i--) { const t = i / 6, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push(T([CX - hw * 0.9, CY + (70 + 170 * t) * 0.9])); }+ g.fill(abd, BLANK, 0.97);+};+// y-scale 1 to 0.45 about its centre with a slight keystone: the sheet is lying in the grass now+const sheetOnto = (ctx: Ctx, env: Env, cam: Cam, f: number) => {+ const L = sheetLayer(env, f >= TAKEOFFS[0]), pr = projector(cam, 0), c = pr.at([540, 540]);+ const yk = 1 - 0.55 * ramp(f, 285, 335), sk = 0.18 * ramp(f, 290, 340), k = cam.S * env.scale;+ ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0);+ ctx.translate(c[0] * env.scale, c[1] * env.scale); ctx.transform(k, sk * k * 0.35, -sk * k, k * yk, 0, 0);+ ctx.globalAlpha = 1; ctx.imageSmoothingEnabled = true;+ ctx.drawImage(L.canvas as CanvasImageSource, -540 * env.scale, -540 * env.scale, env.W * env.scale, env.H * env.scale);+ ctx.restore();+};++// ---------------------------------------------------------------- the NEAR world, stages M to R+const nearFrame = (ctx: Ctx, env: Env, f: number) => {+ const cam = camAt(f), W = env.W, H = env.H, g = new Gfx(ctx, env, f, PENCIL);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = PAPER_F; ctx.fillRect(0, 0, W, H);+ g.paper("coldpress", 0.16);+ const meadow = ramp(f, 262, 330); /* the scenery arrives from behind the sheet as the camera rises */+ if (meadow > 0) {+ g.group("plain", () => backdrop(g, cam, W, H), { alpha: meadow });+ g.group("plain", () => backGrass(g, cam, 3.5, 4601, 26, 0.55, 0.06), { alpha: 0.9 * meadow, blur: 3.4 });+ g.group("plain", () => backGrass(g, cam, 2.2, 4602, 24, 0.34, 0.08), { alpha: 0.92 * meadow, blur: 2.2 });+ g.group("plain", () => backGrass(g, cam, 1.0, 4603, 20, 0.14, 0.1), { alpha: 0.95 * meadow, blur: 1.1 });+ const dips: Record<string, number> = {};+ LANDINGS.forEach((l) => { const off = TAKEOFFS.find((t) => t > l.at) ?? 1e9; if (f >= l.at && f <= off + 30) { const t = f - l.at, s = t < 12 ? 1.35 * (1 - Math.pow(1 - t / 12, 2)) : 1 + 0.35 * Math.cos((t - 12) * 0.34) * Math.exp(-(t - 12) / 14); dips[l.flower] = f <= off ? s : s * Math.max(0, 1 - (f - off) / 24); } });+ const gust = GUSTS.reduce((a, gt) => (f >= gt && f < gt + 70 ? a + 0.12 * Math.sin(((f - gt) / 70) * Math.PI) : a), 0);+ g.group("plain", () => drawClump(g, cam, f, { dip: dips, lean: 0.05 + gust }), { alpha: 0.99 * meadow });+ }+ // ---- the sheet: live at the macro, then its own cached surface, only ever downscaled+ if (f < 285) {+ const st: PlateState = { wings: { flap: 1, sweep: 0 }, lift: liftAt(f), keyY: 0, keyTurn: 0, train: trainAt(f), shadow: f > 180 && f < 240 ? [((f - 180) / 60) * 14, ((f - 180) / 60) * 20] : [0, 0], boil: 1, inkedBoil: 1, boilIndex: Math.floor(f / 4), p: FULL, view: { cx: cam.look[0], cy: cam.look[1], zoom: cam.S } };+ drawPlate(ctx, env, st);+ if (f >= TAKEOFFS[0]) { const pr = projector(cam, 0); g.group("plain", () => knockOut(g, pr.at), { alpha: 1 }); }+ } else if (f < 345) sheetOnto(ctx, env, cam, f);+ // ---- the water, only while it is still making the creature+ const wt = f < 130 ? wetnessAt(f) : ALL_WET;+ const w = whereAt(f), pose = poseAt(f), pr = projector(cam, 0), at = pr.at(w.at);+ if (w.perched && f >= 345) {+ const host = hostOf(w.on), hp = projector(cam, host.z), hs = hp.at(host.at), R = host.R * hp.k;+ const n = nod(host.seed, f), well: P = [hs[0] - R * 0.02, hs[1] + R * 0.11 + n * R * 0.1];+ const sip = SIPS.find(([a, b]) => f >= a - 20 && f <= b + 10), land = LANDINGS.find((l) => l.flower === w.on)!;+ const p = sip ? clamp((f - sip[0] + 10) / 10) : 0, beat = 0.5 - 0.5 * Math.cos(((f - land.at) / 15) * Math.PI * 2);+ /* TOP / three-quarter, wings OPEN. The head is turned down toward the throat so the proboscis+ reaches it without crossing the body, and the body's form shading is computed in SCREEN space,+ so turning the creature never moves the sun off the upper right. */+ const fan = 0.5 - 0.5 * Math.cos(((f - land.at) / 30) * Math.PI * 2);+ const head: Flight = { pose: { flap: 0.96 - 0.16 * fan, sweep: -0.02 - 0.02 * fan }, heading: 2.78 + 0.05 * Math.sin((f - land.at) * 0.06), pitch: 0.9, bank: 0.06 + 0.04 * Math.sin((f - land.at) * 0.19) };+ const sit: P = [well[0] - 58 * cam.S, well[1] - 168 * cam.S];+ g.group("plain", () => paintCreature(g, sit, cam.S * (1 + beat * 0.008), head, { proboscis: p, probTo: well, shadow: 1, shadowOff: [-0.55, 0.85], legs: 1, behind: PAINTS[host.v].mid, seed: 900 }), { alpha: 0.99 });+ } else {+ g.group("plain", () => paintCreature(g, at, cam.S, pose, { wetness: wt, groundLift: f < 130, shadow: f > 180 && f < 300 ? ramp(f, 180, 240) * (1 - ramp(f, 260, 300)) : 0, shadowOff: [-0.35, 0.45], legs: f >= 135 ? ramp(f, 135, 150) * (f > 240 ? 0.25 : 1) : 0, seed: 900 }), { alpha: 0.98 });+ if (f < 130) { const T = mapper(at, cam.S, pose), Wg = wingsOf(pose); g.group("plain", () => frontRim(g, T, cam.S * 90, Wg, f, wt), { alpha: 0.9 }); if (f < 60) { const c = cen(Wg[3].panels[2]), lp = liftAt(f); g.group("plain", () => drop(g, T([c[0] + 58 * lp, c[1] - 60 * lp]), cam.S * 26, f), { alpha: 1 }); } }+ }+ if (f >= SEED_FLUFF) g.group("plain", () => seedFluff(g, cam, f), { alpha: 0.7, blur: 1.4 });+ if (meadow > 0.4) fringe(g, cam, 0.05);+ g.paper("washGran", 0.05); g.paper("coldpress", 0.07);+};+const liftAt = (f: number): number => { if (f <= 45) return 1; if (f >= PANEL2_HOME + 6) return 0; const u = clamp((f - 45) / 15), e = 1 - Math.pow(1 - u, 3); return Math.max(-0.06, 1 - e) + (f > PANEL2_HOME ? -0.06 * Math.sin(((f - PANEL2_HOME) / 6) * Math.PI) : 0); };+const trainAt = (f: number) => { const n = Math.floor(f / 5) + (f >= 130 ? 1 : 0), th = n * 0.42; return { centre: th, third: th * 2.1, pinion: th * 4.4, escape: -th * 3.2, fork: Math.sin(n * 1.7) * 0.22 }; };++// ---------------------------------------------------------------- the FINALE world, stages F and W+const DRIFTS: [number, Drift][] = [+ [3.5, { sp: "buttercup", at: [470, 545], r: 150, n: 26, size: 5.5, seed: 7101 }],+ [3.5, { sp: "buttercup", at: [700, 560], r: 120, n: 16, size: 5, seed: 7102 }],+ [3.5, { sp: "daisy", at: [200, 560], r: 130, n: 12, size: 5, seed: 7103 }],+ [2.2, { sp: "poppy", at: [780, 655], r: 170, n: 20, size: 9, seed: 7201 }],+ [2.2, { sp: "cosmos", at: [640, 640], r: 90, n: 9, size: 11, seed: 7202 }],+ [2.2, { sp: "daisy", at: [250, 660], r: 120, n: 14, size: 8, seed: 7203 }],+ [1.0, { sp: "cornflower", at: [250, 690], r: 95, n: 13, size: 13, seed: 7301 }],+ [1.0, { sp: "daisy", at: [430, 720], r: 150, n: 16, size: 12, seed: 7302 }],+ [1.0, { sp: "cosmos", at: [760, 700], r: 110, n: 8, size: 13, seed: 7303 }],+];+// D runs from the clump out to the approved still's 0.8, and the look-at lands on its composition+const fcamAt = (f: number): FCam => {+ const t = ease(clamp((f - 575) / 175)), t2 = ease(clamp((f - 750) / 120));+ return { D: 0.26 + (0.8 - 0.26) * t + 0.012 * t2, look: [520 - 190 * t + 0 * t2, 800 - 190 * t] };+};+const POPPY: P = [800, 640]; // the field poppy it touches down on at 810, deeper in the field+const wideFrame = (ctx: Ctx, env: Env, f: number) => {+ const W = env.W, H = env.H, g = new Gfx(ctx, env, f, PENCIL), cam = fcamAt(f);+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = PAPER_F; ctx.fillRect(0, 0, W, H);+ g.paper("coldpress", 0.16);+ const open = ramp(f, 570, 660); /* the sky and the hills arrive as the camera clears the stems */+ if (open > 0) { g.group("plain", () => sky(g, cam, W, H), { alpha: open }); g.group("plain", () => hills(g, cam), { alpha: open }); g.group("plain", () => farField(g, cam), { alpha: open }); }+ const gust = GUSTS.reduce((a, gt) => (f >= gt && f < gt + 90 ? a + 0.1 * Math.sin(((f - gt) / 90) * Math.PI) : a), 0);+ const lean = 0.05 + gust + 0.02 * Math.sin(f * 0.03);+ ([[3.5, 545, 61, 26, 0.06, 0.3], [2.2, 640, 67, 34, 0.08, 0.12], [1.0, 706, 71, 46, 0.1, 0]] as number[][]).forEach(([z, y0, seed, n, ln, fade]) => {+ g.group("plain", () => { grassWash(g, cam, z, y0, seed, { lean: ln + gust, fade, cool: z === 1 }); if (z === 3.5) footpath(g, cam); }, { alpha: 1 });+ g.group("plain", () => grassBlades(g, cam, z, y0, seed, { blades: n, lean: ln + gust, fade }), { alpha: 0.95 });+ const pr = fprojector(cam, z);+ g.group("plain", () => DRIFTS.filter(([dz]) => dz === z).forEach(([, d]) => drift(g, d, pr.at, pr.k, lean)), { alpha: 0.97 });+ });+ const h0 = fprojector(cam, 0), h1 = fprojector(cam, 0.3);+ g.group("plain", () => {+ if (f >= 700) blueprintSheet(g, h0.at([150, 965]), 150 * h0.k); /* what it left behind, back in frame lower left, never pointed at */+ ([[330, 830, 34, 7401, 0], [250, 880, 26, 7402, 1]] as number[][]).forEach(([x, y, s, sd, v]) => flower(g, "daisy", h0.at([x, y]), s * h0.k, sd, { variant: v, lean }));+ ([[560, 800, 30, 7403, 0], [650, 840, 22, 7404, 3]] as number[][]).forEach(([x, y, s, sd, v]) => flower(g, "poppy", h1.at([x, y]), s * h1.k, sd, { variant: v, lean }));+ }, { alpha: 0.98 });+ // ---- the creature: along the path, down on a poppy at 810, then up the field toward us+ const cr = creatureWide(f, cam);+ if (cr) g.group("plain", () => paintCreature(g, cr.at, cr.scale, cr.flight, { shadow: cr.low, shadowOff: [-0.5, 0.6], legs: cr.perched ? 1 : 0.2, proboscis: cr.sip, probTo: cr.probTo, seed: 900 }), { alpha: 0.99 });+ whites(g, f, cam);+ const fr = fprojector(cam, -0.2);+ if (f < 700) g.group("plain", () => { ([[-40, 1120], [180, 1160], [900, 1150], [1120, 1090], [620, 1180]] as P[]).forEach((w0, i) => grassClump(g, fr.at(w0), (240 + i * 34) * fr.k, 60 * fr.k, [GRASS_SHADE, GRASS_MID, GRASS_LIT][i % 3], 7500 + i, 0.06 + i * 0.02, 6, 0.3)); }, { alpha: 0.5 * (1 - ramp(f, 620, 700)), blur: 2.2 });+ if (f >= CORNER_LIFT[0]) g.group("plain", () => { clearCorner(g, ramp(f, CORNER_LIFT[0], CORNER_LIFT[1])); signature(g, clamp((f - SIGNATURE[0]) / (SIGNATURE[1] - SIGNATURE[0])), 0.75 - 0.15 * ramp(f, DING, 1245)); }, { alpha: 1 });+ g.paper("washGran", 0.05); g.paper("coldpress", 0.07);+};++// its flight through the last three stages, in finale-world coordinates+const creatureWide = (f: number, cam: FCam) => {+ const off = 620, arrive = HOVER, end: P = [246, 648];+ let world: P, z: number, k: number;+ if (f < off) { /* the climb out of the clump, along the field: stage F keeps its move and loses its stop */+ const t = ease(clamp((f - 575) / 45));+ world = [540 + (POPPY[0] - 540) * t + Math.sin(t * Math.PI * 1.7) * 90, 760 + (POPPY[1] - 760) * t - Math.sin(t * Math.PI) * 120];+ z = 1.2 + 1.0 * t; k = 0.2 - 0.06 * t;+ } else { /* it turns and comes UP the field to the foreground, GROWING as the world shrinks */+ const t = ease(clamp((f - off) / (arrive - off)));+ z = 2.2 + (1.0 - 2.2) * t; /* the depth the spec asks for, kept short of the camera plane: the+ finale projector divides by (D + z) and turns inside out at z = -D, so the approach is carried+ by the creature's own scale rather than by flying it through the lens */+ k = 0.14 + (0.36 - 0.14) * t;+ world = [POPPY[0] + (end[0] - POPPY[0]) * t + Math.sin(t * Math.PI * 2.3) * 60, POPPY[1] + (end[1] - POPPY[1]) * t - Math.sin(t * Math.PI) * 70];+ if (f >= arrive) { const u = (f - arrive) / 60; world = [end[0] + Math.sin(u * Math.PI * 2) * 16, end[1] + Math.sin(u * Math.PI * 4) * 9 - (f - arrive) * 0.05]; k = 0.36; z = 1.0; } /* the approved still's position, hovering */+ }+ const pr = fprojector(cam, z), ph = (f % 10) / 10, flap = 0.6 + 0.4 * Math.cos(ph * Math.PI * 2);+ const scale = Math.max(0.105, k * pr.k); /* readability floor: below about 80 px of wingspan it stops being a butterfly and becomes a speck */+ return { at: pr.at(world), scale, perched: false, low: 0, sip: 0, probTo: undefined as P | undefined, flight: { pose: { flap, sweep: -0.03 }, heading: 0.1 * Math.sin(f * 0.05), pitch: 0.94, bank: 0.08 * Math.sin(f * 0.09) } as Flight };+};+// two REAL white butterflies lift out of the grass and spiral round it, then peel away+const whites = (g: Gfx, f: number, cam: FCam) => {+ if (f < WHITES[0] || f > WHITES[1]) return;+ const pr = fprojector(cam, 1.6);+ for (let k = 0; k < 2; k++) {+ const t = (f - WHITES[0]) / (WHITES[1] - WHITES[0]), a = f * 0.08 + k * Math.PI;+ const w: P = [820 - t * 420 + Math.cos(a) * 60, 700 - t * 300 + Math.sin(a) * 40 - t * t * 260];+ const p = pr.at(w), s = 26 * pr.k * (1 - t * 0.3), fl = 0.4 + 0.6 * Math.abs(Math.cos(f * 0.32 + k));+ g.fill([[p[0] - s * fl, p[1] - s * 0.7], [p[0] - s * 0.1, p[1] - s * 0.2], [p[0] - s * 0.8 * fl, p[1] + s * 0.5]], "#fbf8ef", 0.85);+ g.fill([[p[0] + s * fl, p[1] - s * 0.7], [p[0] + s * 0.1, p[1] - s * 0.2], [p[0] + s * 0.8 * fl, p[1] + s * 0.5]], "#f4efe2", 0.8);+ g.fill([[p[0] - s * 0.09, p[1] - s * 0.34], [p[0] + s * 0.09, p[1] - s * 0.3], [p[0] + s * 0.06, p[1] + s * 0.3], [p[0] - s * 0.06, p[1] + s * 0.3]], "#6b6250", 0.7);+ }+};++// ---------------------------------------------------------------- the movement+export const drawAlive = (ctx: Ctx, env: Env, f: number) => {+ if (f < HANDOVER[0]) return nearFrame(ctx, env, f);+ if (f >= HANDOVER[1]) return wideFrame(ctx, env, f);+ const t = ease((f - HANDOVER[0]) / (HANDOVER[1] - HANDOVER[0]));+ nearFrame(ctx, env, f);+ const dw = Math.round(env.W * env.scale), dh = Math.round(env.H * env.scale);+ let L = env.cache.get("alive:dissolve") as Layer | undefined;+ if (!L) { L = env.canvas(dw, dh); env.cache.set("alive:dissolve", L); }+ L.ctx.setTransform(1, 0, 0, 1, 0, 0); L.ctx.globalAlpha = 1; L.ctx.globalCompositeOperation = "source-over"; L.ctx.clearRect(0, 0, dw, dh);+ wideFrame(L.ctx, env, f);+ ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = t; ctx.drawImage(L.canvas as CanvasImageSource, 0, 0); ctx.restore();+};diff --git a/example/src/canvas-core/butterfly/alive/perch.ts b/example/src/canvas-core/butterfly/alive/perch.tsnew file mode 100644index 0000000..b3a8983--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/perch.ts@@ -0,0 +1,94 @@+// BEATS 3 AND 4, THE RANUNCULUS CLOSE-UP. The heart of the film, held for six bars so it has+// time to be believed. The camera only creeps and drifts sideways with the creature, stepping+// back a little on each take-off; the creature lands, sips, and goes on to the next head.+//+// This composes stage R for any frame. The approval still is local 390: thirty frames after the+// landing on R1, with the proboscis down in the tight green centre and the head still carrying+// the dip it took when the creature arrived on it.+import { Ctx, Env, Gfx, P, PENCIL } from "../../core";+import { PAPER_F } from "../finale/compose";+import { LANDINGS, SIPS, PROBOSCIS, TAKEOFFS } from "./cues";+import { PAINTS, head } from "./ranunculus";++export const LATERAL = ["R1", "R3"]; // spec 5.7: at least two of the four visits are the lateral figure+import { CLUMP, R_LOOK, backGrass, backdrop, drawClump, fringe, nod, seedFluff } from "./meadow2";+import { Cam, projector, scaleOf } from "./view";+import { Flight, paintCreature } from "./wingpaint";+import { drawLateral } from "./lateral";++export const camAt = (f: number): Cam => ({ S: scaleOf(f), look: R_LOOK });++// A visited head dips when the creature lands on it and rebounds when it leaves: stem bends about+// six degrees, one settle, and nothing else in the clump moves with it.+const dipOf = (f: number) => {+ const out: Record<string, number> = {};+ LANDINGS.forEach((l, i) => {+ const off = TAKEOFFS.find((t) => t > l.at) ?? 1e9;+ if (f < l.at || f > off + 30) return;+ const t = f - l.at;+ const settle = t < 12 ? 1.35 * (1 - Math.pow(1 - t / 12, 2)) : 1 + 0.35 * Math.cos((t - 12) * 0.34) * Math.exp(-(t - 12) / 14);+ out[l.flower] = f <= off ? settle : settle * Math.max(0, 1 - (f - off) / 24);+ });+ return out;+};+// It is never still. Wings fan on a 30-frame cycle at an amplitude of about a third, one side+// leads the other, and the abdomen pulses once a beat: the tick has become a heartbeat.+const perched = (f: number, landed: number): Flight => {+ const t = f - landed, fan = 0.5 - 0.5 * Math.cos((t / 30) * Math.PI * 2);+ return { pose: { flap: 1 - 0.35 * fan, sweep: -0.02 - 0.03 * fan }, heading: -2.35 + 0.05 * Math.sin(t * 0.08), pitch: 0.9, bank: 0.07 + 0.03 * Math.sin(t * 0.21) };+};++export type PerchState = { f: number; on: string };+export const drawPerch = (ctx: Ctx, env: Env, f: number, on = "R1") => {+ const W = env.W, H = env.H, g = new Gfx(ctx, env, f, PENCIL), cam = camAt(f), c = ctx;+ c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.fillStyle = PAPER_F; c.fillRect(0, 0, W, H);+ g.paper("coldpress", 0.16);+ g.group("plain", () => backdrop(g, cam, W, H), { alpha: 1 });+ g.group("plain", () => backGrass(g, cam, 3.5, 4601, 46, 0.55, 0.06), { alpha: 0.9, blur: 3.4 }); /* aerial perspective is the only way distance reads in paint: paler, bluer, softer, no drawing */+ g.group("plain", () => backGrass(g, cam, 2.2, 4602, 40, 0.34, 0.08), { alpha: 0.92, blur: 2.2 });+ g.group("plain", () => backGrass(g, cam, 1.0, 4603, 32, 0.14, 0.1), { alpha: 0.95, blur: 1.1 });++ const land = LANDINGS.find((l) => l.flower === on), dips = dipOf(f);+ g.group("plain", () => drawClump(g, cam, f, { dip: dips, lean: 0.05 }), { alpha: 0.99 });++ // ---- the creature, perched on the head it landed on. Spec 5.7: at least two of the four+ // ranunculus visits are LATERAL, wings closed over the back, which is how a butterfly actually+ // sips and what a plate shows beside the dorsal figure. R1 and R3 are the two.+ const host = CLUMP.find((p) => p.id === on);+ if (host && land && f >= land.at) {+ const pr = projector(cam, host.z), hs = pr.at(host.at), R = host.R * pr.k;+ const dip = dips[on] ?? 0, n = nod(host.seed, f);+ const well: P = [hs[0] + (dip + n) * R * 0.12 - R * 0.02, hs[1] + (dip + n) * R * 0.1 + R * 0.11];+ const sip = SIPS.find(([a, b]) => f >= a - 20 && f <= b + 10);+ const p = sip ? Math.max(0, Math.min(1, (f - PROBOSCIS[0]) / (PROBOSCIS[1] - PROBOSCIS[0]))) : 0;+ const beat = 0.5 - 0.5 * Math.cos(((f - land.at) / 15) * Math.PI * 2); /* one soft pulse per beat while it sips: the heartbeat */+ if (LATERAL.includes(on)) {+ const at: P = [well[0] + R * 0.5, well[1] - R * 0.5];+ const grip: P[] = [[well[0] + R * 0.16, well[1] - R * 0.04], [well[0] + R * 0.42, well[1] + R * 0.06], [well[0] + R * 0.68, well[1] + R * 0.1]];+ g.group("plain", () => drawLateral(g, { at, scale: cam.S * (1 + beat * 0.008), face: -1, lean: 0.52 + 0.03 * Math.sin((f - land.at) * 0.07), open: 0.16 + 0.1 * (0.5 - 0.5 * Math.cos(((f - land.at) / 30) * Math.PI * 2)), proboscis: p, probTo: well, grip, seed: 900 }), { alpha: 0.98 });+ } else {+ const at: P = [well[0] + R * 0.42, well[1] - R * 0.56];+ g.group("plain", () => paintCreature(g, at, cam.S * (1 + beat * 0.008), perched(f, land.at), { proboscis: p, probTo: well, shadow: 1, shadowOff: [-0.8, 0.95], legs: 1, behind: PAINTS[host.v].mid, seed: 900 }), { alpha: 0.98 });+ }+ }++ g.group("plain", () => seedFluff(g, cam, f), { alpha: 0.7, blur: 1.4 });+ fringe(g, cam, 0.05);+ g.paper("washGran", 0.05); g.paper("coldpress", 0.07);+};++// ---------------------------------------------------------------- G-R, the study sheet+// The five hand-authored views in three colours at full level of detail, which is the sheet a+// painter would put on the wall before starting the picture. Nothing here is in the film.+export const drawViews = (ctx: Ctx, env: Env) => {+ const W = env.W, H = env.H, g = new Gfx(ctx, env, 0, PENCIL), c = ctx;+ c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.fillStyle = PAPER_F; c.fillRect(0, 0, W, H);+ g.paper("coldpress", 0.18);+ const views = ["facing", "three", "profile", "half", "bud"] as const, cols = ["coral", "blush", "butter"] as const;+ const x0 = 118, y0 = 190, dx = 202, dy = 300;+ cols.forEach((v, row) => views.forEach((view, col) => {+ const at: P = [x0 + col * dx, y0 + row * dy], R = view === "bud" ? 52 : 86;+ g.group("paint", () => head(g, at, R, v, { view, tilt: (col - 2) * 0.09 + (row - 1) * 0.05, seed: 3000 + row * 41 + col * 7, reserve: false }), { alpha: 0.99 });+ }));+ g.paper("coldpress", 0.07);+};diff --git a/example/src/canvas-core/butterfly/alive/ranunculus.ts b/example/src/canvas-core/butterfly/alive/ranunculus.tsnew file mode 100644index 0000000..74086d9--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/ranunculus.ts@@ -0,0 +1,288 @@+// RANUNCULUS ASIATICUS, the Persian buttercup. Spec 6.1 is binding and it is a craft brief, not+// a shape brief: the head is painted FROM THE CENTRE OUT as short overlapping C-strokes circling+// a tight green button, each ring larger and looser than the last, with slivers of bare paper+// LEFT between the strokes. Those slivers are the petal edges. There is no concentric scallop,+// no mathematical spiral, and no ring of separate ovals anywhere in this file.+//+// PHOTOGRAPHS STUDIED before a point was moved (spec 6.1 asks which; these are the three I+// actually opened, not a list from memory):+// 1. Alamy HX5F8J, "close up of Ranunculus asiaticus petals opening": a macro straight into the+// centre of a red-on-yellow bloom. What it settles: the centre is NOT a flat yellow button.+// It is a dark green-black domed receptacle, finely stippled, with a pale green star at its+// apex, sitting at the bottom of a WELL. The innermost whorl stands almost vertical around+// that well as narrow creased strips; petals widen and flatten ring by ring outward; every+// ring sits in the gaps of the one inside it; each petal carries a darker edge, and the+// overlap between two petals reads as a bright hairline.+// 2. TopTropicals `ranunculus_asiaticus3857`, a white bloom from above and slightly in front.+// What it settles: the head is TWO ZONES, and this is the whole read. A broad outer SKIRT of+// a few large, pale, nearly flat petals that reflex downward, and a much smaller, tighter,+// GREEN-hearted inner cup raised inside it. Also: the foliage is dark, deeply cut and+// parsley-like, and a bud on the same plant is a clasped green ball.+// 3. BigCommerce "Wholesale Coral Ranunculus", one whole cut stem. What it settles: the+// proportions. The stem runs about three and a half head-widths long, has its own S-curve,+// thickens toward the base, swells green at the neck, carries its deeply cut leaves around+// the middle of its length with a side bud on a short branch, and the head NODS a few+// degrees off the stem's axis rather than sitting square on it.+//+// The head is built as real cup geometry, not as a flat pattern: a petal knows its radius, its+// angle and its HEIGHT in the bowl, and the view is that bowl seen at an elevation. Which is why+// the three-quarter view gets its stacked crescents and the profile gets its cup for free.+import { Gfx, P, displace, jitter, oval, rng, sample, tube } from "../../core";+import { lift } from "../finale/paint";++export type View = "facing" | "three" | "profile" | "half" | "bud";+export type Variety = "coral" | "blush" | "butter" | "magenta" | "peach";++// Colour sets read off the references: a mid, a dark for the wells and the shadow side, a pale+// for the lit rim of the skirt, and the edge tint that rides the outer margin (the picotee).+type Paints = { mid: string; dark: string; pale: string; edge: string; heart: string };+export const PAINTS: Record<Variety, Paints> = {+ coral: { mid: "#ee8a70", dark: "#cf5a3f", pale: "#f9c6b0", edge: "#d9603f", heart: "#dfa86a" },+ blush: { mid: "#f6ece4", dark: "#c9b4ac", pale: "#fffbf5", edge: "#e0819a", heart: "#e6dcab" }, // blush white with a pink picotee edge+ butter: { mid: "#f3d577", dark: "#d8a83c", pale: "#fbeeb6", edge: "#dfae3f", heart: "#c9c657" },+ magenta: { mid: "#b8417e", dark: "#7c2154", pale: "#d98cb0", edge: "#8d2a63", heart: "#c98f6a" },+ peach: { mid: "#f5b98a", dark: "#dd8a5f", pale: "#fbdcc0", edge: "#e0906a", heart: "#e2c37e" },+};+export const SEPAL = "#7d9a52", STEM_G = "#88a457", STEM_SHADE = "#5e7a42", LEAF = "#55713f", LEAF_LIT = "#7b9455";+const BUTTON = "#b7c150", BUTTON_DARK = "#3f4a28", BUTTON_STAR = "#e6e6a6", WELL = "#6d7a42", PAPER = "#fbf7ee", COOL = "#8ea3c4";++// Elevation of the camera above the flower's own plane, per view. 1 = straight down the throat,+// 0 = edge on. Everything else about a view follows from this one number, the ring set and the+// sepals: there is no per-view special casing of shape anywhere below.+const ELEV: Record<View, number> = { facing: 0.95, three: 0.6, profile: 0.16, half: 0.82, bud: 0.5 };++// The bowl, in units of the head radius: height above the rim plane at radius t. A deep dark well+// at the centre, a crest about three quarters out where the skirt is widest, and only a SLIGHT+// reflex past it. This one curve is what makes the three-quarter view stack its crescents and+// the profile view sit up as a cup, so it is the shape of the flower and not a lighting trick.+const bowl = (t: number): number => (t < 0.74 ? -0.70 + 0.80 * Math.pow(t / 0.74, 1.5) : 0.10 - 0.20 * Math.pow((t - 0.74) / 0.26, 1.7));++// The rings, centre out. `r` is the fraction of the head radius the petal's MARGIN reaches, `n`+// the count, `w` its tangential half-width as a multiple of the even spacing, `into` how far back+// toward the centre it is attached, and `lift` how far it curls up out of the bowl.+// The two zones are the whole read (reference 2): a HEART of many small tight greener petals, and+// a SKIRT of a few big pale ones. A ranunculus with one uniform zone is a pompom.+type Ring = { r: number; n: number; w: number; into: number; lift: number; heart: boolean };+const RINGS: Ring[] = [+ { r: 0.62, n: 5, w: 1.38, into: 0.50, lift: 0.09, heart: false },+ { r: 0.76, n: 6, w: 1.34, into: 0.54, lift: 0.07, heart: false },+ { r: 0.89, n: 6, w: 1.34, into: 0.58, lift: 0.05, heart: false },+ { r: 1.00, n: 7, w: 1.32, into: 0.60, lift: 0.04, heart: false },+];+// A petal is a BLADE, not a fan: its inner edge is nearly as wide as its margin, because what+// narrows a real petal toward its base is hidden behind the ring inside it. Fans that all+// converge on the centre make a pinwheel, and a pinwheel is a mathematical spiral with extra+// steps. What breaks the four rings up instead is that no petal is the same size as its+// neighbour and none of them sits at quite the radius its ring says.+// The HEART is not rings. Concentric annuli of petals nest into a moulded shell, which is the+// scalloped-circle failure the spec rejects on sight. A real heart is a ROLLED WHORL: broad+// crescents that each wrap a third of the way round the centre, overlapping like a rose, laid+// biggest and lowest first and finishing on the small upright ones standing over the button.+// These twelve turn offsets are HAND PLACED, not a golden angle and not a step: no two gaps+// between consecutive petals are the same, which is what stops the eye finding the rule.+const TURNS = [0, 0.41, 0.77, 0.19, 0.6, 0.93, 0.33, 0.7, 0.08, 0.52, 0.86, 0.26];+// A half-open bloom has not let its skirt down yet: the outer rings are still drawn in and stood+// up round the green heart, so what you see is a cup closing rather than a disc.+const halfOpen = (rg: Ring): Ring => (rg.heart ? { ...rg, lift: rg.lift + 0.06 } : { ...rg, r: rg.r * 0.66, lift: rg.lift + 0.34, w: rg.w * 0.96, into: rg.into * 0.8 });++const mix = (a: string, b: string, t: number) => { const h = (x: string) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)]; const A = h(a), B = h(b); return "#" + A.map((v, i) => Math.round(v + (B[i] - v) * Math.max(0, Math.min(1, t))).toString(16).padStart(2, "0")).join(""); };++// A C-STROKE. The core's `wash` wobbles every outline by an ABSOLUTE thirteen units, which is+// right for a wing panel three hundred units across and turns a twenty-pixel petal into porridge.+// A petal therefore gets its own wash, wobbled in proportion to its own width, so a small one+// keeps the crisp dried edge that makes the stack of tissue read.+const cstroke = (g: Gfx, pts: P[], col: string, alpha: number, seed: number, w: number) => {+ const s = displace(sample(jitter(pts, w * 0.035, seed), true, 4), w * 0.07, 1.7 / Math.max(3, w), 2, (seed % 89) + 3);+ g.fill(s, col, alpha);+ return s;+};++// One head. `R` is its radius ON SCREEN, `tilt` the nod off the stem's axis in radians, and the+// sun is upper right, so the lit side of every petal is the side facing about -0.9 rad.+export type HeadOpts = { view?: View; tilt?: number; seed?: number; reserve?: boolean; dip?: number };+export const head = (g: Gfx, at: P, R: number, v: Variety, o: HeadOpts = {}) => {+ const view = o.view ?? "facing", seed = o.seed ?? 1, r = rng(seed), C = PAINTS[v], tilt = (o.tilt ?? 0) + (o.dip ?? 0) * 0.16;+ if (view === "bud") return budHead(g, at, R, v, seed, tilt);+ // ---- level of detail, spec 6.1. Below these sizes a painter stops drawing the flower and+ // starts putting down what the flower does to the picture: two tones, then one dab.+ if (R < 7) { g.fill(oval(at[0], at[1], R * 1.15, R * 0.95, 8), C.mid, 0.8); return; }+ if (R < 20) { g.fill(oval(at[0] - R * 0.22, at[1] + R * 0.24, R * 1.05, R * 0.86, 9), C.dark, 0.5); g.fill(oval(at[0], at[1], R * 1.1, R * 0.92, 9), C.mid, 0.9); g.fill(oval(at[0], at[1], R * 0.28, R * 0.24, 7), mix(BUTTON, WELL, 0.4), 0.85); return; }+ const set = (R < 60 ? [RINGS[0], RINGS[2], RINGS[3]] : RINGS).map((rg) => (view === "half" ? halfOpen(rg) : rg)); // 40 to 120 px: three rings of strokes and the button++ const e = ELEV[view], ce = Math.sqrt(Math.max(0, 1 - e * e)), ct = Math.cos(tilt), st = Math.sin(tilt);+ // bowl point -> screen. X across, Y away from the camera, Z up out of the cup, then the nod.+ const T = (ang: number, rad: number, z: number): P => {+ const X = Math.cos(ang) * rad, Y = Math.sin(ang) * rad, sy = -(Y * e + z * ce);+ return [at[0] + (X * ct - sy * st) * R, at[1] + (X * st + sy * ct) * R];+ };+ if (view === "profile" || view === "half") sepals(g, T, R, seed, view === "profile" ? 1 : 0.5);+ const edgeR = set[set.length - 1].r;+ if (o.reserve !== false) { const sil: P[] = []; for (let i = 0; i < 20; i++) { const a = (i / 20) * Math.PI * 2; sil.push(T(a, edgeR * 0.93, bowl(edgeR) + 0.02)); } g.fill(jitter(sil, R * 0.03, seed + 1), PAPER, 0.5); } /* the paper is LEFT for it: a wash over white glows, a wash over green does not */++ const ring = (rg: Ring, i: number) => {+ const t = rg.r, phase = r() * Math.PI * 2, step = (Math.PI * 2) / rg.n, half = step * 0.5 * rg.w;+ const zIn = bowl(t * rg.into), zOut = bowl(t) + rg.lift, outermost = i === set.length - 1;+ const pw = 2 * half * t * R; /* the petal's own width on screen: everything wobbles in proportion to this */+ const petals = Array.from({ length: rg.n }, (_, k) => phase + k * step + (r() - 0.5) * step * 0.22);+ petals.sort((a, b) => T(a, t, zOut)[1] - T(b, t, zOut)[1]); /* the far side of the bowl is behind the near side */+ petals.forEach((a, k) => {+ const lit = 0.5 + 0.5 * Math.cos(a + 0.9 - tilt), s2 = seed + i * 31 + k * 7, rr = rng(s2);+ const ruf = 0.03 + rr() * 0.045, skew = (rr() - 0.5) * 0.3, notch = outermost ? 0.045 + rr() * 0.04 : 0, size = 0.82 + rr() * 0.38, shove = (rr() - 0.5) * 0.13; /* hand-placed: no two petals in a ring reach the same distance, so the margin is never a circle */ /* one side always leads, and the big outer petals are notched at the top */+ const N = 9, outer: P[] = [], band: P[] = [];+ for (let q = 0; q < N; q++) {+ const u = q / (N - 1), ang = a + (u - 0.5) * 2 * half * (1 + skew * (u - 0.5));+ const rad = t * size + t * shove + t * size * (ruf * Math.sin(u * Math.PI * 2.2 + s2) - notch * Math.exp(-Math.pow((u - 0.5) * 4, 2)));+ outer.push(T(ang, rad, zOut)); band.push(T(ang, rad * 0.86, zOut * 0.95));+ }+ const inner: P[] = []; for (let q = 3; q >= 0; q--) { const u = q / 3, ang = a + (u - 0.5) * 2 * half * 0.84; inner.push(T(ang, (t * size + t * shove) * rg.into, zIn)); }+ // Value. The heart is CREAM AND GREEN, lighter than the throat it stands in, which is the+ // only way the tight inner whorl reads as petals instead of one dark mass; the dark in the+ // heart is the throat showing between the strokes, never paint on the strokes themselves.+ const vary = (rr() - 0.5) * 0.2; /* no two petals in a ring are the same value: that is what stops a ring reading as one moulded shell */+ const base = rg.heart ? mix(mix(C.pale, C.heart, 0.5 + vary), BUTTON_STAR, 0.24 - t * 0.35) : mix(C.mid, C.pale, (t - 0.5) * 0.95 + lit * 0.42 + vary);+ const col = mix(base, C.dark, (1 - lit) * (rg.heart ? 0.3 : 0.38) + Math.max(0, vary));+ cstroke(g, [...outer, ...inner], col, rg.heart ? 0.93 : 0.9, s2, pw);+ /* a petal is darker where it folds down into the cup and paler at the margin the light hits:+ one more stroke on the inner half, not a gradient */+ const half2: P[] = []; for (let q = 0; q < N; q++) { const u = q / (N - 1), ang = a + (u - 0.5) * 2 * half * 0.9; half2.push(T(ang, (t * size + t * shove) * (rg.into + (1 - rg.into) * 0.42), (zIn + zOut) / 2)); }+ cstroke(g, [...half2, ...inner], mix(col, rg.heart ? WELL : C.dark, rg.heart ? 0.4 : 0.3), rg.heart ? 0.72 : 0.5, s2 + 2, pw * 0.7);+ /* pigment settles where the water stopped: a darker rim along the outer margin only, which+ is a dried edge and not an outline, because it never goes round the sides */+ g.fill(tube(outer.slice(1, N - 1), pw * 0.025, pw * 0.012, false), mix(col, C.dark, 0.55), 0.34 + (1 - lit) * 0.2);+ /* and the shadow the petal in front throws on it: this is what opens the stack up */+ g.fill(tube([T(a + (skew > 0 ? -half : half) * 0.92, t * 0.62, (zIn + zOut) / 2), outer[skew > 0 ? 0 : N - 1]], pw * 0.045, pw * 0.014, false), mix(col, WELL, 0.38), 0.26);+ if (R > 50 && !rg.heart) { const crease = [T(a, t * rg.into, zIn), T(a + skew * 0.12, t * 0.82, (zIn + zOut) / 2), T(a, t * 0.96, zOut)]; g.fill(tube(crease, pw * 0.012, pw * 0.005, false), mix(col, C.dark, 0.4), 0.2); }+ /* the picotee: a BAND of colour along the outer margin, which is what a picotee is. Every+ other variety gets the same band, quieter, as the colour its own margin dries to. */+ if (outermost && R > 40) cstroke(g, [...outer, ...band.slice().reverse()], C.edge, v === "blush" ? 0.55 : 0.25, s2 + 11, pw);+ });+ };++ for (let i = set.length - 1; i >= 0; i--) ring(set[i], i); /* the skirt was laid first and let dry */+ // the THROAT: the darkest value in the picture of this flower, and it goes UNDER the heart so+ // that what shows between the tight inner petals is depth rather than paper+ const cz = bowl(0), c0 = T(0, 0.001, cz), well: P[] = []; for (let i = 0; i < 14; i++) { const a = (i / 14) * Math.PI * 2; well.push(T(a, 0.42, bowl(0.42))); }+ cstroke(g, well, mix(C.dark, WELL, 0.22), 0.6, seed + 600, R * 0.75);+ cstroke(g, well.map((p) => [at[0] + (p[0] - at[0]) * 0.6, at[1] + (p[1] - at[1]) * 0.6] as P), mix(C.dark, "#4a4426", 0.45), 0.55, seed + 602, R * 0.45);+ whorl(g, T, R, C, seed, tilt, R >= 60 ? 9 : 5, view === "half" ? 0.78 : 1);++ // ---- the centre. A domed receptacle at the bottom of the well, finely stippled, with a pale+ // star at its apex and a ring of stamens round its foot (reference 1). Never a flat button.+ const cr = R * 0.08;+ if (R > 30 && view !== "profile") {+ const green = view === "half" ? mix(BUTTON, WELL, 0.68) : mix(BUTTON, WELL, 0.3);+ cstroke(g, oval(c0[0], c0[1], cr * 1.3, cr * (0.36 + e * 0.8), 11), green, 0.94, seed + 610, cr * 2);+ cstroke(g, oval(c0[0] - cr * 0.3, c0[1] + cr * 0.38, cr * 0.9, cr * 0.46 * (0.36 + e * 0.7), 10), mix(BUTTON_DARK, WELL, 0.45), 0.5, seed + 615, cr * 1.6);+ if (R > 60) {+ g.fill(oval(c0[0] + cr * 0.06, c0[1] - cr * 0.14, cr * 0.32, cr * 0.26 * (0.4 + e * 0.6), 9), BUTTON_STAR, 0.78);+ const rs = rng(seed + 620), n = view === "half" ? 8 : 18;+ for (let k = 0; k < n; k++) { const a = rs() * Math.PI * 2, d = cr * (1.4 + rs() * 0.55), p: P = [c0[0] + Math.cos(a) * d, c0[1] + Math.sin(a) * d * (0.3 + e * 0.65)]; g.fill(oval(p[0], p[1], R * 0.0075, R * 0.006, 6), BUTTON_DARK, 0.5 + rs() * 0.34); }+ }+ }+ // ---- one cool wash over the side away from the sun, laid as an annulus that hugs the rim, so+ // it never puts a chord across the middle of the flower. No outline anywhere on the head.+ for (let pass = 0; pass < 2; pass++) {+ const a0 = 1.15 + pass * 0.3, a1 = a0 + Math.PI * (0.95 - pass * 0.18), out: P[] = [], inn: P[] = [];+ for (let i = 0; i <= 8; i++) { const a = a0 + (i / 8) * (a1 - a0); out.push(T(a, edgeR * 0.98, bowl(edgeR))); inn.push(T(a, edgeR * (0.44 + pass * 0.2), bowl(0.55))); }+ cstroke(g, [...out, ...inn.reverse()], COOL, 0.09, seed + 700 + pass, R * 1.2);+ }+ g.fill(oval(at[0] - R * 0.5, at[1] + R * (0.38 + 0.4 * e), R * 0.62, R * 0.13, 9), "#6d7f55", 0.11); /* the dab of shadow it throws below itself */+};++// The rolled heart. Each crescent knows its radius, how far round it wraps, and how high it+// stands, so the three-quarter view stacks it into the overlapping arcs the reference shows and+// the facing view rolls it into a cone. The darkness between them is the throat, not paint.+const whorl = (g: Gfx, T: (a: number, r: number, z: number) => P, R: number, C: Paints, seed: number, tilt: number, n: number, squeeze: number) => {+ const r0 = rng(seed + 900), phase = r0();+ for (let k = n - 1; k >= 0; k--) {+ const u = n > 1 ? k / (n - 1) : 1, rr = rng(seed + 910 + k * 13);+ const t = (0.26 + 0.2 * Math.pow(u, 0.7) + (rr() - 0.5) * 0.09) * squeeze; /* a tight rosette of crescents at nearly one radius, each with its own reach: a monotone radius against a turning angle is a nautilus */+ const a = (TURNS[k % TURNS.length] + phase) * Math.PI * 2 + (rr() - 0.5) * 0.34;+ const half = 0.78 + 0.28 * u + (rr() - 0.5) * 0.26; /* it wraps between a third and a half of the way round */+ const zOut = bowl(t) + 0.3 * (1 - u) + 0.06, zIn = bowl(t * 0.5) + 0.34 * (1 - u);+ const lit = 0.5 + 0.5 * Math.cos(a + 0.9 - tilt), vary = (rr() - 0.5) * 0.22;+ const N = 11, outer: P[] = [], free: P[] = [], inner: P[] = [];+ for (let q = 0; q < N; q++) { const w = q / (N - 1), ang = a + (w - 0.5) * 2 * half, rad = t * (1 + 0.05 * Math.sin(w * 5.1 + k) - 0.07 * Math.pow(Math.abs(w - 0.5) * 2, 3)); outer.push(T(ang, rad, zOut)); free.push(T(ang, rad * 0.9, zOut * 0.99)); }+ for (let q = 4; q >= 0; q--) { const w = q / 4, ang = a + (w - 0.5) * 2 * half * 0.86; inner.push(T(ang, t * 0.5, zIn)); }+ const pw = 2 * half * t * R;+ const body = mix(mix(C.pale, C.mid, 0.46 + vary), BUTTON_STAR, Math.max(0, 0.38 * (1 - t / 0.22))); /* it keeps the flower's own hue and only goes green in the last few petals over the button */+ const col = mix(body, C.dark, (1 - lit) * 0.26 + Math.max(0, vary * 0.8));+ cstroke(g, [...outer, ...inner], col, 0.94, seed + 920 + k, pw);+ cstroke(g, [...inner, ...inner.map((p) => p).reverse().slice(0, 1), ...free.slice(2, N - 2).reverse()], mix(col, WELL, 0.42), 0.6, seed + 930 + k, pw * 0.8); /* the shade where it folds down into the throat */+ g.fill(tube(outer.slice(1, N - 1), pw * 0.022, pw * 0.01, false), mix(col, C.dark, 0.5), 0.3); /* pigment dried along the free edge */+ lift(g, tube(free.slice(2, N - 2), pw * 0.02, pw * 0.009, false), seed + 940 + k, 0.34); /* and the light sitting on the fold just inside it */+ }+};++// the green sepals a cup sits in, reflexed beneath it: only ever seen from the side+const sepals = (g: Gfx, T: (a: number, r: number, z: number) => P, R: number, seed: number, amt: number) => {+ const r = rng(seed + 77);+ for (let i = 0; i < 3; i++) {+ const a = -0.35 + (i / 2) * (Math.PI + 0.7) + (r() - 0.5) * 0.18;+ const base = T(a, 0.2, bowl(0.2) - 0.14), mid = T(a, 0.66, bowl(0.66) - 0.22 * amt), tip = T(a, 0.94, bowl(0.94) - 0.34 * amt);+ g.fill(tube([base, mid, tip], R * 0.075, R * 0.025, false), i === 1 ? SEPAL : STEM_SHADE, 0.88); /* broad straps that lie under the cup, not legs */+ }+};++// A BUD: a tight green ovoid clasped by sepals that hug it and flick out at their tips, nodding+// on its own stalk, with the first sliver of the petal colour showing at the crown. Every+// reference carries one on the plant, so the clump does too.+const budHead = (g: Gfx, at: P, R: number, v: Variety, seed: number, tilt: number) => {+ const C = PAINTS[v], r = rng(seed), ct = Math.cos(tilt), st = Math.sin(tilt);+ const T = (x: number, y: number): P => [at[0] + (x * ct - y * st) * R, at[1] + (x * st + y * ct) * R];+ if (R < 6) { g.fill(oval(at[0], at[1], R, R * 1.1, 7), SEPAL, 0.85); return; }+ const ball = jitter([...Array(13)].map((_, i) => { const a = (i / 13) * Math.PI * 2; return T(Math.cos(a) * 0.8, Math.sin(a) * 1.0 - 0.08); }), R * 0.045, seed);+ g.fill(ball, PAPER, 0.92);+ g.wash(ball, mix(C.pale, SEPAL, 0.5), { alpha: 0.8, seed, shrink: 0.95, rim: true });+ g.wash(ball.map((p) => [p[0] - R * 0.22, p[1] + R * 0.2] as P), STEM_SHADE, { alpha: 0.32, seed: seed + 4, shrink: 0.8, rim: false });+ /* the sepals do not radiate: they lie ON the bud from its foot and only their points leave it */+ for (let i = 0; i < 5; i++) {+ const a = -2.5 + i * 0.78 + (r() - 0.5) * 0.22, w = Math.cos(a), h = Math.sin(a);+ const foot = T(w * 0.18, 0.86), mid = T(w * 0.62, 0.86 - Math.abs(h) * 0.7), tip = T(w * 1.02, 0.5 - h * 0.66);+ g.fill(tube([foot, mid, tip], R * 0.15, R * 0.025, false), i % 2 ? SEPAL : STEM_SHADE, 0.88);+ }+ if (R > 16) { g.wash([T(-0.34, -0.86), T(0.1, -1.02), T(0.4, -0.78), T(0.0, -0.66)], C.mid, { alpha: 0.5, seed: seed + 8, shrink: 0.9, rim: true }); } /* the first sliver of colour, breaking out at the crown */+};++// ---------------------------------------------------------------- stem, leaves, the whole plant+// Every stem gets its OWN S-curve and thickness. Nothing here is straight (rejected on sight).+export const stem = (g: Gfx, root: P, neck: P, w: number, seed: number, lean = 0) => {+ const r = rng(seed), dx = neck[0] - root[0], dy = neck[1] - root[1], len = Math.hypot(dx, dy) || 1, nx = -dy / len, ny = dx / len;+ const bow = (0.05 + r() * 0.07) * len * (r() > 0.5 ? 1 : -1) + lean * len * 0.1, bow2 = -bow * (0.3 + r() * 0.4);+ const spine: P[] = [root, [root[0] + dx * 0.32 + nx * bow, root[1] + dy * 0.32 + ny * bow], [root[0] + dx * 0.7 + nx * bow2, root[1] + dy * 0.7 + ny * bow2], neck];+ g.fill(tube(spine, w * 1.2, w * 0.7, false), STEM_SHADE, 0.62);+ g.fill(tube(spine.map((p) => [p[0] - w * 0.34, p[1]] as P), w * 0.8, w * 0.44, false), STEM_G, 0.82); /* a stem is a cylinder: a shadow side, a lit side and the paper between them */+ for (let i = 0; i < 5; i++) { const t = 0.15 + i * 0.18, p: P = [root[0] + dx * t + nx * bow * Math.sin(t * Math.PI), root[1] + dy * t + ny * bow * Math.sin(t * Math.PI)]; g.fill(oval(p[0] + w * 0.5, p[1], w * 0.16, w * 0.5, 6), mix(STEM_G, PAPER, 0.5), 0.3); } /* faintly hairy: the light catches down one side */+ g.fill(tube([[neck[0] - w * 0.8, neck[1] + w * 1.6], [neck[0], neck[1] + w * 0.2]], w * 1.5, w * 1.1, false), SEPAL, 0.8); /* the green swell at the neck */+ return spine;+};+// A leaf: basal, deeply cut, parsley-like. Three lobes, each lobe notched twice, never a blob.+export const leaf = (g: Gfx, at: P, len: number, ang: number, seed: number, alpha = 0.9) => {+ const r = rng(seed), pts: P[] = [], lobes = 3;+ const put = (d: number, off: number) => { const a = ang + off; pts.push([at[0] + Math.cos(a) * d, at[1] + Math.sin(a) * d]); };+ put(len * 0.1, -0.1);+ for (let i = 0; i < lobes; i++) { const o = (i / (lobes - 1) - 0.5) * 1.5; put(len * (0.42 + r() * 0.12), o * 1.25); put(len * (0.86 + r() * 0.2), o * 0.95); put(len * (0.6 + r() * 0.12), o * 0.72); put(len * (0.92 + r() * 0.14), o * 0.5); put(len * (0.52 + r() * 0.1), o * 0.3); }+ put(len * 0.12, 0.1);+ g.wash(pts, LEAF, { alpha: alpha * 0.85, seed, dx: 1, dy: 1, shrink: 0.94, rim: true });+ g.wash(pts.map((p) => [at[0] + (p[0] - at[0]) * 0.72 - len * 0.05, at[1] + (p[1] - at[1]) * 0.72 - len * 0.04] as P), LEAF_LIT, { alpha: alpha * 0.4, seed: seed + 5, shrink: 0.9, rim: false });+ g.fill(tube([at, [at[0] + Math.cos(ang) * len * 0.5, at[1] + Math.sin(ang) * len * 0.5]], len * 0.03, len * 0.015, false), LEAF_LIT, 0.5);+};+// the dark ferny mass a clump sits in: leaves at the foot, smaller and cooler as they go back+export const basalLeaves = (g: Gfx, at: P, spread: number, seed: number, n = 7) => {+ const r = rng(seed), set: { p: P; L: number; a: number; s: number }[] = [];+ for (let i = 0; i < n; i++) { const t = (i / (n - 1) - 0.5) * 2; set.push({ p: [at[0] + t * spread * 0.55 + (r() - 0.5) * spread * 0.14, at[1] + (r() - 0.5) * spread * 0.1], L: spread * (0.2 + r() * 0.2), a: -Math.PI / 2 + t * 0.95 + (r() - 0.5) * 0.3, s: seed + i * 13 }); }+ set.sort((a, b) => a.p[1] - b.p[1]).forEach((s, i) => leaf(g, s.p, s.L, s.a, s.s, 0.55 + (i / n) * 0.4));+};++// ---------------------------------------------------------------- a whole plant at one position+export type Plant = { at: P; R: number; v: Variety; view: View; tilt: number; stemLen: number; seed: number; sideBud?: number };+export const plant = (g: Gfx, pl: Plant, k: number, dip = 0, lean = 0) => {+ const R = pl.R * k, w = Math.max(0.7, R * 0.05), neck: P = [pl.at[0], pl.at[1] + R * 0.86];+ const root: P = [neck[0] - pl.stemLen * k * lean * 0.5, neck[1] + pl.stemLen * k];+ if (R > 5) {+ stem(g, root, [neck[0] + dip * R * 0.2, neck[1] + dip * R * 0.1], w, pl.seed + 3, lean);+ if (R > 22) { const r = rng(pl.seed + 9), ly = 0.45 + r() * 0.2, at: P = [root[0] + (neck[0] - root[0]) * ly, root[1] + (neck[1] - root[1]) * ly]; leaf(g, at, R * 0.62, r() > 0.5 ? -0.5 : Math.PI + 0.5, pl.seed + 11, 0.85); }+ if (pl.sideBud !== undefined && R > 18) { const b: P = [neck[0] + Math.cos(pl.sideBud) * R * 1.35, neck[1] + R * 0.5 + Math.sin(pl.sideBud) * R * 0.7]; g.fill(tube([[neck[0], neck[1] + R * 0.5], b], w * 0.9, w * 0.5, false), STEM_G, 0.85); head(g, b, R * 0.3, pl.v, { view: "bud", seed: pl.seed + 17, tilt: pl.sideBud * 0.4 }); }+ }+ head(g, [pl.at[0] + dip * R * 0.12, pl.at[1] + dip * R * 0.1], R, pl.v, { view: pl.view, tilt: pl.tilt + dip * 0.1 + lean * 0.3, seed: pl.seed, dip });+};diff --git a/example/src/canvas-core/butterfly/alive/score.ts b/example/src/canvas-core/butterfly/alive/score.tsnew file mode 100644index 0000000..82bec78--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/score.ts@@ -0,0 +1,145 @@+// THE SCORE (spec section 8, rewritten on note: a real piece, not a sound design pass).+// Pure maths into two Float32Arrays. No Web Audio, no samples, no Node: as deterministic as the+// picture, and it runs under any backend.+//+// ONE THEME carries the whole film, and the whole film is in a MAJOR key. The note was: it was+// reading sad and eerie, which was the minor mode doing exactly what the minor mode does. Act 1 is+// curious and mechanical but SUNNY: a music box in C major, sparse and bright, which ends on the+// dominant so the question is still open without ever being mournful. The come-alive warms it with+// a harp and a low pad; the bloom opens it out; the meadow answers it home. Nothing anywhere is+// minor except two passing chords that make the major ones taste sweeter.+//+// frames 0-540 C major Act 1. Music box and a clockwork ostinato, ending open on G+// frames 540-1200 C major the come-alive and the bloom: harp, warm pad, a counter-line+// frame 1200 C MAJOR the meadow. Plagal turn, perfect cadence, DING on 1365+import { DING, LANDINGS, SIPS, TAKEOFFS } from "./cues";++const OFF = 540, FPS = 30, BEAT = 15, BAR = 60;+export const atFrame = (filmFrame: number, sr: number) => Math.round((filmFrame / FPS) * sr);++const HZ: Record<string, number> = {+ C2: 65.41, G2: 98.0, Ab2: 103.83, Bb2: 116.54, C3: 130.81, D3: 146.83, Eb3: 155.56, E3: 164.81, F3: 174.61, G3: 196.0, Ab3: 207.65, A3: 220.0, Bb3: 233.08,+ C4: 261.63, D4: 293.66, Eb4: 311.13, E4: 329.63, F4: 349.23, G4: 392.0, Ab4: 415.3, A4: 440.0, Bb4: 466.16, B4: 493.88,+ C5: 523.25, D5: 587.33, Eb5: 622.25, E5: 659.25, F5: 698.46, G5: 784.0, Ab5: 830.61, A5: 880.0, Bb5: 932.33, C6: 1046.5, Eb6: 1244.51, G6: 1568.0,+};+// root, and the triad over it. The harmony is a real progression, not a drone.+const CHORD: Record<string, [string, string[]]> = {+ C: ["C3", ["C4", "E4", "G4"]], F: ["F3", ["F4", "A4", "C5"]], G: ["G3", ["G4", "B4", "D5"]],+ Am: ["A3", ["A4", "C5", "E5"]], Dm: ["D3", ["D4", "F4", "A4"]], C2nd: ["C3", ["D4", "E4", "G4"]],+};+// film frame -> chord. The meadow lands on C MAJOR exactly on 1410, which is local 870.+const PROG: [number, string][] = [+ [0, "C"], [120, "F"], [180, "G"], [240, "C"], [300, "Am"], [360, "F"], [420, "G"],+ [540, "C"], [600, "F"], [660, "C2nd"], [720, "G"], [780, "C"], [840, "F"], [900, "Dm"],+ [960, "G"], [1020, "C"], [1080, "F"], [1140, "G"],+ [1200, "C"], [1260, "F"], [1320, "Am"], [1350, "G"], [1365, "C"],+];+const chordAt = (f: number) => { let c = PROG[0][1]; for (const [s, ch] of PROG) if (f >= s) c = ch; return c; };++// THE THEME: eight notes, in semitones above the tonic, with its rhythm in beats. The only+// difference between the minor statement and the major answer is the third.+const THEME_MAJ = [0, 4, 7, 5, 4, 0, 2, 4]; // the only mode this film is in+const RHYTHM = [1, 1, 2, 1, 1, 2, 1, 3];++export const aliveScore = (frames: number) => (sr: number): [Float32Array, Float32Array] => {+ const n = Math.ceil((frames / FPS) * sr), L = new Float32Array(n), R = new Float32Array(n);+ const put = (i0: number, len: number, fn: (t: number) => number, pan: number, gain: number) => {+ for (let i = 0; i < len; i++) { const j = i0 + i; if (j < 0 || j >= n) continue; const v = fn(i / sr) * gain; L[j] += v * (1 - pan); R[j] += v * pan; }+ };+ // ---- the instruments. Each one is a different way of making a note start and stop, which is+ // all an instrument is once you have the harmony right.+ const box = (fr: number, hz: number, g = 0.3, pan = 0.5, ring = 2.2) => put(atFrame(fr, sr), Math.floor(ring * sr), (t) => {+ const e = Math.exp(-t * 2.8) * Math.min(1, t * 900);+ return (Math.sin(6.283 * hz * t) + 0.4 * Math.sin(6.283 * hz * 2.76 * t) * Math.exp(-t * 6) + 0.18 * Math.sin(6.283 * hz * 5.4 * t) * Math.exp(-t * 11)) * e * 0.5;+ }, pan, g);+ const harp = (fr: number, hz: number, g = 0.22, pan = 0.5, ring = 2.6) => put(atFrame(fr, sr), Math.floor(ring * sr), (t) => {+ const e = Math.exp(-t * 1.9) * Math.min(1, t * 500);+ return (Math.sin(6.283 * hz * t) + 0.34 * Math.sin(6.283 * hz * 2 * t) * Math.exp(-t * 3) + 0.14 * Math.sin(6.283 * hz * 3 * t) * Math.exp(-t * 5)) * e * 0.5;+ }, pan, g);+ const pad = (fr: number, hz: number, lenFr: number, g = 0.1, pan = 0.5) => { const len = Math.floor((lenFr / FPS) * sr); put(atFrame(fr, sr), len, (t) => {+ const u = t / (len / sr), e = Math.min(1, u * 5) * Math.min(1, (1 - u) * 4), vib = 1 + 0.0016 * Math.sin(6.283 * 4.2 * t);+ let v = Math.sin(6.283 * hz * t * vib) * 1.5; for (let k = 2; k <= 4; k++) v += Math.sin(6.283 * hz * k * t * vib) / (k * k * 0.85);+ return v * e * 0.26;+ }, pan, g); };+ const bass = (fr: number, hz: number, lenFr: number, g = 0.16) => { const len = Math.floor((lenFr / FPS) * sr); put(atFrame(fr, sr), len, (t) => {+ const u = t / (len / sr), e = Math.min(1, u * 8) * Math.min(1, (1 - u) * 3);+ return (Math.sin(6.283 * hz * t) + 0.3 * Math.sin(6.283 * hz * 2 * t) + 0.12 * Math.sin(6.283 * hz * 3 * t)) * e * 0.42;+ }, 0.5, g); };+ const bell = (fr: number, hz: number, g = 0.3) => put(atFrame(fr, sr), Math.floor(4.5 * sr), (t) => {+ const e = Math.exp(-t * 1.0) * Math.min(1, t * 700);+ return (Math.sin(6.283 * hz * t) + 0.5 * Math.sin(6.283 * hz * 2.0 * t) * Math.exp(-t * 1.6) + 0.3 * Math.sin(6.283 * hz * 2.76 * t) * Math.exp(-t * 2.4) + 0.16 * Math.sin(6.283 * hz * 5.4 * t) * Math.exp(-t * 4)) * e * 0.5;+ }, 0.5, g);+ const tick = (fr: number, g: number) => put(atFrame(fr, sr), Math.floor(0.04 * sr), (t) => (Math.sin(6.283 * 2100 * t) * 0.55 + Math.sin(6.283 * 3300 * t) * 0.45) * Math.exp(-t * 170), 0.46, g);+ const flutter = (fr: number, g: number, sd: number) => { let s = (sd * 2654435761) >>> 0; put(atFrame(fr, sr), Math.floor(0.15 * sr), (t) => { s = (s * 1664525 + 1013904223) >>> 0; return ((s / 4294967296) * 2 - 1) * Math.exp(-t * 24) * (0.35 + 0.65 * Math.sin(6.283 * 95 * t)); }, 0.5, g); };+ const water = (fr: number, g: number) => put(atFrame(fr, sr), Math.floor(0.6 * sr), (t) => Math.sin(6.283 * (600 + 850 * t) * t) * Math.exp(-t * 6.5) * Math.min(1, t * 500), 0.52, g);+ const heart = (fr: number, g: number) => put(atFrame(fr, sr), Math.floor(0.36 * sr), (t) => (Math.sin(6.283 * 56 * t) + 0.4 * Math.sin(6.283 * 112 * t)) * Math.exp(-t * 8.5) * Math.min(1, t * 180), 0.5, g);++ const semis = (hz: number, s: number) => hz * Math.pow(2, s / 12);+ // one statement of the theme, on whatever instrument and in whichever mode+ const theme = (start: number, tonic: number, major: boolean, voice: (fr: number, hz: number, g: number, pan: number) => void, g: number, stretch = 1, pan = 0.5) => {+ const T = THEME_MAJ; let fr = start;+ T.forEach((s, i) => { voice(fr, semis(tonic, s), g * (i === 0 || i === 2 ? 1 : 0.82), pan + (i % 2 ? 0.06 : -0.06)); fr += RHYTHM[i] * BEAT * stretch; });+ return fr;+ };++ // ================================================================ ACT 1: curious, mechanical+ // A clockwork ostinato under a music box, and the theme stated twice in C minor. The act ends+ // on the DOMINANT and stays there: the question the whole rest of the film answers.+ for (let f = 0; f < 540; f += BEAT / 2) { const ch = CHORD[chordAt(f)][1], k = (f / (BEAT / 2)) % 3; box(f, HZ[ch[k]] * 2, 0.07, 0.3 + 0.4 * ((f / BEAT) % 2), 0.9); } /* the escapement, ticking through the harmony */+ for (let f = 0; f < 540; f += BAR) { const c = chordAt(f); bass(f, HZ[CHORD[c][0]], BAR, 0.14); pad(f, HZ[CHORD[c][1][1]], BAR, 0.045, 0.62); }+ theme(30, HZ.C5, true, (fr, hz, g, pan) => box(fr, hz, g, pan), 0.28);+ theme(240, HZ.C5, true, (fr, hz, g, pan) => box(fr, hz, g, pan), 0.26);+ box(420, HZ.G5, 0.24, 0.42, 3); box(450, HZ.D5, 0.2, 0.58, 3); box(480, HZ.B4, 0.24, 0.5, 4); box(480, HZ.G4, 0.2, 0.5, 4); /* it asks, and leaves it open */+ pad(420, HZ.G3, 120, 0.075, 0.5); pad(420, HZ.D4, 120, 0.05, 0.36); pad(420, HZ.B4, 120, 0.035, 0.66);++ // ================================================================ MOVEMENT 2+ water(OFF + 5, 0.3);+ for (let fr = 0; fr < 240; fr += 5) { const thin = fr < 180 ? 1 : 1 - (fr - 180) / 60; if (thin > 0) tick(OFF + fr, 0.16 * thin); } /* the tick thins to a wing-flutter and is gone by 240 */+ [180, 210, 230].forEach((a, k) => { for (let j = 0; j < 3; j++) flutter(OFF + a + j * (30 - k * 10), 0.085 + k * 0.02, a + j); });++ // the come-alive: the theme returns at HALF SPEED and warm, on a harp, over a real bass line+ for (let f = 540; f < 1200; f += BAR) { const c = chordAt(f); bass(f, HZ[CHORD[c][0]], BAR, 0.155); CHORD[c][1].forEach((nm, k) => pad(f, HZ[nm], BAR, 0.05 - k * 0.008, 0.28 + k * 0.22)); }+ theme(OFF + 15, HZ.C4, true, (fr, hz, g, pan) => harp(fr, hz, g, pan, 3.2), 0.2, 2, 0.44);+ theme(OFF + 255, HZ.C5, true, (fr, hz, g, pan) => harp(fr, hz, g, pan, 2.8), 0.18, 1.5, 0.56); /* it lifts an octave as the creature does */++ // the BLOOM: E flat major, the relative major. Same theme, opened out, with a counter-line+ // moving against it in thirds, which is the sound of a world arriving.+ theme(1020, HZ.F4, true, (fr, hz, g, pan) => harp(fr, hz, g, pan, 3.4), 0.2, 1.5, 0.4);+ theme(1020 + 8, HZ.A4, true, (fr, hz, g, pan) => harp(fr, hz, g * 0.6, pan, 3), 0.17, 1.5, 0.64);+ [1110, 1125, 1140, 1170].forEach((f, k) => harp(f, [HZ.G5, HZ.F5, HZ.E5, HZ.D5][k], 0.15, 0.3 + k * 0.12, 2.4));+ pad(1140, HZ.G3, 60, 0.09, 0.5); pad(1140, HZ.D4, 60, 0.06, 0.4); /* the dominant, gathering */++ // the MEADOW at 1410: C MAJOR. The answer to Act 1's question, the same eight notes with the+ // third raised, then a plagal turn and a perfect cadence to close.+ for (let f = 1200; f < 1410; f += BAR) { const c = chordAt(f); bass(f, HZ[CHORD[c][0]], BAR, 0.17); CHORD[c][1].forEach((nm, k) => pad(f, HZ[nm], BAR, 0.055 - k * 0.008, 0.26 + k * 0.24)); }+ theme(1200, HZ.C5, true, (fr, hz, g, pan) => box(fr, hz, g, pan, 3.4), 0.3, 1, 0.46);+ theme(1206, HZ.E4, true, (fr, hz, g, pan) => harp(fr, hz, g * 0.72, pan, 3), 0.2, 1, 0.66);+ theme(1200, HZ.C3, true, (fr, hz, g, pan) => pad(fr, hz, 45, g * 0.4, pan), 0.1, 1, 0.5);+ [1290, 1320, 1335, 1350].forEach((f, k) => harp(f, [HZ.A4, HZ.C5, HZ.F5, HZ.G5][k], 0.17, 0.36 + k * 0.1, 3));+ bell(OFF + DING, HZ.C6, 0.3); bell(OFF + DING, HZ.C5, 0.16); box(OFF + DING, HZ.G5, 0.12, 0.5, 3.4); /* the DING, on the last stroke of the signature */+ bass(OFF + DING, HZ.C2, 75, 0.17); pad(OFF + DING, HZ.C4, 75, 0.07, 0.5); pad(OFF + DING, HZ.E4, 75, 0.05, 0.36); pad(OFF + DING, HZ.G4, 75, 0.04, 0.64);+ [1380, 1390, 1400].forEach((f, k) => harp(f, [HZ.E5, HZ.G5, HZ.C6][k], 0.11 - k * 0.02, 0.4 + k * 0.1, 3));++ // ---- the events the picture makes, sitting inside the harmony rather than on top of it+ LANDINGS.forEach((l, i) => { const c = CHORD[chordAt(OFF + l.at)][1]; harp(OFF + l.at, HZ[c[i % 3]] * 2, 0.16, 0.3 + i * 0.12, 2.2); });+ TAKEOFFS.forEach((t, i) => { flutter(OFF + t, 0.1, t); if (i > 0) { const c = CHORD[chordAt(OFF + t)][1]; harp(OFF + t, HZ[c[1]], 0.1, 0.62, 1.8); } });+ SIPS.forEach(([a, b]) => { for (let fr = a; fr < b; fr += BEAT) heart(OFF + fr, 0.17); }); /* the tick has become a heartbeat */++ // ---- a little room. Three taps is not a reverb, but it is the difference between a score and+ // a row of beeps: nothing in this film happens in an anechoic chamber.+ const taps: [number, number][] = [[0.085, 0.3], [0.168, 0.19], [0.287, 0.11]];+ const dl = L.slice(), dr = R.slice();+ taps.forEach(([sec, g]) => { const d = Math.floor(sec * sr); for (let i = d; i < n; i++) { L[i] += dr[i - d] * g; R[i] += dl[i - d] * g; } });+ for (let i = 0; i < n; i++) { const w = i < 1200 ? i / 1200 : i > n - 18000 ? Math.max(0, (n - i) / 18000) : 1; L[i] = Math.tanh(L[i] * 2.15) * w; R[i] = Math.tanh(R[i] * 2.15) * w; }+ return [L, R];+};++// every onset must sit exactly on its frame, which is what makes a cue a cue+export const scoreProblems = (sr = 48000): string[] => {+ const p: string[] = [];+ [5, ...TAKEOFFS, ...LANDINGS.map((l) => l.at), DING, 660, 750].forEach((fr) => { const want = Math.round(((fr + OFF) / FPS) * sr); if (atFrame(fr + OFF, sr) !== want) p.push(`cue at local ${fr} lands on sample ${atFrame(fr + OFF, sr)}, not ${want}`); });+ if (atFrame(OFF + DING, 48000) !== 2184000) p.push(`the DING is at sample ${atFrame(OFF + DING, 48000)}, expected 2184000 (film frame ${OFF + DING})`);+ if (chordAt(1200) !== "C") p.push(`the meadow does not land on C major at 1200, it lands on ${chordAt(1200)}`);+ if (chordAt(480) !== "G") p.push(`Act 1 does not end on the dominant, it ends on ${chordAt(480)}`);+ return p;+};diff --git a/example/src/canvas-core/butterfly/alive/sign.ts b/example/src/canvas-core/butterfly/alive/sign.tsnew file mode 100644index 0000000..a40354f--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/sign.ts@@ -0,0 +1,72 @@+// THE SIGNATURE, REDRAWN FOR READABILITY (spec 7: "LEGIBLE FIRST: it is a URL, the dot must read+// as a dot"). The approved still's signature is a run of control points that reads as a scribble+// at any size, which the spec itself flags as not passing. This is a proper hand: every letter is+// authored from its own strokes, in em units with the x-height at 1, so it can be set at whatever+// size the frame needs and still be a word rather than a gesture.+//+// It stays a SIGNATURE and not a caption: one warm grey-brown rigger line, a forward slant, a+// baseline that rises the couple of degrees a hand rises, uneven letter widths, real descenders on+// g and p. It is just large enough to read, which at 1080 means about 410 px across.+//+// `finale/signature.ts` is left exactly as it was, so the approved finale still keeps re-rendering+// byte for byte. This is the one the film uses.+import { Gfx, P, jitter, rng, tube } from "../../core";++const SIG = "#574d43";+type Glyph = { w: number; s: P[][] };+const arc = (cx: number, cy: number, rx: number, ry: number, a0: number, a1: number, n = 11): P[] =>+ Array.from({ length: n }, (_, i) => { const a = a0 + ((a1 - a0) * i) / (n - 1); return [cx + Math.cos(a) * rx, cy + Math.sin(a) * ry] as P; });++// x-height 1, ascenders to about 1.75, descenders to about -0.55. Widths are deliberately uneven.+const G: Record<string, Glyph> = {+ a: { w: 0.94, s: [arc(0.46, 0.47, 0.4, 0.45, -0.35, 4.3), [[0.86, 0.9], [0.84, 0.14], [0.97, 0.03]]] },+ l: { w: 0.5, s: [[[0.2, 1.72], [0.23, 0.2], [0.38, 0.03]]] },+ e: { w: 0.88, s: [[[0.08, 0.5], [0.78, 0.54]], arc(0.44, 0.47, 0.38, 0.45, -0.12, 4.0)] },+ x: { w: 0.92, s: [[[0.07, 0.9], [0.82, 0.05]], [[0.09, 0.05], [0.84, 0.9]]] },+ g: { w: 0.98, s: [arc(0.46, 0.55, 0.4, 0.4, -0.35, 4.3), [[0.86, 0.94], [0.85, 0.1], [0.74, -0.42], [0.36, -0.54], [0.18, -0.34]]] },+ r: { w: 0.7, s: [[[0.17, 0.9], [0.2, 0.04]], [[0.2, 0.58], [0.42, 0.92], [0.68, 0.84]]] },+ n: { w: 0.9, s: [[[0.14, 0.9], [0.17, 0.04]], [[0.17, 0.56], [0.44, 0.93], [0.76, 0.72], [0.79, 0.04]]] },+ s: { w: 0.82, s: [[[0.76, 0.82], [0.42, 0.95], [0.16, 0.74], [0.48, 0.52], [0.76, 0.36], [0.58, 0.04], [0.16, 0.14]]] },+ h: { w: 0.9, s: [[[0.14, 1.74], [0.17, 0.04]], [[0.17, 0.56], [0.44, 0.93], [0.76, 0.72], [0.79, 0.04]]] },+ p: { w: 0.94, s: [[[0.15, 0.92], [0.11, -0.52]], [[0.14, 0.78], [0.48, 0.92], [0.78, 0.62], [0.64, 0.24], [0.17, 0.18]]] },+ u: { w: 0.94, s: [[[0.14, 0.9], [0.16, 0.28], [0.4, 0.03], [0.68, 0.2], [0.78, 0.64], [0.8, 0.08], [0.95, 0.04]]] },+ c: { w: 0.86, s: [arc(0.52, 0.47, 0.4, 0.45, 0.85, 5.45)] }, /* a c has to be OPEN on the right or it is an o */+ o: { w: 0.9, s: [arc(0.46, 0.47, 0.4, 0.45, 0, 6.35, 13)] },+ m: { w: 1.24, s: [[[0.1, 0.9], [0.13, 0.04]], [[0.13, 0.56], [0.35, 0.93], [0.58, 0.72], [0.6, 0.04]], [[0.6, 0.56], [0.84, 0.93], [1.08, 0.72], [1.11, 0.04]]] },+ ".": { w: 0.4, s: [] },+};+const WORD = "alexgreenshpun.com";++// `p` writes it on, stroke by stroke, in the order a hand would. `alpha` is the ink drying.+export const signature = (g: Gfx, p = 1, alpha = 0.8) => {+ if (p <= 0) return;+ const em = 27, right = 1042, base = 1032, slant = 0.1, rise = Math.tan((-2 * Math.PI) / 180);+ const total = [...WORD].reduce((a, ch) => a + (G[ch]?.w ?? 0.5) + 0.045, 0);+ const x0 = right - total * em;+ const strokes: { pts: P[]; dot?: boolean }[] = [];+ let pen = 0;+ for (const ch of WORD) {+ const gl = G[ch]; if (!gl) { pen += 0.5; continue; }+ const T = ([gx, gy]: P): P => { const X = x0 + (pen + gx + gy * slant) * em; return [X, base - gy * em + (X - x0) * rise]; };+ if (ch === ".") strokes.push({ pts: [T([0.16, 0.05])], dot: true });+ else gl.s.forEach((st) => strokes.push({ pts: st.map(T) }));+ pen += gl.w + 0.045;+ }+ const r = rng(5901), each = 1 / strokes.length;+ strokes.forEach((st, i) => {+ const q = Math.max(0, Math.min(1, (p - i * each) / each)); if (q <= 0) return;+ if (st.dot) { const [x, y] = st.pts[0], d = em * 0.1; g.fill([[x - d, y - d], [x + d * 1.1, y - d * 0.85], [x + d * 0.95, y + d * 1.1], [x - d * 1.05, y + d * 0.95]], SIG, alpha); return; } /* the dot reads as a dot, which is the whole point of a URL */+ const n = Math.max(2, Math.ceil(st.pts.length * q)), s = jitter(st.pts.slice(0, n), em * 0.016, 5910 + i);+ const w = em * (0.1 + r() * 0.03); /* a rigger: loaded at the start of a stroke, thinner as it runs */+ g.fill(tube(s, w, w * 0.62, false), SIG, alpha);+ if (q >= 1) { const e = s[s.length - 1], d = w * 0.85; g.fill([[e[0] - d, e[1] - d], [e[0] + d, e[1] - d * 0.8], [e[0] + d * 0.9, e[1] + d], [e[0] - d * 0.95, e[1] + d * 0.9]], SIG, alpha * 0.9); } /* pigment pools where the brush left the paper */+ });+};+// a clean damp brush lifts the corner before anyone signs over a dark passage+export const clearCorner = (g: Gfx, p = 1) => {+ if (p <= 0) return;+ const c = g.cur;+ c.globalCompositeOperation = "destination-out";+ g.wash([[560, 992], [1062, 986], [1066, 1058], [556, 1064]], "#000000", { alpha: 0.5 * p, seed: 5900, dx: 0, dy: 0, shrink: 1, rim: false });+ c.globalCompositeOperation = "source-over";+};diff --git a/example/src/canvas-core/butterfly/alive/transform.ts b/example/src/canvas-core/butterfly/alive/transform.tsnew file mode 100644index 0000000..fc468b4--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/transform.ts@@ -0,0 +1,48 @@+// BEAT 1, THE MACRO: the mechanical creature turns into a real watercolour butterfly. One shot,+// no cut, at S = 4.0 creeping to 3.4, so the frame holds one forewing root, panel 2 on its+// projection lines, and the edge of the thorax window with its wheels still stepping on the tick.+//+// The order of the picture is the order of the event. The BLUEPRINT is drawn first, in full, by+// Act 1's own composer at a close view, so what the water is lifting is genuinely the same+// drawing. Then the water takes the creature, panel by panel, and only the creature: the sheet+// around it stays a blueprint for ever, which is the line the whole film turns on.+import { Ctx, Env, Gfx, P, PENCIL } from "../../core";+import { CX, CY } from "../geom";+import { FULL, PlateState } from "../plate";+import { drawPlate } from "../plate";+import { IDLE } from "../parts";+import { M0, PANEL2_HOME, DROP } from "./cues";+import { Cam, projector, scaleOf } from "./view";+import { drop, frontRim, wetnessAt } from "./water";+import { paintCreature, wingsOf, REST_FLIGHT, mapper } from "./wingpaint";++// The lifted panel seats on 60 with the last mechanical overshoot in the film, and the flaw+// becomes the mark of the individual: that blue panel is the one on the approved finale still.+const liftAt = (f: number): number => {+ if (f <= 45) return 1;+ if (f >= PANEL2_HOME + 6) return 0;+ const u = Math.min(1, (f - 45) / 15), e = 1 - Math.pow(1 - u, 3);+ return Math.max(-0.06, 1 - e) + (f > PANEL2_HOME ? -0.06 * Math.sin(((f - PANEL2_HOME) / 6) * Math.PI) : 0);+};+// the train steps on the tick, one notch per five frames, all the way through the macro+const trainAt = (f: number) => { const n = Math.floor(f / 5) + (f >= 130 ? 1 : 0), th = n * 0.42; return { centre: th, third: th * 2.1, pinion: th * 4.4, escape: -th * 3.2, fork: Math.sin(n * 1.7) * 0.22 }; };++export const camAt = (f: number): Cam => {+ const S = scaleOf(f), u = Math.max(0, Math.min(1, (f - 60) / 60)); /* 60-120: a slow drift left across the thorax to the port wing roots */+ return { S, look: [M0[0] - 78 * u * u * (3 - 2 * u) * 0.5, M0[1] + 10 * u] as P };+};++export const drawTransform = (ctx: Ctx, env: Env, f: number) => {+ const cam = camAt(f), pr = projector(cam, 0);+ // ---- the blueprint, at this view, by Act 1's composer+ const st: PlateState = { wings: { flap: 1, sweep: 0 }, lift: liftAt(f), keyY: 0, keyTurn: 0, train: trainAt(f), shadow: f > 180 ? [((f - 180) / 60) * 14, ((f - 180) / 60) * 20] : [0, 0], boil: 1, inkedBoil: 1, boilIndex: Math.floor(f / 4), p: FULL, view: { cx: cam.look[0], cy: cam.look[1], zoom: cam.S } };+ drawPlate(ctx, env, st);++ // ---- the water, and what it leaves behind+ const g = new Gfx(ctx, env, f, PENCIL), wt = wetnessAt(f), at = pr.at([CX, CY]);+ g.group("plain", () => paintCreature(g, at, cam.S, REST_FLIGHT, { wetness: wt, groundLift: true, shadow: f > 180 ? (f - 180) / 60 : 0, shadowOff: [-0.35, 0.45], seed: 900 }), { alpha: 0.98 });+ const T = mapper(at, cam.S, REST_FLIGHT), W = wingsOf(REST_FLIGHT);+ g.group("plain", () => frontRim(g, T, cam.S * 90, W, f, wt), { alpha: 0.9 });+ if (f >= DROP && f < DROP + 55) { const liftedPanel = W[3].panels[2], c = liftedPanel.reduce((a, p) => [a[0] + p[0] / liftedPanel.length, a[1] + p[1] / liftedPanel.length] as P, [0, 0] as P); const lp = liftAt(f); g.group("plain", () => drop(g, T([c[0] + 58 * lp, c[1] - 60 * lp]), cam.S * 26, f), { alpha: 1 }); }+ g.paper("coldpress", 0.07); /* the tooth of the sheet, over the paint as well as over the ink */+};diff --git a/example/src/canvas-core/butterfly/alive/view.ts b/example/src/canvas-core/butterfly/alive/view.tsnew file mode 100644index 0000000..a680f8c--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/view.ts@@ -0,0 +1,35 @@+// THE CAMERA, spec section 4. A true dolly over depth planes: camera distance D, plane depth z,+// plane scale 1/(D + z). The hero plane is z = 0, so the hero scale S is 1/D, and S is SCREEN+// PIXELS PER SHEET UNIT: at S = 1 the creature (wingspan 780 units) is 780 px across.+//+// NOTE, one engine item, does not block the stills: the finale world's projector+// (butterfly/finale/world.ts) normalises every plane by (1 + z) so that all planes are 1:1 on the+// last frame. That convention inverts parallax for D > 1, and movement 2 spends almost all of its+// time there (D runs 0.25 to 8.7). This movement uses the spec's model instead. The two have to+// be reconciled once, at the wide end, by choosing world positions for the last bars; that is+// G-W work, not stills work.+import { P } from "../../core";+import { S_KEYS } from "./cues";++export type Cam = { S: number; look: P };+export const distance = (S: number) => 1 / S;+export const scaleAt = (c: Cam, z: number) => 1 / (distance(c.S) + z);+export const projector = (c: Cam, z: number) => { const k = scaleAt(c, z); return { k, at: (p: P): P => [540 + (p[0] - c.look[0]) * k, 540 + (p[1] - c.look[1]) * k] }; };+// A close shot must not fatten the line by the zoom: w = w_authored * S^0.35 (spec 4).+export const weight = (S: number) => Math.pow(S, 0.35);++// Monotone cubic (Fritsch-Carlson) so the dolly never overshoots into a scale it was not given,+// and never reverses: S is interpolated in log2, which is what "one stop of zoom" means.+const mono = (xs: number[], ys: number[], x: number): number => {+ const n = xs.length;+ if (x <= xs[0]) return ys[0];+ if (x >= xs[n - 1]) return ys[n - 1];+ const d: number[] = []; for (let i = 0; i < n - 1; i++) d.push((ys[i + 1] - ys[i]) / (xs[i + 1] - xs[i]));+ const m: number[] = [d[0]]; for (let i = 1; i < n - 1; i++) m.push(d[i - 1] * d[i] <= 0 ? 0 : (d[i - 1] + d[i]) / 2); m.push(d[n - 2]);+ for (let i = 0; i < n - 1; i++) { if (d[i] === 0) { m[i] = 0; m[i + 1] = 0; continue; } const a = m[i] / d[i], b = m[i + 1] / d[i], s = a * a + b * b; if (s > 9) { const t = 3 / Math.sqrt(s); m[i] = t * a * d[i]; m[i + 1] = t * b * d[i]; } }+ let i = 0; while (x > xs[i + 1]) i++;+ const h = xs[i + 1] - xs[i], t = (x - xs[i]) / h, t2 = t * t, t3 = t2 * t;+ return ys[i] * (2 * t3 - 3 * t2 + 1) + h * m[i] * (t3 - 2 * t2 + t) + ys[i + 1] * (-2 * t3 + 3 * t2) + h * m[i + 1] * (t3 - t2);+};+const SX = S_KEYS.map((k) => k[0]), SY = S_KEYS.map((k) => Math.log2(k[1]));+export const scaleOf = (local: number): number => Math.pow(2, mono(SX, SY, local));diff --git a/example/src/canvas-core/butterfly/alive/water.ts b/example/src/canvas-core/butterfly/alive/water.tsnew file mode 100644index 0000000..625e22f--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/water.ts@@ -0,0 +1,54 @@+// THE WATER FRONT. A cyanotype is developed in water and its blue lifts when the sheet is wet,+// which is the only honest device that turns this drawing into a painting, and it is why a single+// drop is the whole bridge between the two movements of the film (spec section 0).+//+// The water does not spread as a circle. It lands on the lifted panel, runs down its projection+// lines onto the wing, and from there it follows the DRAWING by capillary, one spar per five+// frames, in an order the draftsman would never have chosen. Behind the front the Prussian ground+// is gone and there is paint; in front of it there is still a blueprint; and the front itself is+// a dark rim of the pigment it pushed along in front of it.+import { Gfx, P, jitter, oval, rng, tube } from "../../core";+import { Wing, cen, lerp } from "../geom";+import { BODY_WET, DROP, PANEL2_FLOOD, SPAR_WET } from "./cues";+import { Wetness, frontLine } from "./wingpaint";++const FRONT = "#1e4f7e", DROP_DARK = "#0f3558", HIGHLIGHT = "#fdfdfb";+const ramp = (f: number, at: number, len: number) => Math.max(0, Math.min(1, (f - at) / len));++// when a panel starts to flood: both its spars have to be running before it fills+export const panelAt = (i: number, j: number): number => (i === 3 && j === 2 ? PANEL2_FLOOD : Math.max(SPAR_WET[i][j], SPAR_WET[i][j + 1] ?? SPAR_WET[i][j]) + 5);+export const panelFrom = (i: number, j: number): number => ((SPAR_WET[i][j] ?? 0) <= (SPAR_WET[i][j + 1] ?? 1e9) ? j : j + 1); // the spar the water arrived on++export const wetnessAt = (f: number): Wetness => ({+ panel: (i, j) => ramp(f, panelAt(i, j), i === 3 && j === 2 ? 15 : 10),+ spar: (i, j) => ramp(f, SPAR_WET[i][j] ?? 1e9, 8),+ body: (part) => ramp(f, BODY_WET[part], 20),+ from: (i, j) => panelFrom(i, j) === j,+});++// The front itself, drawn after the paint: wherever a panel is half taken, a wet edge is crossing+// it, and a wet edge in watercolour is a dark line because the pigment piles up at the water's rim.+export const frontRim = (g: Gfx, T: (p: P) => P, sc: number, W: Wing[], f: number, wt: Wetness) => {+ W.forEach((wg, i) => wg.panels.forEach((pn, j) => {+ const u = wt.panel(i, j); if (u <= 0.02 || u >= 0.98) return;+ const p = pn.map((q) => lerp(q, cen(pn), 0.09)), line = frontLine(p, panelFrom(i, j) === j, u).map(T);+ /* a wet edge in watercolour is DARK, because the water carries the pigment to its own rim and+ leaves it there when it stops. That dark line is the only thing that says this is liquid. */+ g.fill(jitter(tube(line, sc * 0.03, sc * 0.02, false), sc * 0.012, 4100 + i * 9 + j), FRONT, 0.62);+ g.fill(jitter(tube(line.map((q) => [q[0] - sc * 0.035, q[1] + sc * 0.02] as P), sc * 0.05, sc * 0.03, false), sc * 0.02, 4150 + i * 9 + j), "#8fb1cb", 0.28); /* the damp sheen just behind it */+ }));+};++// The drop. A clear bead on a blue sheet: darker blue under it because it magnifies the ground,+// one paper-white highlight up and left of centre, and a crown of four droplets thrown off the+// impact that are gone again within a beat.+export const drop = (g: Gfx, at: P, r: number, f: number) => {+ const t = f - DROP; if (t < 0 || t > 55) return;+ const spread = Math.min(1, t / 30), R = r * (0.55 + spread * 0.75), fade = 1 - Math.max(0, (t - 34) / 21);+ g.wash(jitter(oval(at[0], at[1], R * 1.05, R * 0.92, 14), R * 0.08, 4300), DROP_DARK, { alpha: 0.42 * fade, seed: 4300, shrink: 0.97, rim: true, dx: 1, dy: 2 });+ if (t < 26) { /* while it is still a bead it has a lens in it */+ g.fill(oval(at[0] - R * 0.28, at[1] - R * 0.3, R * 0.2, R * 0.14, 9), HIGHLIGHT, 0.8 * (1 - t / 26));+ g.wash(oval(at[0] + R * 0.2, at[1] + R * 0.24, R * 0.5, R * 0.34, 10), "#5f8fb4", { alpha: 0.3, seed: 4310, shrink: 0.9, rim: false });+ }+ if (t <= 10) { const rr = rng(4320); for (let i = 0; i < 4; i++) { const a = rr() * Math.PI * 2, d = R * (0.9 + t * 0.14 + rr() * 0.4), s = R * 0.12 * (1 - t / 10); g.fill(oval(at[0] + Math.cos(a) * d, at[1] + Math.sin(a) * d * 0.7 - t * R * 0.04, s, s * 0.85, 7), "#bfd8e8", 0.75 * (1 - t / 10)); } } /* the crown */+};diff --git a/example/src/canvas-core/butterfly/alive/wingpaint.ts b/example/src/canvas-core/butterfly/alive/wingpaint.tsnew file mode 100644index 0000000..74bf419--- /dev/null+++ b/example/src/canvas-core/butterfly/alive/wingpaint.ts@@ -0,0 +1,269 @@+// THE CREATURE AS A NATURALIST PLATE (spec 5.7: more realistic, less abstract).+// The stained-glass direction is withdrawn and this file is rebuilt to it. A lepidopterist should+// be able to name every part: a closed discal cell, veins forking to a scalloped margin, the+// submarginal spot row, the apical patch, the discal spot, a furred thorax, seven abdominal+// segments, compound eyes with palps between them, clubbed antennae, a proboscis that is a tube+// and not a spring, and six jointed legs. The species stays ORIGINAL: the medium and the anatomy+// are borrowed, the pattern is not. The reference actually opened is named atop `anatomy.ts`.+//+// It still carries a WETNESS per part, because this is also the creature the water is making in+// beat 1. At 0 the blueprint shows through untouched; between 0 and 1 the paint reaches only as+// far as the water has, clipped to the front, never faded in over the whole shape.+import { Gfx, P, displace, jitter, oval, rng, sample, tube } from "../../core";+import { CX, CY, FW, FW_H, FW_T, HEAD, HW, HW_H, HW_T, Pose, THORAX, Wing, cen, lerp, wingGeom } from "../geom";+import { GRASS_SHADE, PAPER_W } from "../finale/world";++// RICHER PIGMENT (not washed out, real pigment depth). The finale's ROSE and+// PEACH are a value or two too weak to carry a naturalist plate, so the creature gets its own,+// deeper set here rather than an edit to `finale/world.ts`: that file feeds the approved finale+// still, which keeps re-rendering byte-identical, and this way the film gets the stronger paint+// without moving anything anyone has already signed off.+const ROSE = "#d96e80", ROSE_D = "#b04a5e", PEACH = "#ef9a5c", PEACH_L = "#f8c48c", CORNFLOWER = "#3f6fc4";+import { lift } from "../finale/paint";+import { venation } from "./anatomy";++export type Flight = { pose: Pose; heading: number; pitch: number; bank: number };+export const REST_FLIGHT: Flight = { pose: { flap: 1, sweep: 0 }, heading: 0, pitch: 1, bank: 0 };+// Wing order everywhere in movement 2: 0 port hind, 1 starboard hind, 2 port fore, 3 starboard fore.+export const wingsOf = (f: Flight): Wing[] => {+ const port = { ...f.pose, flap: Math.min(1, f.pose.flap + f.bank) }, star = { ...f.pose, flap: Math.max(0.2, f.pose.flap - f.bank) };+ return [wingGeom(-1, HW, HW_H, HW_T, 2000, port), wingGeom(1, HW, HW_H, HW_T, 2600, star), wingGeom(-1, FW, FW_H, FW_T, 1000, port), wingGeom(1, FW, FW_H, FW_T, 1600, star)];+};+export const mapper = (at: P, scale: number, f: Flight) => {+ const c = Math.cos(f.heading), s = Math.sin(f.heading);+ return (p: P): P => { const dx = (p[0] - CX) * scale, dy = (p[1] - CY) * scale * f.pitch; return [at[0] + dx * c - dy * s, at[1] + dx * s + dy * c]; };+};++export type Wetness = { panel: (wing: number, panel: number) => number; spar: (wing: number, spar: number) => number; body: (part: "shell" | "head" | "window" | "abdomen") => number; from: (wing: number, panel: number) => boolean };+export const ALL_WET: Wetness = { panel: () => 1, spar: () => 1, body: () => 1, from: () => true };++// The wet part of a panel. A half-taken panel is not a whole panel at half strength: it is paint+// up to the water's edge and blueprint past it.+export const wetPart = (p: P[], fromLow: boolean, t: number): P[] => {+ if (t >= 0.995) return p;+ const A = fromLow ? [p[0], p[1], p[2]] : [p[6], p[5], p[4]], B = fromLow ? [p[6], p[5], p[4]] : [p[0], p[1], p[2]];+ const f = A.map((q, i) => lerp(q, B[i], t));+ return [...A, ...(t > 0.55 ? [p[3]] : []), ...f.slice().reverse()];+};+export const frontLine = (p: P[], fromLow: boolean, t: number): P[] => {+ const A = fromLow ? [p[0], p[1], p[2]] : [p[6], p[5], p[4]], B = fromLow ? [p[6], p[5], p[4]] : [p[0], p[1], p[2]];+ return A.map((q, i) => lerp(q, B[i], t));+};++// ---------------------------------------------------------------- the paint box+export const UMBER = "#6d4a33", BAND = "#57402f", DUST = "#a08a70", SPOT = "#fcf5e7", FUR = "#c8a98c", FUR_D = "#7d6249";+export const EYE = "#3a3026", EYE_HI = "#fdfbf4", IRIS_B = "#4d72ae", IRIS_O = "#df8a3d", LEG = "#5e4b3a";+export const mixc = (a: string, b: string, t: number) => { const h = (x: string) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)]; const A = h(a), B = h(b); return "#" + A.map((v, i) => Math.round(v + (B[i] - v) * Math.max(0, Math.min(1, t))).toString(16).padStart(2, "0")).join(""); };++// A wash that wobbles in proportion to the thing it is painting. The core's `wash` displaces every+// outline by an ABSOLUTE thirteen units: right for a wing, porridge for a palp and a flat+// airbrushed ribbon for a macro cell. Everything here therefore carries its own scale.+export const ps = (g: Gfx, pts: P[], col: string, alpha: number, seed: number, s: number, rim = true): P[] => {+ const q = displace(sample(jitter(pts, s * 0.012, seed), true, 5), s * 0.035, 1.9 / Math.max(6, s), 2, (seed % 83) + 5);+ g.fill(q, col, alpha);+ if (rim) { const c = g.cur; c.globalAlpha = alpha * 0.5; c.strokeStyle = col; c.lineWidth = Math.max(1.1, s * 0.016); c.lineJoin = "round"; g.path(c, q); c.stroke(); c.globalAlpha = 1; }+ return q;+};+// WET ON DAMP. A marking dropped into a wash that has not dried has no edge of its own: it creeps+// a little and stops soft. Three passes, each smaller and stronger, is what that looks like.+export const damp = (g: Gfx, pts: P[], col: string, alpha: number, seed: number, s: number) => {+ const c = cen(pts);+ for (let k = 0; k < 3; k++) ps(g, pts.map((q) => lerp(q, c, k * 0.11)), col, alpha * (0.42 + k * 0.26), seed + k * 7, s * (1 - k * 0.12), false);+};+export const dilate = (pts: P[], d: number): P[] => { const c = cen(pts); return pts.map(([x, y]) => { const dx = x - c[0], dy = y - c[1], l = Math.hypot(dx, dy) || 1; return [x + (dx / l) * d, y + (dy / l) * d] as P; }); };+// a vein: heavier at the base, thinning to nothing, and BROKEN, because a rigger runs out of paint+export const rigger = (g: Gfx, pts: P[], w0: number, col: string, alpha: number, seed: number) => {+ const s = sample(pts, false, 11), r = rng(seed);+ for (let i = 0; i < s.length - 1; i++) {+ const t = i / (s.length - 1); if (r() < 0.035 + t * 0.13) continue; /* a rigger runs dry here and there; it does not draw a dash-dot rule */+ const w = w0 * (1 - t * 0.94) ** 1.7;+ g.fill(tube([s[i], s[i + 1]], Math.max(0.28, w), Math.max(0.24, w * 0.92), false), col, alpha * (0.55 + 0.45 * (1 - t)));+ }+};++export type PaintOpts = {+ wetness?: Wetness;+ groundLift?: boolean;+ shadow?: number; shadowOff?: P;+ proboscis?: number; probTo?: P;+ legs?: number; // 0 tucked in flight, 1 unfolded and gripping+ seed?: number;+ behind?: string; // what the wings are over, for the fifth of it that warms through them+};++export const paintCreature = (g: Gfx, at: P, scale: number, f: Flight, o: PaintOpts = {}) => {+ const T = mapper(at, scale, f), seed = o.seed ?? 900, W = wingsOf(f), sc = scale * 90;+ const wt = o.wetness ?? ALL_WET, gl = o.groundLift === true, lod = scale * 780; // wingspan on screen++ if ((o.shadow ?? 0) > 0) { const d = o.shadowOff ?? [-0.5, 0.55]; g.fill(oval(at[0] + sc * d[0], at[1] + sc * d[1], sc * 1.5, sc * 0.35, 10), GRASS_SHADE, 0.16 * (o.shadow ?? 0)); }+ if ((o.legs ?? 0) > 0 && lod > 120) legs(g, T, sc, o.legs ?? 1, seed, false);+ // hindwings first: the forewing OVERLAPS the hindwing's leading third, and the double layer is darker+ [0, 1, 2, 3].forEach((i) => paintWing(g, T, W[i], i, sc, lod, wt, gl, seed, o.behind));+ body(g, T, sc, lod, wt, seed);+ if ((o.legs ?? 0) > 0 && lod > 120) legs(g, T, sc, o.legs ?? 1, seed, true);+ headParts(g, T, sc, lod, wt, o.proboscis ?? 0, o.probTo, seed);+};++// ---------------------------------------------------------------- one wing+const paintWing = (g: Gfx, T: (p: P) => P, wg: Wing, i: number, sc: number, lod: number, wt: Wetness, gl: boolean, seed: number, behind?: string) => {+ const fore = i >= 2, star = i % 2 === 1, A = venation(wg, fore, seed + i * 77), r = rng(seed + i * 11);+ const c0 = cen(wg.out);+ // how wet a point of the wing is: which panel it falls in, and how far the front has crossed it+ const cents = wg.panels.map(cen);+ const wetAt = (q: P): number => {+ let bi = 0, bd = 1e18; cents.forEach((c, j) => { const d = (c[0] - q[0]) ** 2 + (c[1] - q[1]) ** 2; if (d < bd) { bd = d; bi = j; } });+ const u = wt.panel(i, bi); if (u <= 0 || u >= 1) return u;+ const p = wg.panels[bi], low = wt.from(i, bi);+ const Am = low ? lerp(p[0], p[2], 0.5) : lerp(p[6], p[4], 0.5), Bm = low ? lerp(p[6], p[4], 0.5) : lerp(p[0], p[2], 0.5);+ const vx = Bm[0] - Am[0], vy = Bm[1] - Am[1], L = vx * vx + vy * vy || 1;+ return ((q[0] - Am[0]) * vx + (q[1] - Am[1]) * vy) / L <= u ? 1 : 0;+ };+ if (!wg.panels.some((_, j) => wt.panel(i, j) > 0)) return;++ // ---- the paper. Either the ground LIFTED panel by panel as the water arrives, or one reserve.+ if (gl) wg.panels.forEach((pn, j) => { const u = wt.panel(i, j); if (u <= 0) return; const part = wetPart(pn, wt.from(i, j), u); ps(g, dilate(part, 15).map(T), PAPER_W, 0.93, seed + 800 + i * 9 + j, sc * 0.8, false); ps(g, jitter(dilate(part, 12).map(T), sc * 0.04, seed + 810 + i * 9 + j), "#6f8ea8", 0.1, seed + 820 + i * 9 + j, sc * 0.5, false); });+ else g.fill(dilate(A.out, 1.5).map(T), PAPER_W, 0.62);++ // ---- 1. the pale first wash, laid PANEL BY PANEL so the water's edge stays the edge of the+ // paint. Filtering an outline point by point instead tears the polygon into a rag: a shape has+ // to keep all of its vertices, so what gets clipped is the region, never the point list.+ let anyPaint = false;+ wg.panels.forEach((pn, j) => {+ const u = wt.panel(i, j); if (u <= 0) return;+ anyPaint = true;+ const q = dilate(wetPart(pn, wt.from(i, j), u), 4), p = q.map(T), pc = cen(p), root = T(wg.h);+ const far = Math.min(1, Math.hypot(pc[0] - root[0], pc[1] - root[1]) / (sc * 3.2));+ ps(g, p, ROSE, 0.62 + (1 - far) * 0.28, seed + i * 20 + j, sc);+ ps(g, p.map((z) => lerp(z, T(wg.h), 0.24)), ROSE_D, 0.3 * (1 - far), seed + 40 + i * 20 + j, sc * 0.9, false); /* the pigment pools deepest at the wing root */+ ps(g, p.map((z) => lerp(z, pc, 0.16)), PEACH, 0.4 + far * 0.38, seed + 60 + i * 20 + j, sc * 0.8, false);+ ps(g, p.map((z) => lerp(z, pc, 0.42)), PEACH_L, 0.24 + far * 0.2, seed + 70 + i * 20 + j, sc * 0.6, false);+ if (behind) ps(g, p.map((z) => lerp(z, pc, 0.3)), behind, 0.17, seed + 90 + i * 20 + j, sc * 0.7, false); /* a wing is TRANSLUCENT: a fifth of what is behind it warms through */+ for (let k = 0; k < 2; k++) { const rr = rng(seed + 700 + i * 30 + j * 5 + k), k2 = 0.3 + rr() * 0.4, off: P = [(rr() - 0.5) * sc * 0.45, (rr() - 0.5) * sc * 0.35]; ps(g, p.map((z) => [pc[0] + (z[0] - pc[0]) * k2 + off[0], pc[1] + (z[1] - pc[1]) * k2 + off[1]] as P), rr() > 0.5 ? mixc(ROSE_D, "#8f3a50", 0.4) : mixc(PEACH, "#e8843f", 0.45), 0.2 + rr() * 0.22, seed + 710 + i * 30 + j * 5 + k, sc * 0.6, false); }+ /* the marginal band lives on the OUTER edge of each panel, so it narrows toward the rear+ corner on its own, because the panels do */+ if (lod > 46 && wetAt(pn[3]) > 0.5) { const outerEdge = [pn[2], pn[3], pn[4]].map(T), innerEdge = outerEdge.map((z) => lerp(z, pc, 0.3)); damp(g, [...outerEdge, ...innerEdge.slice().reverse()], BAND, 0.5, seed + 160 + i * 9 + j, sc * 0.7); }+ });+ if (!anyPaint) return;++ // ---- 2. the pattern, dropped in WET ON DAMP so nothing but the eyespot's pupil has a hard edge+ const dustPts = wg.panels.filter((_, j) => wt.panel(i, j) > 0.5).map((pn) => lerp(cen(pn), wg.h, 0.62));+ if (dustPts.length > 2) damp(g, [...dustPts, wg.h].map(T), DUST, 0.46, seed + 120 + i, sc * 0.8); /* the warm grey-umber dusting at the base, where the wing is hairy */+ const disc = lerp(A.cell[4], A.cell[5], 0.5);+ if (lod > 120 && wetAt(disc) > 0.5) { const d = T(disc); damp(g, oval(d[0], d[1], sc * 0.085, sc * 0.065, 9), UMBER, 0.66, seed + 130 + i, sc * 0.22); } /* the discal spot, at the end of the cell */+ if (fore && lod > 120) {+ const apex = A.ends[Math.min(1, A.ends.length - 1)], apx = lerp(apex, c0, 0.22), second = A.ends[Math.min(2, A.ends.length - 1)];+ if (wetAt(apx) > 0.5) { /* the dark umber apical patch, holding three pale spots */+ damp(g, [apex, lerp(apex, A.ends[0], 0.55), lerp(apx, c0, 0.34), lerp(apex, second, 0.6)].map(T), UMBER, 0.56, seed + 140 + i, sc * 0.6);+ for (let k = 0; k < 3; k++) { const q = T(lerp(apx, lerp(A.ends[0], second, 0.15 + k * 0.3), 0.42)); ps(g, oval(q[0], q[1], sc * 0.034, sc * 0.028, 8), SPOT, 0.7, seed + 150 + i * 5 + k, sc * 0.1, false); }+ }+ }+ // the row of pale submarginal spots that the blueprint's rivets became+ if (lod > 120) A.ends.forEach((e, k) => { const p = lerp(e, c0, 0.19); if (wetAt(p) < 0.5) return; const q = T(p); ps(g, oval(q[0], q[1], sc * 0.03, sc * 0.025, 8), SPOT, 0.66, seed + 170 + i * 7 + k, sc * 0.1, false); });+ // the one mark no real butterfly has: an iridescent cornflower scale patch in the starboard forewing+ if (i === 3) { const u = wt.panel(3, 2); if (u > 0) { const q = dilate(wetPart(wg.panels[2], wt.from(3, 2), u), 4).map(T), qc = cen(q); ps(g, q, CORNFLOWER, 0.92, seed + 300, sc); ps(g, q.map((z) => lerp(z, qc, 0.34)), mixc(CORNFLOWER, "#8fb6e8", 0.5), 0.4, seed + 302, sc * 0.6, false); lift(g, q.map((z) => lerp(z, qc, 0.52)), seed + 304, 0.3); } }+ // the hindwing's eyespot at the base of the tail: the only hard edge on the whole creature+ if (!fore && lod > 120) {+ const tail = A.ends[Math.max(0, A.ends.length - 2)], e = lerp(tail, c0, 0.26);+ if (wetAt(e) > 0.5) { const q = T(e); damp(g, oval(q[0], q[1], sc * 0.105, sc * 0.09, 10), IRIS_O, 0.76, seed + 180 + i, sc * 0.24); ps(g, oval(q[0], q[1], sc * 0.066, sc * 0.056, 9), IRIS_B, 0.86, seed + 182 + i, sc * 0.16, false); g.fill(oval(q[0], q[1], sc * 0.028, sc * 0.024, 8), EYE, 0.86); g.fill(oval(q[0] + sc * 0.011, q[1] - sc * 0.011, sc * 0.009, sc * 0.007, 6), EYE_HI, 0.8); }+ }+ // ---- 3. VOLUME. The wing has a camber, so a soft shadow lies behind every main vein.+ if (lod > 120) A.veins.filter((v) => v.main).forEach((v) => { const sh = v.pts.map((q) => [q[0] + 2.6, q[1] + 2.8] as P).map(T); g.fill(tube(sh, sc * 0.021 * v.w, sc * 0.006, false), mixc(UMBER, ROSE, 0.55), 0.18); });+ // ---- 4. the VEINS, last, with a fine rigger: broken, tapering, heavier at the base+ A.veins.forEach((v, k) => {+ const n = 7; let cut = 0;+ for (let q = n - 1; q >= 0; q--) { const p = v.pts[Math.min(v.pts.length - 1, Math.round((q / (n - 1)) * (v.pts.length - 1)))]; if (wetAt(p) > 0.5) { cut = (q + 1) / n; break; } }+ if (cut <= 0) return;+ rigger(g, v.pts.slice(0, Math.max(2, Math.ceil(v.pts.length * cut))).map(T), sc * 0.021 * v.w, mixc(UMBER, ROSE_D, 0.3), (v.main ? 0.72 : 0.48) * (lod > 120 ? 1 : 0.7), seed + 400 + i * 20 + k);+ });+ // ---- 5. the fringe: tiny alternating ticks, pale then dark, outside the margin+ if (lod > 120) A.out.forEach((q, k) => {+ if (wetAt(q) < 0.5) return;+ const nx = q[0] - c0[0], ny = q[1] - c0[1], L = Math.hypot(nx, ny) || 1;+ g.fill(tube([T(q), T([q[0] + (nx / L) * A.span * 0.022, q[1] + (ny / L) * A.span * 0.022])], sc * 0.008, sc * 0.003, false), k % 2 ? SPOT : BAND, 0.6);+ });+ // ---- 6. the rim light on the sunward margin: paper LIFTED, never white paint+ if (star) { const rim = A.out.slice(0, Math.ceil(A.out.length * 0.36)).filter((q) => wetAt(q) > 0.5); if (rim.length > 2) lift(g, tube(rim.map(T), sc * 0.05, sc * 0.03, false), seed + 260 + i, 0.6); }+};++// ---------------------------------------------------------------- the body, painted as a FORM+const body = (g: Gfx, T: (p: P) => P, sc: number, lod: number, wt: Wetness, seed: number) => {+ const r = rng(seed + 5), ua = wt.body("abdomen");+ if (ua > 0) for (let i = 0; i < 7; i++) { /* seven visible segments, tapering, a paler band at each joint */+ const t0 = i / 7, t1 = (i + 1) / 7, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5;+ const u = Math.min(1, ua * (1.4 - i * 0.06)); if (u <= 0) continue;+ const q: P[] = [T([CX - hw(t0) * 0.9, CY + (70 + 170 * t0) * 0.9]), T([CX + hw(t0) * 0.9, CY + (70 + 170 * t0) * 0.9]), T([CX + hw(t1) * 0.9, CY + (70 + 170 * t1) * 0.9]), T([CX - hw(t1) * 0.9, CY + (70 + 170 * t1) * 0.9])];+ ps(g, q, mixc(UMBER, DUST, 0.16 + i * 0.05), (0.8 - i * 0.02) * u, seed + 400 + i, sc * 0.4);+ ps(g, [q[0], q[1], lerp(q[1], q[2], 0.3), lerp(q[0], q[3], 0.3)], mixc(DUST, SPOT, 0.42), 0.4 * u, seed + 410 + i, sc * 0.3, false); /* the paler band at the joint, wrapping round the cylinder */+ ps(g, [lerp(q[0], q[3], 0.1), lerp(q[1], q[2], 0.1), lerp(q[1], q[2], 0.9), lerp(q[0], q[3], 0.9)].map((z) => lerp(z, cen(q), 0.45)), "#43352a", 0.16 * u, seed + 412 + i, sc * 0.3, false); /* the core shadow, so a segment is a cylinder and not a tile */+ }+ const us = wt.body("shell");+ if (us > 0) {+ const th = THORAX.map(T), c = cen(th);+ ps(g, th, mixc(UMBER, "#4a3a2c", 0.3), 0.84 * us, seed + 420, sc * 0.7);+ ps(g, th.map((q) => lerp(q, [c[0] + sc * 0.16, c[1] - sc * 0.14] as P, 0.42)), mixc(DUST, SPOT, 0.3), 0.44 * us, seed + 422, sc * 0.5, false); /* lit upper right */+ ps(g, th.map((q) => lerp(q, [c[0] - sc * 0.2, c[1] + sc * 0.2] as P, 0.5)), "#3b2f24", 0.3 * us, seed + 424, sc * 0.5, false); /* core shadow */+ ps(g, th.map((q) => lerp(q, [c[0] - sc * 0.26, c[1] + sc * 0.28] as P, 0.64)), mixc(DUST, "#8c7a63", 0.5), 0.24 * us, seed + 426, sc * 0.4, false); /* reflected light coming back up off the petal */+ if (lod > 120) for (let i = 0; i < 30; i++) { /* the fur, dry-brushed ALONG the thorax in the direction it grows, and over the old window */+ const t = r(), a = -1.62 + (r() - 0.5) * 1.5, p = T([CX + (r() - 0.5) * 88, CY - 88 + t * 156]), L = sc * (0.1 + r() * 0.13);+ g.fill(tube([p, [p[0] + Math.cos(a) * L, p[1] + Math.sin(a) * L]], sc * 0.012, sc * 0.003, false), r() > 0.45 ? FUR : FUR_D, 0.38 + r() * 0.3);+ }+ }+};++// ---------------------------------------------------------------- head: eyes, palps, antennae+const headParts = (g: Gfx, T: (p: P) => P, sc: number, lod: number, wt: Wetness, prob: number, probTo: P | undefined, seed: number) => {+ if (wt.body("head") <= 0) return;+ ps(g, HEAD.map(T), mixc(UMBER, "#493928", 0.35), 0.86, seed + 424, sc * 0.35);+ if (lod > 120) {+ [-1, 1].forEach((sd) => { /* two large compound eyes, one soft highlight each */+ const e = T([CX + sd * 20, CY - 112]);+ ps(g, oval(e[0], e[1], sc * 0.085, sc * 0.095, 12), EYE, 0.9, seed + 430 + sd, sc * 0.2, false);+ ps(g, oval(e[0] - sc * 0.02, e[1] + sc * 0.02, sc * 0.058, sc * 0.064, 10), mixc(EYE, "#6a5a45", 0.4), 0.42, seed + 432 + sd, sc * 0.14, false);+ g.fill(oval(e[0] + sc * 0.03, e[1] - sc * 0.035, sc * 0.021, sc * 0.017, 8), EYE_HI, 0.85);+ });+ [-1, 1].forEach((sd) => { /* the furry palps, between and below the eyes, pointing forward */+ const b = T([CX + sd * 9, CY - 116]), t = T([CX + sd * 15, CY - 154]);+ g.fill(tube([b, lerp(b, t, 0.55), t], sc * 0.033, sc * 0.012, false), FUR, 0.88);+ g.fill(tube([lerp(b, t, 0.62), t], sc * 0.018, sc * 0.007, false), FUR_D, 0.7);+ });+ }+ [-1, 1].forEach((sd) => { /* the antennae: slender, finely RINGED, ending in a true club */+ const a0 = T([CX + sd * 10, CY - 124]), a1 = T([CX + sd * 52, CY - 190]), a2 = T([CX + sd * 116, CY - 226]);+ const pts = Array.from({ length: 9 }, (_, i) => { const t = i / 8; return lerp(lerp(a0, a1, t), lerp(a1, a2, t), t); });+ g.fill(tube(pts, sc * 0.026, sc * 0.011, false), mixc(EYE, UMBER, 0.3), 0.82);+ if (lod > 120) for (let i = 1; i < 8; i++) g.fill(tube([pts[i], lerp(pts[i], pts[i + 1], 0.45)], sc * 0.016, sc * 0.014, false), FUR, 0.4);+ const cl = pts[8], cb = pts[7];+ ps(g, oval(cl[0] + (cl[0] - cb[0]) * 0.3, cl[1] + (cl[1] - cb[1]) * 0.3, sc * 0.046, sc * 0.03, 9), mixc(EYE, UMBER, 0.2), 0.88, seed + 440 + sd, sc * 0.1, false);+ });+ proboscis(g, T, sc, prob, probTo);+};++// coiled between the palps at rest, a fine double tube when it is out+export const proboscis = (g: Gfx, T: (p: P) => P, sc: number, p: number, to?: P) => {+ const base = T([CX, CY - 132]), tip: P = to ?? [base[0], base[1] + sc * 1.2], spir: P[] = [];+ for (let i = 0; i <= 26; i++) {+ const t = i / 26, a = 1.4 + t * 2.6 * Math.PI * 2, rr = sc * (0.018 + 0.085 * t);+ const coiled: P = [base[0] + Math.cos(a) * rr, base[1] + Math.sin(a) * rr];+ const bw = Math.sin(t * Math.PI) * sc * 0.3;+ const straight: P = [base[0] + (tip[0] - base[0]) * t - bw * 0.45, base[1] + (tip[1] - base[1]) * t + bw];+ spir.push([coiled[0] + (straight[0] - coiled[0]) * p, coiled[1] + (straight[1] - coiled[1]) * p]);+ }+ g.fill(tube(spir, sc * 0.022, sc * 0.012, false), mixc(EYE, UMBER, 0.25), 0.72);+ if (p > 0.4) g.fill(tube(spir.map((q) => [q[0] + sc * 0.013, q[1] + sc * 0.006] as P), sc * 0.009, sc * 0.005, false), FUR, 0.3 * p); /* it is a DOUBLE tube: two galeae zipped together */+};++// ---------------------------------------------------------------- six legs: femur, tibia, tarsus+export const legs = (g: Gfx, T: (p: P) => P, sc: number, open: number, seed: number, front: boolean) => {+ const r = rng(seed + 77);+ ([[-1, -46, 0.95], [1, -46, 0.95], [-1, 4, 1.05], [1, 4, 1.05], [-1, 52, 1.15], [1, 52, 1.15]] as number[][]).forEach(([sd, y, len], k) => {+ if ((k % 2 === 0) === front) return; /* half of them are on the far side of the body and go under the wings */+ const hip = T([CX + sd * 26, CY + y]), a0 = sd * (0.5 + 0.55 * open) + (r() - 0.5) * 0.18, L = sc * 0.34 * len;+ const knee: P = [hip[0] + Math.cos(a0) * L * (0.5 + 0.5 * open), hip[1] + Math.abs(Math.sin(a0)) * L * 0.42 + L * 0.1];+ const a1 = a0 + sd * (0.9 - 0.4 * open);+ const foot: P = [knee[0] + Math.cos(a1) * L * 0.9 * (0.4 + 0.6 * open), knee[1] + L * (0.5 + 0.5 * open)];+ g.fill(tube([hip, knee], sc * 0.022, sc * 0.015, false), LEG, 0.8); /* femur */+ g.fill(tube([knee, foot], sc * 0.016, sc * 0.009, false), LEG, 0.78); /* tibia */+ g.fill(tube([foot, [foot[0] + Math.cos(a1) * L * 0.2, foot[1] + L * 0.1] as P], sc * 0.01, sc * 0.004, false), mixc(LEG, EYE, 0.5), 0.8); /* tarsus, ending in a claw */+ for (let i = 0; i < 3; i++) { const p = lerp(hip, knee, 0.3 + i * 0.25); g.fill(tube([p, [p[0] + (r() - 0.5) * sc * 0.05, p[1] - sc * 0.03] as P], sc * 0.005, sc * 0.002, false), FUR_D, 0.5); }+ });+};diff --git a/example/src/canvas-core/butterfly/cues.ts b/example/src/canvas-core/butterfly/cues.tsnew file mode 100644index 0000000..d476bf3--- /dev/null+++ b/example/src/canvas-core/butterfly/cues.ts@@ -0,0 +1,71 @@+// THE TIMELINE. Every frame number in the film lives in this table and nowhere else. 120 bpm at+// 30 fps: one beat = 15 frames, cuts on multiples of 15, events on multiples of 5 (triplet+// eighths, which is what an escapement sounds like anyway). State is a pure function of frame.+import { FULL, PlateState } from "./plate";+import { WIDE } from "./surface";+import { Train } from "./parts";++export type Ease = "linear" | "out" | "outBack" | "flick";+export type Cue = { at: number; dur: number; id: string; ease?: Ease; amp?: number };++// The motion test: four shots, eight beats. It starts on the approved plate and ends on it.+export const SHOTS: [string, number, number][] = [["still", 0, 30], ["wind", 30, 60], ["hush", 60, 90], ["alive", 90, 120]];+export const CUES: Cue[] = [+ { at: 15, dur: 20, id: "key.rise", ease: "outBack" }, /* the key rides up its own centre line and seats with a small overshoot */+ { at: 35, dur: 20, id: "key.wind", ease: "linear" }, /* four turns of 5 frames: in plan view the bows foreshorten to a line and back */+ { at: 55, dur: 10, id: "key.out", ease: "out" },+ { at: 65, dur: 10, id: "twitch", ease: "flick", amp: 0.14 }, /* it moves once before anyone expects it */+ { at: 75, dur: 15, id: "flap1", ease: "flick", amp: 0.55 },+ { at: 90, dur: 10, id: "flap2", ease: "flick", amp: 0.62 },+ { at: 100, dur: 5, id: "flap3", ease: "flick", amp: 0.45 },+ { at: 105, dur: 5, id: "flap4", ease: "flick", amp: 0.3 },+ { at: 110, dur: 5, id: "flap5", ease: "flick", amp: 0.14 },+ { at: 85, dur: 15, id: "shadow.out", ease: "out" }, /* the drawing separates from its own paper */+ { at: 105, dur: 10, id: "shadow.in", ease: "out" },+ { at: 85, dur: 30, id: "boil" }, /* hero linework breathes only while it is alive */+];+export const TICK0 = 35, TICK = 5; // the train starts on the first turn of the key and never stops+export const DURATION = 120;++const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ease = (p: number, e: Ease = "linear") => e === "out" ? 1 - (1 - p) ** 3 : e === "outBack" ? 1 + 1.7 * (p - 1) ** 3 + 0.7 * (p - 1) ** 2 : e === "flick" ? (p < 0.35 ? Math.sin((p / 0.35) * Math.PI / 2) : Math.cos(((p - 0.35) / 0.65) * Math.PI / 2)) : p;+const cue = (id: string) => { const c = CUES.find((x) => x.id === id); if (!c) throw new Error(`no cue '${id}'`); return c; };+export const at = (frame: number, id: string): number => { const c = cue(id); return ease(clamp((frame - c.at) / c.dur), c.ease); }; // 0 before, 1 after+export const raw = (frame: number, id: string): number => { const c = cue(id); return clamp((frame - c.at) / c.dur); };++// the going train: one tooth of the escape wheel per tick, snapped over two frames with a+// one-frame recoil, and every other wheel geared off it by its tooth count+const STEP = [14 / 24, 26 / 24, 1, 1, 1];+export const advance = (frame: number): number => { if (frame < TICK0 + TICK) return 0; const t = Math.floor((frame - TICK0) / TICK), s = (frame - TICK0) % TICK; return t - 1 + STEP[s]; };+export const trainAt = (frame: number): Train => {+ const a = advance(frame), w = (Math.PI * 2) / 96, t = Math.floor((frame - TICK0) / TICK), s = (frame - TICK0) % TICK;+ const rocking = frame >= TICK0 + TICK && s === 0 ? 0 : 0.085 * (t % 2 ? 1 : -1); /* the fork passes through centre on the tick frame */+ return { centre: a * w, third: -a * w * (24 / 14), pinion: a * w * (24 / 8), escape: a * ((Math.PI * 2) / 15), fork: frame < TICK0 + TICK ? 0 : rocking };+};++export const stateAt = (frame: number): PlateState => {+ const flap = ["twitch", "flap1", "flap2", "flap3", "flap4", "flap5"].reduce((f, id) => f - (cue(id).amp ?? 0) * at(frame, id), 1);+ const sh = 1 - at(frame, "shadow.in"), out = at(frame, "shadow.out") * sh, wind = raw(frame, "key.wind");+ return {+ wings: { flap, sweep: -0.2 * (1 - flap) }, /* a raised wing also rakes forward: the 57o sweep the plate dimensions */+ lift: 1, /* the starboard panel stays off the wing: the film ends on the approved plate */+ keyY: at(frame, "key.rise") * (1 - at(frame, "key.out")),+ keyTurn: wind >= 1 || wind <= 0 ? 0 : wind * 4 * Math.PI * 2,+ train: trainAt(frame),+ shadow: [out * 10, out * 14],+ boil: at(frame, "boil") > 0 && raw(frame, "boil") < 1 ? 0.25 : 0,+ inkedBoil: 0, /* the motion test is the same desk: the furniture does not move (spec 4) */+ boilIndex: Math.floor(frame / 5) % 4,+ p: FULL, /* the motion test starts from the finished plate */+ view: WIDE,+ };+};++// The grid is a rule, so it is checked, not trusted (spec 9, G1).+export const gridProblems = (): string[] => {+ const p: string[] = [];+ CUES.forEach((c) => { if (c.at % 5) p.push(`cue '${c.id}' starts on frame ${c.at}, not a multiple of 5`); if ((c.at + c.dur) % 5) p.push(`cue '${c.id}' ends on frame ${c.at + c.dur}, not a multiple of 5`); if (c.at + c.dur > DURATION) p.push(`cue '${c.id}' ends after the film`); });+ SHOTS.forEach(([id, a, b]) => { if (a % 15 || b % 15) p.push(`shot '${id}' cuts off the beat grid (${a}..${b})`); });+ if (TICK0 % 5) p.push(`the train starts on frame ${TICK0}, not a multiple of 5`);+ return p;+};diff --git a/example/src/canvas-core/butterfly/finale/compose.ts b/example/src/canvas-core/butterfly/finale/compose.tsnew file mode 100644index 0000000..78eaa89--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/compose.ts@@ -0,0 +1,61 @@+// THE FINALE FRAME. One sheet of cold-press, painted back to front: sky, hills, far field, the+// path, the grass planes with their flower drifts, the hero flowers, what it left behind, the+// creature, the fringe across the lens, and the signature in the corner. The camera is one+// number, so the same function paints the opening close-up and the last wide shot.+import { Ctx, Env, Gfx, P, PENCIL } from "../../core";+import { Cam, GRASS_LIT, GRASS_MID, GRASS_SHADE, projector } from "./world";+import { farField, footpath, grassBlades, grassWash, hills, sky } from "./scene";+import { Drift, drift, flower } from "./flora";+import { Flight, drawCreature } from "./creature";+import { blueprintSheet } from "./sheet";+import { clearCorner, signature } from "./signature";+import { clump } from "./paint";++export type FinaleState = { cam: Cam; creature: { at: P; scale: number; flight: Flight } | null; sig: number; lean: number };+export const PAPER_F = "#fbf7ee";++// hand-placed drifts: a centre, a radius, a species, and seeded scatter that thins outward.+// Three bare rests of plain grass are left on purpose, at world x 380-520 on P3, left of F3,+// and right of the path on P4.+const DRIFTS: [number, Drift][] = [+ [3.5, { sp: "buttercup", at: [470, 545], r: 150, n: 26, size: 5.5, seed: 7101 }],+ [3.5, { sp: "buttercup", at: [700, 560], r: 120, n: 16, size: 5, seed: 7102 }],+ [3.5, { sp: "daisy", at: [200, 560], r: 130, n: 12, size: 5, seed: 7103 }],+ [2.2, { sp: "poppy", at: [780, 655], r: 170, n: 20, size: 9, seed: 7201 }],+ [2.2, { sp: "cosmos", at: [640, 640], r: 90, n: 9, size: 11, seed: 7202 }],+ [2.2, { sp: "daisy", at: [250, 660], r: 120, n: 14, size: 8, seed: 7203 }],+ [1.0, { sp: "cornflower", at: [250, 690], r: 95, n: 13, size: 13, seed: 7301 }],+ [1.0, { sp: "daisy", at: [430, 720], r: 150, n: 16, size: 12, seed: 7302 }],+ [1.0, { sp: "cosmos", at: [760, 700], r: 110, n: 8, size: 13, seed: 7303 }],+];++export const drawFinale = (ctx: Ctx, env: Env, s: FinaleState) => {+ const W = env.W, H = env.H, g = new Gfx(ctx, env, 0, PENCIL), c = ctx, cam = s.cam;+ c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.fillStyle = PAPER_F; c.fillRect(0, 0, W, H);+ g.paper("coldpress", 0.16); /* the sheet, before anything is on it */+ g.group("plain", () => { sky(g, cam, W, H); }, { alpha: 1 }); /* a paint group softens and granulates every plane, which put a grey veil over the whole meadow: the washes carry their own edge */+ g.group("plain", () => { hills(g, cam); }, { alpha: 1 });+ g.group("plain", () => { farField(g, cam); }, { alpha: 1 });+ ([[3.5, 545, 61, 26, 0.06, 0.42], [2.2, 640, 67, 34, 0.08, 0.22], [1.0, 706, 71, 46, 0.1, 0]] as number[][]).forEach(([z, y0, seed, n, lean, fade]) => {+ g.group("plain", () => { grassWash(g, cam, z, y0, seed, { lean, fade, cool: z === 1 }); if (z === 3.5) footpath(g, cam); }, { alpha: 1 }); /* the path is worn INTO the plane it crosses */+ g.group("plain", () => grassBlades(g, cam, z, y0, seed, { blades: n, lean, fade }), { alpha: 0.95 }); /* blades on dry paint keep their edge */+ const pr = projector(cam, z);+ g.group("plain", () => DRIFTS.filter(([dz]) => dz === z).forEach(([, d]) => drift(g, d, pr.at, pr.k, s.lean)), { alpha: 0.97 });+ });+ /* the hero plane: what it left behind, and the two flowers it has already visited */+ const h0 = projector(cam, 0), h1 = projector(cam, 0.3);+ g.group("plain", () => {+ blueprintSheet(g, h0.at([150, 965]), 150 * h0.k);+ flower(g, "daisy", h0.at([330, 830]), 34 * h0.k, 7401, { variant: 0, lean: s.lean });+ flower(g, "daisy", h0.at([250, 880]), 26 * h0.k, 7402, { variant: 1, lean: s.lean });+ flower(g, "poppy", h1.at([560, 800]), 30 * h1.k, 7403, { variant: 0, lean: s.lean });+ flower(g, "poppy", h1.at([650, 840]), 22 * h1.k, 7404, { variant: 3, lean: s.lean });+ }, { alpha: 0.98 });+ if (s.creature) g.group("plain", () => drawCreature(g, s.creature!.at, s.creature!.scale, s.creature!.flight), { alpha: 0.98 });+ /* the fringe across the lens: huge, soft, no edge, and gone by the third second */+ const fr = projector(cam, -0.2);+ g.group("plain", () => { const roots: P[] = [[-40, 1120], [180, 1160], [900, 1150], [1120, 1090], [620, 1180]];+ roots.forEach((w0, i) => clump(g, fr.at(w0), (240 + i * 34) * fr.k, 60 * fr.k, [GRASS_SHADE, GRASS_MID, GRASS_LIT][i % 3], 7500 + i, 0.06 + i * 0.02, 6, 0.3)); }, { alpha: 0.5, blur: 2.2 });+ g.group("plain", () => { clearCorner(g, s.sig > 0 ? 1 : 0); signature(g, s.sig); }, { alpha: 1 });+ g.paper("washGran", 0.05); g.paper("coldpress", 0.07); /* the tooth of the sheet, over everything */+};diff --git a/example/src/canvas-core/butterfly/finale/creature.ts b/example/src/canvas-core/butterfly/finale/creature.tsnew file mode 100644index 0000000..792300c--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/creature.ts@@ -0,0 +1,73 @@+// THE CREATURE, REPAINTED. Same control points, new paint. Each membrane panel between the+// spars is its own small wet-in-wet wash, rose at the root running to peach at the margin with+// a butter drop near the tip. The spars are denim line, the rivets are lifted dots, the rim+// light on the sunward margins is paper left unpainted, and starboard forewing panel 2 is+// cornflower blue with a ruled grid lifted in it: a piece of the blueprint it carries with it.+import { Gfx, P, jitter, oval, rng, tube } from "../../core";+import { CX, CY, FW, FW_H, FW_T, HEAD, HW, HW_H, HW_T, Pose, THORAX, Wing, cen, lerp, wingGeom } from "../geom";+import { BUTTER, CORNFLOWER, DENIM, GRASS_SHADE, INK_P, PAPER_W, PEACH, ROSE } from "./world";+import { lift, mottle, wet } from "./paint";++export type Flight = { pose: Pose; heading: number; pitch: number; bank: number };+export const REST_FLIGHT: Flight = { pose: { flap: 1, sweep: 0 }, heading: 0, pitch: 1, bank: 0 };++// world -> screen for the creature: pose on the control points first, then heading, pitch, scale+const mapper = (at: P, scale: number, f: Flight) => {+ const c = Math.cos(f.heading), s = Math.sin(f.heading);+ return (p: P): P => {+ const dx = (p[0] - CX) * scale, dy = (p[1] - CY) * scale * f.pitch; /* pitch foreshortens along the body axis as it climbs away */+ return [at[0] + dx * c - dy * s, at[1] + dx * s + dy * c];+ };+};+export const drawCreature = (g: Gfx, at: P, scale: number, f: Flight, seed = 900) => {+ const T = mapper(at, scale, f), r = rng(seed);+ const pose = f.pose, port = { ...pose, flap: Math.min(1, pose.flap + f.bank) }, star = { ...pose, flap: Math.max(0.2, pose.flap - f.bank) };+ const w: Wing[] = [wingGeom(-1, HW, HW_H, HW_T, 2000, port), wingGeom(1, HW, HW_H, HW_T, 2600, star), wingGeom(-1, FW, FW_H, FW_T, 1000, port), wingGeom(1, FW, FW_H, FW_T, 1600, star)];+ const sc = scale * 90; /* one "unit" of paint at this size */+ g.fill(oval(at[0] - sc * 0.5, at[1] + sc * 0.55, sc * 1.5, sc * 0.35, 10), GRASS_SHADE, 0.16); /* the shadow it throws on the grass, lower left */+ /* the paper was LEFT for it. A watercolourist paints the field around the subject and keeps+ the sheet clean underneath, which is why a wash over white glows and a wash over green does not */+ const reserve: P[] = [];+ w.forEach((wg) => wg.out.forEach((q) => reserve.push(T(q))));+ const rc = cen(reserve);+ w.forEach((wg) => { g.fill(wg.out.map((q) => { const p = T(q); return lerp(p, rc, -0.03) as P; }), PAPER_W, 0.93); });+ g.fill(THORAX.map((q) => lerp(T(q), rc, -0.08)), PAPER_W, 0.95);+ w.forEach((wg, i) => {+ const star2 = i % 2 === 1, out = wg.out.map(T), root = T(wg.h), margin = out.map((q) => lerp(q, cen(out), 0.055));+ /* the margin band: the darkest pigment on the wing, laid first and let dry */+ wet(g, out, ROSE, { alpha: 0.62, seed: seed + i * 40, shrink: 0.985, rim: true, dx: 2, dy: 2 });+ wg.panels.forEach((pn, j) => {+ const p = pn.map((q) => lerp(q, cen(pn), 0.12)).map(T), c0 = cen(p), d = Math.hypot(c0[0] - root[0], c0[1] - root[1]), far = Math.min(1, d / (sc * 3.2));+ if (i === 3 && j === 2) { /* the panel that never came home, painted the colour of the plate it came from */+ wet(g, p, CORNFLOWER, { alpha: 0.8, seed: seed + 300, shrink: 0.95, rim: true });+ const gr = 3; for (let q = 1; q < gr; q++) { const a = lerp(p[0], p[6], q / gr), b = lerp(p[2], p[4], q / gr); lift(g, tube([a, b], sc * 0.03, sc * 0.03, false), seed + 310 + q, 0.5); }+ return;+ }+ /* each panel is its OWN small wash: rose at the root, peach running out to the margin,+ with a paper gap between panels so the wing reads like stained glass */+ wet(g, p, ROSE, { alpha: 0.5 + (1 - far) * 0.34, seed: seed + i * 20 + j, shrink: 0.93, rim: true, dx: 1.5, dy: 1.5 });+ wet(g, p.map((q) => lerp(q, lerp(c0, T(wg.ends[Math.min(j + 1, wg.ends.length - 1)]), 0.45), 0.3)), PEACH, { alpha: 0.3 + far * 0.34, seed: seed + 60 + i * 20 + j, dx: 2, dy: -2, shrink: 0.86, rim: false });+ if (far > 0.5 && r() > 0.4) { const tip = lerp(c0, T(wg.ends[Math.min(j + 1, wg.ends.length - 1)]), 0.55); wet(g, oval(tip[0], tip[1], sc * 0.2, sc * 0.16, 9), BUTTER, { alpha: 0.5, seed: seed + 120 + i * 9 + j, shrink: 0.88, rim: false }); } /* a drop of butter near the tip, dropped in while it is wet */+ });+ wg.ends.forEach((_, j) => { const line = Array.from({ length: 6 }, (_, q) => T(wg.spar(j, 0.05 + (q / 5) * 0.9))); g.fill(tube(line, sc * (j === 0 ? 0.05 : 0.03), sc * 0.01, false), DENIM, j === 0 ? 0.78 : 0.56); });+ for (let j = 1; j <= 4; j++) { const p = T(wg.spar(0, 0.16 + j * 0.18)); lift(g, oval(p[0], p[1], sc * 0.03, sc * 0.03, 8), seed + 200 + i * 9 + j, 0.6); }+ if (star2) { const rim = out.slice(0, Math.ceil(out.length * 0.4)); lift(g, tube(rim, sc * 0.07, sc * 0.04, false), seed + 260 + i, 0.72); } /* rim light on the sunward margin: paper left, never white paint */+ /* lost-and-found pencil: it follows the margin for a while, then leaves it alone */+ const seg = Math.ceil(out.length * 0.45); g.fill(tube([...out.slice(0, seg)], sc * 0.024, sc * 0.014, false), INK_P, 0.5);+ g.fill(tube([...out.slice(seg + 2, out.length)], sc * 0.02, sc * 0.012, false), INK_P, 0.3);+ });+ const body = THORAX.map(T), head = HEAD.map(T);+ for (let i = 0; i < 6; i++) { /* the abdomen is six printed segments with the paper showing in the joints */+ const t0 = i / 6, t1 = (i + 1) / 6, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5, g0 = 1.6;+ const q: P[] = [T([CX - hw(t0) * 0.9 + g0, CY + (70 + 170 * t0) * 0.9 + g0]), T([CX + hw(t0) * 0.9 - g0, CY + (70 + 170 * t0) * 0.9 + g0]), T([CX + hw(t1) * 0.9 - g0, CY + (70 + 170 * t1) * 0.9 - g0]), T([CX - hw(t1) * 0.9 + g0, CY + (70 + 170 * t1) * 0.9 - g0])];+ wet(g, q, DENIM, { alpha: 0.72 - i * 0.03, seed: seed + 400 + i, shrink: 0.94, rim: true, dx: 1, dy: 1 });+ }+ wet(g, body, DENIM, { alpha: 0.8, seed: seed + 420, shrink: 0.94, rim: true });+ wet(g, head, DENIM, { alpha: 0.84, seed: seed + 424, shrink: 0.92, rim: true });+ wet(g, body.map((q) => lerp(q, [cen(body)[0] - sc * 0.12, cen(body)[1]] as P, 0.3)), "#4f6f9e", { alpha: 0.34, seed: seed + 426, shrink: 0.9, rim: false }); /* the shadow side: the sun is upper right */+ lift(g, oval(T([CX + 14, CY - 30])[0], T([CX + 14, CY - 30])[1], sc * 0.13, sc * 0.3, 10), seed + 410, 0.45); /* the lit side of the body, taken back off */+ const o = cen(THORAX); ([[o[0] + 2, o[1] + 8, 24], [o[0] - 18, o[1] - 32, 14], [o[0] + 22, o[1] - 24, 10]] as number[][]).forEach(([x, y, rr], i) => { const p = T([x, y]); lift(g, oval(p[0], p[1], rr * scale * 0.95, rr * scale * 0.95, 12), seed + 420 + i, 0.5); wet(g, jitter(oval(p[0], p[1], rr * scale, rr * scale, 12), rr * scale * 0.12, seed + 430 + i), "#8fb3d8", { alpha: 0.42, seed: seed + 430 + i, shrink: 0.9, rim: true }); }); /* the train, lifted out and dropped in cool sky: still clockwork */+ [-1, 1].forEach((sd) => { const a0 = T([CX + sd * 8, CY - 114]), a1 = T([CX + sd * 50, CY - 186]), a2 = T([CX + sd * 112, CY - 222]); const pts = Array.from({ length: 7 }, (_, i) => { const t = i / 6; return lerp(lerp(a0, a1, t), lerp(a1, a2, t), t); }); g.fill(tube(pts, sc * 0.035, sc * 0.012, false), INK_P, 0.7); g.fill(oval(a2[0], a2[1], sc * 0.055, sc * 0.055, 8), INK_P, 0.7); });+ const pr = T([CX, CY - 135]), spir: P[] = []; for (let i = 0; i <= 26; i++) { const t = i / 26, a = 1.4 + t * 2.6 * Math.PI * 2, rr = sc * (0.02 + 0.1 * t); spir.push([pr[0] + Math.cos(a) * rr, pr[1] + Math.sin(a) * rr]); }+ g.fill(tube(spir, sc * 0.026, sc * 0.014, false), INK_P, 0.45); /* the proboscis is still a hairspring */+};diff --git a/example/src/canvas-core/butterfly/finale/flora.ts b/example/src/canvas-core/butterfly/finale/flora.tsnew file mode 100644index 0000000..de224ec--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/flora.ts@@ -0,0 +1,54 @@+// FIVE SPECIES, FOUR VARIANTS EACH, and a level of detail that follows the painter's own rule:+// close up you draw the flower, further off you put down the petals as single strokes, further+// still it is two dabs, colour and shadow, and at the back of the field it is one dab.+// Every species is a colour the film has already used.+import { Gfx, P, oval, rng, tube } from "../../core";+import { BUTTERCUP, CORNFLOWER, COSMOS, DAISY, DAISY_SHADE, GRASS_SHADE, POPPY, POPPY_DARK, PAPER_W, STEM } from "./world";++export type Sp = "daisy" | "poppy" | "cornflower" | "cosmos" | "buttercup";+const COL: Record<Sp, [string, string]> = { daisy: [DAISY, DAISY_SHADE], poppy: [POPPY, POPPY_DARK], cornflower: [CORNFLOWER, "#3f5e9e"], cosmos: [COSMOS, "#d druck"], buttercup: [BUTTERCUP, "#d9a323"] };+COL.cosmos = [COSMOS, "#d2789a"];++const stem = (g: Gfx, root: P, head: P, w: number, seed: number, lean: number) => {+ const r = rng(seed), mid: P = [(root[0] + head[0]) / 2 + (r() - 0.5) * 8 * w + lean * 10, (root[1] + head[1]) / 2];+ g.fill(tube([root, mid, head], w * 1.25, w * 0.6, false), STEM, 0.8);+ if (w > 1.2) { const lp = 0.45 + r() * 0.25, at: P = [root[0] + (head[0] - root[0]) * lp, root[1] + (head[1] - root[1]) * lp], dir = r() < 0.5 ? -1 : 1; g.fill(tube([at, [at[0] + dir * w * 7, at[1] - w * 3], [at[0] + dir * w * 11, at[1] - w * 9]], w * 1.1, w * 0.4, false), STEM, 0.75); }+};+// one flower. `size` is its head radius on screen; everything else follows from that.+export const flower = (g: Gfx, sp: Sp, at: P, size: number, seed: number, o: { variant?: number; lean?: number; dip?: number; light?: number } = {}) => {+ const r = rng(seed), v = o.variant ?? Math.floor(r() * 4), [col, dark] = COL[sp], lean = (o.lean ?? 0) + (o.dip ?? 0) * 0.5;+ const head: P = [at[0] + lean * size * 1.6, at[1] - size * (sp === "daisy" ? 2.6 : sp === "poppy" ? 2.4 : sp === "cosmos" ? 3 : 2.2) * (1 - (o.dip ?? 0) * 0.12)];+ if (size < 3) { g.fill(oval(head[0], head[1], size * 1.2, size, 7), col, 0.75); return; }+ if (size < 7) { g.fill(oval(head[0] + size * 0.3, head[1] + size * 0.3, size * 1.1, size * 0.9, 8), dark, 0.4); g.fill(oval(head[0], head[1], size * 1.15, size * 0.95, 8), col, 0.85); return; } /* two dabs: colour and its shadow */+ stem(g, at, head, Math.max(0.7, size * 0.11), seed + 1, lean);+ const petals = sp === "daisy" ? 13 : sp === "poppy" ? 4 : sp === "cornflower" ? 11 : sp === "cosmos" ? 8 : 5;+ const bud = v === 3, profile = v === 2, tilt = v === 1 ? 0.55 : 1;+ if (bud) { g.fill(oval(head[0], head[1], size * 0.5, size * 0.78, 9), col, 0.85); g.fill(tube([[head[0], head[1] + size * 0.6], [head[0], head[1] - size * 0.2]], size * 0.36, size * 0.2, false), STEM, 0.8); return; }+ const open = profile ? Math.PI * 0.55 : Math.PI * 2, a0 = profile ? -Math.PI * 0.78 : 0;+ if (size < 16) { for (let i = 0; i < petals; i++) { const a = a0 + (i / petals) * open, e: P = [head[0] + Math.cos(a) * size * (profile ? 0.8 : 1), head[1] + Math.sin(a) * size * tilt]; g.fill(tube([head, e], size * 0.3, size * 0.14, false), i % 3 === 0 ? dark : col, 0.85); } g.fill(oval(head[0], head[1], size * 0.3, size * 0.3 * tilt, 8), sp === "daisy" ? BUTTERCUP : dark, 0.9); return; } /* petals as single strokes */+ for (let i = 0; i < petals; i++) {+ const a = a0 + (i / petals) * open + (r() - 0.5) * 0.12, L = size * (0.85 + r() * 0.3), lit = Math.cos(a + 0.9) * 0.5 + 0.5; /* the sun is upper right, so petals facing it are paler */+ const tip: P = [head[0] + Math.cos(a) * L, head[1] + Math.sin(a) * L * tilt], mid: P = [head[0] + Math.cos(a + 0.18) * L * 0.55, head[1] + Math.sin(a + 0.18) * L * 0.55 * tilt];+ const pet = [head, mid, tip, [head[0] + Math.cos(a - 0.2) * L * 0.5, head[1] + Math.sin(a - 0.2) * L * 0.5 * tilt] as P];+ g.wash(pet, lit > 0.55 ? col : dark, { alpha: sp === "daisy" ? 0.5 : 0.62, seed: seed + i * 3, dx: 1, dy: 1, shrink: 0.94, rim: r() > 0.5 });+ if (sp === "daisy" && lit > 0.6) g.fill(tube([head, tip], L * 0.16, L * 0.1, false), PAPER_W, 0.5); /* paper white left for the lit petals */+ }+ const cr = size * (sp === "poppy" ? 0.34 : 0.28);+ g.wash(oval(head[0], head[1], cr, cr * tilt, 10), sp === "daisy" || sp === "cosmos" ? BUTTERCUP : sp === "poppy" ? POPPY_DARK : dark, { alpha: 0.85, seed: seed + 40, dx: 0, dy: 0, shrink: 0.95, rim: true });+ if (sp === "poppy") { const r2 = rng(seed + 9); for (let i = 0; i < 7; i++) { const a = r2() * 6.283; g.fill(oval(head[0] + Math.cos(a) * cr * 1.5, head[1] + Math.sin(a) * cr * 1.5 * tilt, size * 0.05, size * 0.05, 6), POPPY_DARK, 0.7); } }+ g.fill(oval(at[0] - size * 0.5, at[1] + size * 0.12, size * 0.85, size * 0.22, 9), GRASS_SHADE, 0.18); /* the dab of shadow it throws on the grass */+};++// a DRIFT: a hand-placed centre, a radius, a species, and seeded scatter that thins toward its+// edge. No even scatter anywhere, and no variant more than a quarter of the drift.+export type Drift = { sp: Sp; at: P; r: number; n: number; size: number; seed: number };+export const drift = (g: Gfx, d: Drift, project: (p: P) => P, k: number, lean = 0, lod = 1) => {+ const r = rng(d.seed);+ const items: { p: P; s: number; v: number; seed: number }[] = [];+ for (let i = 0; i < d.n; i++) {+ const a = r() * 6.283, rad = Math.pow(r(), 0.7) * d.r, w: P = [d.at[0] + Math.cos(a) * rad, d.at[1] + Math.sin(a) * rad * 0.42];+ items.push({ p: project(w), s: d.size * k * (0.75 + r() * 0.5), v: Math.floor(r() * 4), seed: d.seed + i * 17 });+ }+ items.sort((a, b) => a.p[1] - b.p[1]); /* back to front, so nearer flowers overlap the ones behind */+ items.forEach((it) => { if (it.s * lod < 1.4) return; flower(g, d.sp, it.p, it.s, it.seed, { variant: it.v, lean }); });+};diff --git a/example/src/canvas-core/butterfly/finale/paint.ts b/example/src/canvas-core/butterfly/finale/paint.tsnew file mode 100644index 0000000..5b611ec--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/paint.ts@@ -0,0 +1,48 @@+// WATERCOLOUR, THE VERBS. Every mark in the finale is one of these: a graded wash, a wet band+// that spreads and pools, a lifted highlight (paper left, or pigment taken back off), dry-brush+// texture dragged over dry paint, and a backrun where clean water hit a drying wash.+import { Ctx, Gfx, P, displace, jitter, oval, rng, sample, tube } from "../../core";++export const wet = (g: Gfx, pts: P[], col: string, o: { alpha?: number; seed?: number; shrink?: number; rim?: boolean; dx?: number; dy?: number } = {}) =>+ g.wash(pts, col, { alpha: o.alpha ?? 0.42, seed: o.seed ?? 1, dx: o.dx ?? 2, dy: o.dy ?? 2, shrink: o.shrink ?? 0.97, rim: o.rim ?? true });++// pigment never dries flat: it pools where the water sat and lifts where it ran out+export const mottle = (g: Gfx, pts: P[], col: string, seed: number, n: number, a: number) => {+ const r = rng(seed), c = pts.reduce((s, p) => [s[0] + p[0] / pts.length, s[1] + p[1] / pts.length] as P, [0, 0] as P);+ for (let i = 0; i < n; i++) { const k = 0.3 + r() * 0.45, dx = (r() - 0.5) * 60, dy = (r() - 0.5) * 50; g.wash(pts.map((p) => [c[0] + (p[0] - c[0]) * k + dx, c[1] + (p[1] - c[1]) * k + dy] as P), col, { alpha: a * (0.5 + r() * 0.7), seed: seed + i * 3, dx: (r() - 0.5) * 8, dy: (r() - 0.5) * 8, shrink: 0.88 + r() * 0.2, rim: r() > 0.5 }); }+};+// a graded sky: cream at the horizon, blue at the top, and the sun is simply where the paper was left alone+export const graded = (g: Gfx, x0: number, y0: number, x1: number, y1: number, top: string, low: string) => {+ const c = g.cur, gr = c.createLinearGradient(0, y0, 0, y1); gr.addColorStop(0, top); gr.addColorStop(0.72, low); gr.addColorStop(1, low);+ g.touch(x0, y0, x1, y1); c.fillStyle = gr; c.fillRect(x0, y0, x1 - x0, y1 - y0);+};+export const sunBloom = (g: Gfx, at: P, r: number, col: string, a = 0.9) => {+ const c = g.cur, gr = c.createRadialGradient(at[0], at[1], 0, at[0], at[1], r);+ gr.addColorStop(0, col + "ff"); gr.addColorStop(0.45, col + "aa"); gr.addColorStop(0.8, col + "33"); gr.addColorStop(1, col + "00");+ g.touch(at[0] - r, at[1] - r, at[0] + r, at[1] + r); c.save(); c.globalAlpha = a; c.fillStyle = gr; c.fillRect(at[0] - r, at[1] - r, r * 2, r * 2); c.restore();+};+// clean water into a drying wash: it pushes pigment out and strands it in a hard ring+export const backrun = (g: Gfx, at: P, r: number, seed: number, col: string, strength = 0.55) => {+ const c = g.cur;+ c.globalCompositeOperation = "destination-out";+ g.wash(jitter(oval(at[0], at[1], r, r * 0.86, 18), r * 0.2, seed), "#000000", { alpha: strength, seed, dx: 0, dy: 0, shrink: 1, rim: false });+ c.globalCompositeOperation = "multiply";+ g.wash(jitter(oval(at[0], at[1], r * 1.06, r * 0.93, 18), r * 0.22, seed + 7), col, { alpha: 0.24, seed: seed + 7, dx: 0, dy: 0, shrink: 1.02, rim: true });+ c.globalCompositeOperation = "source-over";+};+// take pigment back off with a damp brush: the only way to get light back in watercolour+export const lift = (g: Gfx, pts: P[], seed: number, strength = 0.5) => { const c = g.cur; c.globalCompositeOperation = "destination-out"; g.wash(pts, "#000000", { alpha: strength, seed, dx: 0, dy: 0, shrink: 1, rim: false }); c.globalCompositeOperation = "source-over"; };+// dry brush: a loaded brush dragged over dry paper skips, and only the tooth takes colour+export const dryBrush = (g: Gfx, a: P, b: P, w: number, col: string, seed: number, alpha = 0.5) => {+ const r = rng(seed), n = 5 + Math.floor(r() * 4), c = g.cur;+ for (let i = 0; i < n; i++) { const t0 = r() * 0.5, t1 = t0 + 0.2 + r() * 0.5, p0: P = [a[0] + (b[0] - a[0]) * t0, a[1] + (b[1] - a[1]) * t0], p1: P = [a[0] + (b[0] - a[0]) * t1, a[1] + (b[1] - a[1]) * t1]; g.fill(tube([p0, p1], w * (0.5 + r() * 0.8), w * 0.3, false), col, alpha * (0.5 + r() * 0.6)); }+};+// a blade of grass: it leaves the ground thick and ends in a point, and it bends with the wind+export const blade = (g: Gfx, root: P, len: number, ang: number, lean: number, w: number, col: string, seed: number, alpha = 0.9) => {+ const pts: P[] = []; for (let i = 0; i <= 5; i++) { const t = i / 5, a = ang + lean * t * t, r = len * t; pts.push([root[0] + Math.sin(a) * r, root[1] - Math.cos(a) * r]); }+ g.fill(tube(pts, w, w * 0.12, false), col, alpha);+};+export const clump = (g: Gfx, root: P, h: number, spread: number, col: string, seed: number, lean = 0, n = 7, alpha = 0.9) => {+ const r = rng(seed);+ for (let i = 0; i < n; i++) { const t = n > 1 ? i / (n - 1) - 0.5 : 0; blade(g, [root[0] + t * spread * 0.4 + (r() - 0.5) * 4, root[1] + (r() - 0.5) * 3], h * (0.6 + r() * 0.65), t * spread * 0.014 + (r() - 0.5) * 0.12, lean * (0.7 + r() * 0.6), Math.max(0.8, h * 0.028), col, seed + i, alpha * (0.7 + r() * 0.35)); }+};diff --git a/example/src/canvas-core/butterfly/finale/scene.ts b/example/src/canvas-core/butterfly/finale/scene.tsnew file mode 100644index 0000000..88cf2ac--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/scene.ts@@ -0,0 +1,104 @@+// THE WORLD, PAINTED. Sky, hills, far field, the path, and the grass planes. Everything is laid+// as a wash first and worked into while it is wet; nothing is outlined. Farther planes are+// paler, bluer, softer and lower in contrast, which is the only way distance reads in paint.+import { Gfx, P, jitter, oval, rng } from "../../core";+import { Cam, CLOUD_SHADE, FIELD_COOL, FIELD_LIT, FIELD_MID, GRASS_LIT, GRASS_MID, GRASS_SHADE, HILL_FAR, HILL_NEAR, HORIZON, PATH, SKY_LOW, SKY_TOP, SUN, SUN_AT, TREE, projector } from "./world";+import { backrun, clump, dryBrush, graded, lift, mottle, sunBloom, wet } from "./paint";++// a band of ground: the top contour, then enough points down the sides and along the bottom that+// the wash's own smoothing cannot bulge the corners out into the sky+const slab = (top: P[], bottom: number): P[] => {+ const out = [...top], right = top[top.length - 1][0], left = top[0][0];+ for (let i = 1; i <= 6; i++) out.push([right, top[top.length - 1][1] + ((bottom - top[top.length - 1][1]) * i) / 6]);+ for (let i = 1; i <= 8; i++) out.push([right + ((left - right) * i) / 8, bottom]);+ for (let i = 1; i < 6; i++) out.push([left, bottom + ((top[0][1] - bottom) * i) / 6]);+ return out;+};+const ridge = (y: number, amp: number, seed: number, from = -200, to = 1300): P[] => {+ const r = rng(seed), out: P[] = [];+ for (let x = from; x <= to; x += 60) out.push([x, y + Math.sin(x * 0.0042 + seed) * amp + Math.sin(x * 0.0011 + seed * 2) * amp * 1.6 + (r() - 0.5) * 6]);+ return out;+};++export const sky = (g: Gfx, c: Cam, W: number, H: number) => {+ const { at } = projector(c, 1e6), hor = projector(c, 20).at([0, HORIZON])[1];+ graded(g, -20, -20, W + 20, hor + 40, SKY_TOP, SKY_LOW);+ sunBloom(g, SUN_AT, 330, "#f8e6bd", 0.34); /* the sun is where the paper was left lightest, never a disc of paint */+ sunBloom(g, SUN_AT, 150, "#fdf4de", 0.6); sunBloom(g, SUN_AT, 62, "#fffdf7", 0.9);+ /* three cumulus, lifted: white tops, a blue-violet wash underneath */+ ([[250, 150, 140, 46], [620, 96, 92, 30], [900, 250, 110, 34]] as number[][]).forEach(([x, y, rx, ry], i) => {+ const top = jitter([...Array(9)].map((_, k) => { const a = Math.PI + (k / 8) * Math.PI; return [x + Math.cos(a) * rx, y + Math.sin(a) * ry * (0.7 + 0.5 * Math.sin(k * 2.1 + i)) ] as P; }), 6, 5200 + i);+ const base: P[] = [...top, [x + rx, y + ry * 0.35], [x - rx, y + ry * 0.35]];+ wet(g, base, CLOUD_SHADE, { alpha: 0.3, seed: 5210 + i, shrink: 0.98, dx: 2, dy: 4 });+ lift(g, jitter([...Array(9)].map((_, k) => { const a = Math.PI + (k / 8) * Math.PI; return [x + Math.cos(a) * rx * 0.94, y - 4 + Math.sin(a) * ry * 0.9] as P; }), 5, 5220 + i), 5230 + i, 0.62);+ });+};++export const hills = (g: Gfx, c: Cam) => {+ const { at, k } = projector(c, 20);+ const far = ridge(HORIZON + 6, 16, 3.1).map(at), near = ridge(HORIZON + 34, 22, 5.7, -200, 1300).map(at);+ const floor = 540 + (760 - c.look[1]) * k + 900;+ wet(g, slab(far, floor), HILL_FAR, { alpha: 0.5, seed: 5300, shrink: 0.995, rim: false, dx: 1, dy: 3 });+ wet(g, slab(near, floor), HILL_NEAR, { alpha: 0.46, seed: 5310, shrink: 0.995, rim: false, dx: -2, dy: 3 });+ mottle(g, [...near.slice(6, 14), ...far.slice(6, 14).reverse()], HILL_NEAR, 5320, 3, 0.1);+ /* a hedgerow of six rounded trees on the right ridge, and one lone tree on the left */+ const r = rng(5330);+ for (let i = 0; i < 6; i++) { const x = 760 + i * 52 + r() * 14, p = at([x, HORIZON + 30 + Math.sin(x * 0.0042 + 5.7) * 22 + Math.sin(x * 0.0011 + 11.4) * 35]); wet(g, jitter(oval(p[0], p[1] - 9 * k, 15 * k * (0.8 + r() * 0.5), 11 * k * (0.8 + r() * 0.4), 11), 2.5, 5340 + i), TREE, { alpha: 0.42, seed: 5340 + i, shrink: 0.96, rim: false }); }+ const lone = at([210, HORIZON + 26 + Math.sin(210 * 0.0042 + 5.7) * 22 + Math.sin(210 * 0.0011 + 11.4) * 35]), th = 26 * k;+ g.fill([[lone[0] - 1.6, lone[1] + 2], [lone[0] + 1.6, lone[1] + 2], [lone[0] + 1.1, lone[1] - th], [lone[0] - 1.1, lone[1] - th]], TREE, 0.55);+ wet(g, jitter(oval(lone[0], lone[1] - th - 9 * k, 15 * k, 13 * k, 13), 2.5, 5360), TREE, { alpha: 0.52, seed: 5360, shrink: 0.94, rim: true }); /* one lone tree on the left ridge, the thing your eye goes to */+};++// the far field: colour only, no plants, and the cloud shadows that sell the sunlight+export const farField = (g: Gfx, c: Cam) => {+ const { at, k } = projector(c, 8), bottom = 540 + (900 - c.look[1]) * k;+ ([[HORIZON + 44, FIELD_COOL, 0.4, 5400], [HORIZON + 96, FIELD_MID, 0.42, 5410], [HORIZON + 168, FIELD_LIT, 0.44, 5420]] as [number, string, number, number][]).forEach(([y, col, a, seed], i) => {+ const band = ridge(y, 9, seed * 0.001 + i).map(at);+ wet(g, slab(band, bottom), col, { alpha: a, seed, shrink: 0.996, rim: i > 0, dx: i ? 3 : -3, dy: 2 });+ });+ const r = rng(5430); /* drifts of flower colour, as dabs of pure pigment, nothing drawn */+ ([["#e2452b", 700, HORIZON + 70, 150, 26], ["#f5c93f", 330, HORIZON + 110, 170, 30], ["#ef9ab8", 880, HORIZON + 140, 120, 18]] as [string, number, number, number, number][]).forEach(([col, cx, cy, rad, n], i) => {+ for (let j = 0; j < n; j++) { const a = r() * 6.283, d = Math.sqrt(r()) * rad, p = at([cx + Math.cos(a) * d, cy + Math.sin(a) * d * 0.45]); g.fill(oval(p[0], p[1], (1.6 + r() * 1.8) * k, (1.2 + r() * 1.1) * k, 7), col, 0.32 + r() * 0.3); }+ });+ ([[420, HORIZON + 120, 260, 60, 5440], [860, HORIZON + 190, 200, 44, 5450]] as number[][]).forEach(([cx, cy, rx, ry, seed]) => { const p = at([cx, cy]); wet(g, jitter(oval(p[0], p[1], rx * k, ry * k, 14), 8, seed), CLOUD_SHADE, { alpha: 0.1, seed, shrink: 0.98, rim: false }); }); /* cloud shadows crossing the field */+};++// the footpath: someone walked out here, and the eye follows them to the gap in the ridges+export const footpath = (g: Gfx, c: Cam) => {+ const { at, k } = projector(c, 3.5);+ const spine: P[] = [[980, 1140], [860, 980], [740, 830], [640, 690], [560, 560], [520, 470], [512, 424]];+ const w = (t: number) => (62 - 56 * t) * k;+ const L: P[] = [], R: P[] = [];+ spine.forEach((p, i) => { const t = i / (spine.length - 1), q = at(p); L.push([q[0] - w(t), q[1]]); R.push([q[0] + w(t), q[1]]); });+ wet(g, [...L, ...R.reverse()], PATH, { alpha: 0.42, seed: 5500, shrink: 0.985, rim: false, dx: 2, dy: 2 });+ mottle(g, [...L.slice(0, 4), ...R.slice(0, 4).reverse()], PATH, 5510, 3, 0.1);+};++// a grass plane: three wash bands on an S contour, then dry-brush and blades on top of dry paint+export const grassWash = (g: Gfx, c: Cam, z: number, y0: number, seed: number, o: { blades?: number; lean?: number; cool?: boolean; fade?: number } = {}) => {+ const { at, k } = projector(c, z), bottom = 540 + (1500 - c.look[1]) * k, r = rng(seed), fade = o.fade ?? 0;+ const mix = (a: string, b: string, t: number) => { const h = (x: string) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)]; const A = h(a), B = h(b); return "#" + A.map((v, i) => Math.round(v + (B[i] - v) * t).toString(16).padStart(2, "0")).join(""); };+ const air = (col: string) => mix(col, "#cfd9dd", fade); /* farther is paler, bluer, lower in contrast: that is all distance is */+ const cols = (o.cool ? [GRASS_SHADE, GRASS_MID, GRASS_LIT] : [GRASS_MID, GRASS_LIT, GRASS_MID]).map(air);+ cols.forEach((col, i) => {+ const band = ridge(y0 + i * 44, 13, seed * 0.01 + i * 3).map(at);+ wet(g, slab(band, bottom), col, { alpha: (0.34 + i * 0.05) * (1 + (1 - fade) * 1.1), seed: seed + i, shrink: 0.996, rim: i === 1, dx: i % 2 ? 3 : -3, dy: 2 }); /* the near planes carry enough pigment to hide what is behind them, or the picture goes milky */+ const hollow = ridge(y0 + i * 44 + 6, 13, seed * 0.01 + i * 3).map(at), lipY = 540 + (y0 + i * 44 + 30 - c.look[1]) * k;+ wet(g, slab(hollow, lipY), air(GRASS_SHADE), { alpha: 0.16 + (1 - fade) * 0.1, seed: seed + 40 + i, shrink: 0.995, rim: false, dx: -2, dy: 1 }); /* the shaded lip where the ground dips away */+ });+ mottle(g, [[-300, 540 + (y0 - c.look[1]) * k] as P, [1400, 540 + (y0 - c.look[1]) * k] as P, [1400, bottom] as P, [-300, bottom] as P], air(GRASS_MID), seed + 90, 4, 0.05);+};++// the blades go on DRY paint, so they are their own pass and they keep their edges+export const grassBlades = (g: Gfx, c: Cam, z: number, y0: number, seed: number, o: { blades?: number; lean?: number; fade?: number } = {}) => {+ const { at, k } = projector(c, z), r = rng(seed + 7), fade = o.fade ?? 0;+ const mix = (a: string, b: string, t: number) => { const h = (x: string) => [parseInt(x.slice(1, 3), 16), parseInt(x.slice(3, 5), 16), parseInt(x.slice(5, 7), 16)]; const A = h(a), B = h(b); return "#" + A.map((v, i) => Math.round(v + (B[i] - v) * t).toString(16).padStart(2, "0")).join(""); };+ const air = (col: string) => mix(col, "#cfd9dd", fade), n = o.blades ?? 26, palette = [GRASS_SHADE, GRASS_MID, GRASS_LIT].map(air);+ for (let i = 0; i < n; i++) {+ const wx = -260 + r() * 1620, wy = y0 + 16 + r() * 200, p = at([wx, wy]), h = (30 + r() * 62) * k, lean = (o.lean ?? 0) + (r() - 0.5) * 0.12;+ g.fill(oval(p[0] - h * 0.22, p[1] + 2 * k, h * 0.3, h * 0.09, 9), air(GRASS_SHADE), 0.2 * (1 - fade)); /* the shadow the clump throws to its lower left: this is what says SUN */+ clump(g, p, h, 22 * k, palette[Math.floor(r() * 3)], seed * 7 + i * 13, lean, 5 + Math.floor(r() * 5), (0.62 + r() * 0.33) * (1 - fade * 0.45));+ if (r() < 0.24) { const tip: P = [p[0] + Math.sin(lean * 1.6) * h * 0.6, p[1] - h * 0.95]; g.fill(oval(tip[0], tip[1], 2.6 * k, 5.6 * k, 9), air(GRASS_SHADE), 0.5 * (1 - fade)); }+ }+ for (let i = 0; i < n * 0.7; i++) { const wx = -260 + r() * 1620, wy = y0 + 50 + r() * 170, p = at([wx, wy]); dryBrush(g, p, [p[0] + (r() - 0.5) * 80 * k, p[1] - (18 + r() * 34) * k], 2.6 * k, air(GRASS_SHADE), seed * 11 + i, 0.3 * (1 - fade * 0.6)); }+};diff --git a/example/src/canvas-core/butterfly/finale/sheet.ts b/example/src/canvas-core/butterfly/finale/sheet.tsnew file mode 100644index 0000000..dbde46e--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/sheet.ts@@ -0,0 +1,30 @@+// WHAT IT LEFT BEHIND. A sheet of blueprint lying in the grass with a butterfly-shaped BLANK in+// it, and the winding key on top of it. The plate is still here; the creature is not in it.+import { Gfx, P, jitter, oval, rng, tube } from "../../core";+import { CX, CY, FW, FW_H, FW_T, HW, HW_H, HW_T, REST, THORAX, cen, lerp, wingGeom } from "../geom";+import { PAPER_W } from "./world";+import { lift, mottle, wet } from "./paint";++const GROUND_BLUE = "#2e5f86";+export const blueprintSheet = (g: Gfx, at: P, w: number, seed = 6000) => {+ const c = g.cur, h = w * 0.72, r = rng(seed);+ /* the sheet lies in the grass, so it is a parallelogram with a lifted near corner */+ const quad: P[] = [[at[0] - w * 0.5, at[1] - h * 0.34], [at[0] + w * 0.52, at[1] - h * 0.46], [at[0] + w * 0.46, at[1] + h * 0.4], [at[0] - w * 0.56, at[1] + h * 0.5]];+ wet(g, jitter(quad, w * 0.012, seed), GROUND_BLUE, { alpha: 0.62, seed, shrink: 0.985, rim: true, dx: 2, dy: 2 });+ mottle(g, quad, GROUND_BLUE, seed + 3, 3, 0.12);+ const grid = 5; c.save(); g.path(c, quad); c.clip();+ for (let i = 1; i < grid; i++) { const a = lerp(quad[0], quad[3], i / grid), b = lerp(quad[1], quad[2], i / grid); g.fill(tube([a, b], w * 0.004, w * 0.004, false), "#9fc4dd", 0.3); const p = lerp(quad[0], quad[1], i / grid), q = lerp(quad[3], quad[2], i / grid); g.fill(tube([p, q], w * 0.004, w * 0.004, false), "#9fc4dd", 0.3); }+ c.restore();+ /* the blank: the creature's own silhouette, lifted clean out of the plate */+ const sc = (w / 1080) * 1.5, T = (p: P): P => [at[0] + (p[0] - CX) * sc * 0.92, at[1] + (p[1] - CY) * sc * 0.5];+ const wings = [wingGeom(-1, HW, HW_H, HW_T, 2000, REST), wingGeom(1, HW, HW_H, HW_T, 2600, REST), wingGeom(-1, FW, FW_H, FW_T, 1000, REST), wingGeom(1, FW, FW_H, FW_T, 1600, REST)];+ wings.forEach((wg, i) => lift(g, wg.out.map(T), seed + 20 + i, 0.92));+ lift(g, THORAX.map(T), seed + 30, 0.92);+ const abd: P[] = []; for (let i = 0; i <= 6; i++) { const t = i / 6, y = 70 + 170 * t, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push(T([CX + hw, CY + y])); } for (let i = 6; i >= 0; i--) { const t = i / 6, y = 70 + 170 * t, hw = 23 * (1 - t) ** 0.8 + 6.5; abd.push(T([CX - hw, CY + y])); }+ lift(g, abd, seed + 32, 0.92);+ /* the key, lying on top of it: it does not need winding any more */+ const k: P = [at[0] + w * 0.3, at[1] + h * 0.16], kw = w * 0.055;+ g.fill(tube([[k[0] - kw * 2.2, k[1] + kw * 0.6], [k[0] + kw * 1.4, k[1] - kw * 0.4]], kw * 0.42, kw * 0.42, false), "#d8dfe4", 0.9);+ [-1, 1].forEach((sd) => { const b = jitter(oval(k[0] + kw * (1.9 + sd * 0.9), k[1] - kw * (0.5 + sd * 0.25), kw * 0.8, kw * 0.58, 10), kw * 0.06, seed + 40 + sd); g.fill(b, "#d8dfe4", 0.9); g.fill(oval(k[0] + kw * (1.9 + sd * 0.9), k[1] - kw * (0.5 + sd * 0.25), kw * 0.34, kw * 0.24, 8), "#8fa8b8", 0.8); });+ g.fill(oval(k[0] - kw * 0.4, k[1] + kw * 1.1, kw * 2.4, kw * 0.5, 10), "#5e7f52", 0.2); /* its shadow in the grass */+};diff --git a/example/src/canvas-core/butterfly/finale/signature.ts b/example/src/canvas-core/butterfly/finale/signature.tsnew file mode 100644index 0000000..596a12a--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/signature.ts@@ -0,0 +1,51 @@+// THE SIGNATURE. `alexgreenshpun.com`, written the way a watercolourist signs a corner: a rigger+// brush in a dilute warm grey, five connected strokes and two marks, not a font and not the+// drafting capitals. Control points only. It is a URL first, so it has to stay legible.+import { Gfx, P, tube } from "../../core";+import { SIG } from "./world";+import { backrun, lift } from "./paint";++// authored in em units: baseline y = 0, x-height = 1, ascenders about 1.7, descenders about -0.8+const ALEX: P[] = [[0.62, 0.02], [0.34, 0.06], [0.12, 0.42], [0.2, 0.86], [0.46, 0.95], [0.63, 0.62], [0.6, 0.06], [0.72, 0.02], [0.86, 0.3],+ [0.98, 1.05], [1.06, 1.62], [1.12, 0.9], [1.1, 0.24], [1.22, 0.04], [1.4, 0.22],+ [1.52, 0.5], [1.72, 0.66], [1.78, 0.48], [1.62, 0.3], [1.46, 0.36], [1.44, 0.14], [1.6, 0.02], [1.8, 0.16],+ [2.02, 0.06], [2.38, 0.82], [2.5, 0.96], [2.62, 0.72], [2.78, 0.12]];+const XBAR: P[] = [[2.06, 0.78], [2.3, 0.5], [2.56, 0.2], [2.8, 0.04]];+const GREEN: P[] = [[3.0, 0.72], [2.88, 0.36], [3.0, 0.06], [3.22, 0.1], [3.3, 0.5], [3.28, 0.02], [3.24, -0.5], [3.06, -0.74], [2.92, -0.6],+ [3.42, 0.08], [3.5, 0.6], [3.54, 0.26], [3.7, 0.52], [3.86, 0.44],+ [3.98, 0.52], [4.14, 0.62], [4.2, 0.4], [4.04, 0.24], [3.94, 0.36], [3.98, 0.08], [4.2, 0.04], [4.36, 0.2],+ [4.46, 0.56], [4.62, 0.64], [4.68, 0.42], [4.52, 0.26], [4.42, 0.38], [4.46, 0.08], [4.68, 0.04], [4.86, 0.22],+ [4.94, 0.66], [4.96, 0.1], [5.02, 0.48], [5.2, 0.66], [5.36, 0.5], [5.38, 0.06]];+const SHPUN: P[] = [[5.66, 0.58], [5.56, 0.7], [5.4, 0.6], [5.5, 0.4], [5.7, 0.3], [5.76, 0.12], [5.6, 0.02], [5.46, 0.12],+ [5.96, 0.1], [6.0, 0.9], [6.04, 1.66], [6.06, 0.72], [6.1, 0.1], [6.22, 0.5], [6.4, 0.66], [6.54, 0.48], [6.56, 0.06],+ [6.86, 0.66], [6.8, 0.1], [6.76, -0.46], [6.72, -0.76], [6.88, 0.52], [7.06, 0.66], [7.22, 0.5], [7.24, 0.2], [7.1, 0.04], [6.94, 0.14],+ [7.5, 0.64], [7.46, 0.2], [7.56, 0.06], [7.74, 0.16], [7.82, 0.62], [7.86, 0.08],+ [8.02, 0.62], [8.04, 0.08], [8.1, 0.46], [8.28, 0.64], [8.44, 0.48], [8.46, 0.06]];+const COM: P[] = [[9.06, 0.54], [8.92, 0.66], [8.74, 0.56], [8.7, 0.26], [8.82, 0.06], [9.0, 0.12],+ [9.2, 0.5], [9.36, 0.64], [9.52, 0.5], [9.54, 0.22], [9.4, 0.06], [9.22, 0.16], [9.2, 0.46],+ [9.72, 0.62], [9.74, 0.08], [9.8, 0.46], [9.96, 0.62], [10.08, 0.46], [10.1, 0.08], [10.16, 0.46], [10.32, 0.62], [10.44, 0.46], [10.46, 0.06]];+const DOT: P = [8.62, 0.06];+const STROKES: [P[], number][] = [[ALEX, 0], [XBAR, 1], [GREEN, 2], [SHPUN, 3], [COM, 4]];++// right edge of the last letter at x = 1036, baseline at y = 1034, x-height 12 px, and the+// baseline rises two degrees to the right the way a hand does+export const signature = (g: Gfx, p = 1, alpha = 0.75) => {+ if (p <= 0) return;+ const em = 15.5, W = 212, k = W / 10.5, x0 = 1036 - W, y0 = 1032, rise = Math.tan((-2 * Math.PI) / 180);+ const T = ([x, y]: P): P => [x0 + x * k, y0 - y * em + (x * k) * rise];+ const each = 1 / STROKES.length;+ STROKES.forEach(([pts, i]) => {+ const q = Math.max(0, Math.min(1, (p - i * each) / each)); if (q <= 0) return;+ const n = Math.max(2, Math.round(pts.length * q)), s = pts.slice(0, n).map(T);+ g.fill(tube(s, 2.7, 1.5, false), SIG, alpha); /* a rigger: it starts loaded and runs thin */+ if (q >= 1) g.fill([[s[s.length - 1][0] - 1.4, s[s.length - 1][1] - 1.4], [s[s.length - 1][0] + 1.6, s[s.length - 1][1] - 1], [s[s.length - 1][0] + 1.2, s[s.length - 1][1] + 1.6], [s[s.length - 1][0] - 1.6, s[s.length - 1][1] + 1.2]], SIG, alpha * 0.9); /* pigment pools where the brush leaves the paper */+ });+ if (p > 0.72) { const d = T(DOT); g.fill([[d[0] - 1.6, d[1] - 1.6], [d[0] + 1.8, d[1] - 1.3], [d[0] + 1.5, d[1] + 1.7], [d[0] - 1.7, d[1] + 1.4]], SIG, alpha); }+};+// before signing over a dark passage a painter lifts the corner with a clean damp brush+export const clearCorner = (g: Gfx, p = 1) => {+ if (p <= 0) return;+ const pts: P[] = [[836, 1000], [1060, 994], [1064, 1052], [832, 1058]];+ lift(g, pts, 5900, 0.45 * p);+ if (p >= 1) backrun(g, [1046, 1044], 26, 5910, "#b8ab96", 0.16);+};diff --git a/example/src/canvas-core/butterfly/finale/world.ts b/example/src/canvas-core/butterfly/finale/world.tsnew file mode 100644index 0000000..4f9da9c--- /dev/null+++ b/example/src/canvas-core/butterfly/finale/world.ts@@ -0,0 +1,38 @@+// THE MEADOW, AS A WORLD. Positions are written as they appear on the LAST frame of the film,+// which makes the spec's table readable, and everything earlier is that world seen from closer+// in. A plane at depth z is magnified about the camera's look-at point by (Dend + z)/(D + z):+// near things swell fast as the camera comes in, the hills hardly move at all. One dolly, one+// number, and the parallax is true for every element at once.+import { P } from "../../core";++export const DEND = 1; // the dolly distance on the last frame; the hero plane is 1:1 there+export type Plane = { id: string; z: number };+export const PLANES: Plane[] = [+ { id: "fringe", z: -0.2 }, /* grass across the lens, huge and soft at the open */+ { id: "hero", z: 0 }, /* the flower it is on, and the blueprint sheet */+ { id: "hero2", z: 0.3 },+ { id: "p2", z: 1.0 }, { id: "p3", z: 2.2 }, { id: "p4", z: 3.5 },+ { id: "far", z: 8 }, /* the far field: colour, no plants */+ { id: "hills", z: 20 },+ { id: "sky", z: 1e6 }, /* no parallax at all */+];+export const zOf = (id: string) => PLANES.find((p) => p.id === id)?.z ?? 0;++export type Cam = { D: number; look: P };+export const scaleAt = (c: Cam, z: number) => (DEND + z) / (c.D + z);+export const project = (c: Cam, z: number, p: P): P => { const k = scaleAt(c, z); return [540 + (p[0] - c.look[0]) * k, 540 + (p[1] - c.look[1]) * k]; };+export const projector = (c: Cam, z: number) => { const k = scaleAt(c, z); return { k, at: (p: P): P => [540 + (p[0] - c.look[0]) * k, 540 + (p[1] - c.look[1]) * k] }; };++// ---------------------------------------------------------------- the paint box+export const SKY_TOP = "#a6c6e4", SKY_LOW = "#f4e7d0", SUN = "#f7dd9a", CLOUD_SHADE = "#c8c9dd";+export const HILL_FAR = "#aec2c4", HILL_NEAR = "#94ad9b", TREE = "#5f7e69";+export const FIELD_LIT = "#cbd485", FIELD_MID = "#a8bd6f", FIELD_COOL = "#7f9d78";+export const GRASS_LIT = "#ccd677", GRASS_MID = "#94b155", GRASS_SHADE = "#5e7f52", PATH = "#e9dfc2";+export const DAISY = "#fbf7ee", DAISY_SHADE = "#e8ddc4", POPPY = "#e2452b", POPPY_DARK = "#8d2a20";+export const CORNFLOWER = "#5b7fc7", COSMOS = "#ef9ab8", BUTTERCUP = "#f5c93f", STEM = "#8aa35f";+export const ROSE = "#e9a3ad", PEACH = "#f5b98a", BUTTER = "#f3d577", DENIM = "#6f93c4", INK_P = "#4a4a52";+export const PAPER_W = "#fbf7ee", SIG = "#5b5148";++// where the light is: upper right, so everything has a lit side and a shadow to its lower left+export const SUN_AT: P = [830, 150];+export const HORIZON = 410; // world y where hills meet sky on the last framediff --git a/example/src/canvas-core/butterfly/geom.ts b/example/src/canvas-core/butterfly/geom.tsnew file mode 100644index 0000000..816cb1e--- /dev/null+++ b/example/src/canvas-core/butterfly/geom.ts@@ -0,0 +1,47 @@+// PLATE GEOMETRY. The authored control points of MECHANICAL LEPIDOPTERA, and the pose that+// moves them. Nothing here draws. A pose transforms CONTROL POINTS only (spec 6.4), so line+// weight never changes when a wing foreshortens.+import { P, jitter } from "../core";++export const WHITE = "#f1f7fb", CYAN = "#a7d8ec", DIM = "#7fbcd8", GROUND = "#123a63";+export const CX = 540, CY = 418, K = 0.9;+export const FW: P[] = [[26, -52], [120, -132], [232, -216], [332, -272], [402, -286], [430, -250], [434, -190], [412, -120], [374, -60], [300, -18], [200, 2], [100, -6], [30, -20]];+export const HW: P[] = [[24, 2], [100, 22], [220, 30], [322, 62], [362, 122], [352, 192], [304, 252], [236, 292], [204, 342], [172, 302], [122, 262], [72, 182], [36, 92]];+export const FW_H: P = [28, -38], HW_H: P = [26, 14];+export const FW_T: P[] = [[402, -286], [433, -222], [424, -150], [392, -86], [318, -26], [208, 1]], HW_T: P[] = [[322, 62], [362, 150], [330, 226], [236, 292], [204, 342], [122, 262], [60, 150]];+export const lerp = (a: P, b: P, t: number): P => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];+export const cen = (pts: P[]): P => [pts.reduce((a, p) => a + p[0], 0) / pts.length, pts.reduce((a, p) => a + p[1], 0) / pts.length];++// A wing pose. flap 1 = spread flat on the sheet (the approved plate), 0.35 = raised and+// foreshortened; sweep = the in-plane rotation the plate dimensions as "57o SWEEP", radians.+export type Pose = { flap: number; sweep: number };+export const REST: Pose = { flap: 1, sweep: 0 };+export const posed = (pose: Pose): boolean => pose.flap !== 1 || pose.sweep !== 0;+const SPAN = 420 * K, RISE = 44; // a raised wing also rides UP the sheet a little: the tip is nearer the eye++export type Wing = { h: P; ends: P[]; out: P[]; panels: P[][]; spar: (i: number, t: number) => P; sparLine: (i: number, a?: number, b?: number, n?: number) => P[] };+export const wingGeom = (side: number, outline: P[], hinge: P, tips: P[], seed: number, pose: Pose = REST): Wing => {+ const place = (pts: P[]): P[] => jitter(pts, 1.6, seed).map(([x, y]) => [CX + side * x * K, CY + y * K] as P); /* each side is placed by hand, so the two never quite match */+ const h = place([hinge])[0];+ const move = (pts: P[]): P[] => {+ if (!posed(pose)) return pts;+ const c = Math.cos(side * pose.sweep), s = Math.sin(side * pose.sweep);+ return pts.map(([x0, y0]) => {+ const rx = pose.sweep ? h[0] + (x0 - h[0]) * c - (y0 - h[1]) * s : x0, ry = pose.sweep ? h[1] + (x0 - h[0]) * s + (y0 - h[1]) * c : y0;+ return [h[0] + (rx - h[0]) * pose.flap, ry - (1 - pose.flap) * RISE * Math.min(1, Math.abs(rx - h[0]) / SPAN)] as P; /* foreshorten about the hinge, lift with the tip */+ });+ };+ const out = move(place(outline)), ends = move(place(tips));+ const spar = (i: number, t: number): P => { const e = ends[i], m = lerp(h, e, 0.5), nx = -(e[1] - h[1]), ny = e[0] - h[0], l = Math.hypot(nx, ny) || 1, bow = (i === 0 ? -22 : 5 - i * 2.4) * side * K, b: P = [m[0] + (nx / l) * bow, m[1] + (ny / l) * bow]; return lerp(lerp(h, b, t), lerp(b, e, t), t); };+ const sparLine = (i: number, a = 0, b = 1, n = 7): P[] => Array.from({ length: n }, (_, k) => spar(i, a + ((b - a) * k) / (n - 1)));+ const panels = ends.slice(0, -1).map((_, i) => { const raw = [spar(i, 0.16), spar(i, 0.55), spar(i, 0.97), lerp(lerp(ends[i], ends[i + 1], 0.5), cen(out), -0.04), spar(i + 1, 0.97), spar(i + 1, 0.55), spar(i + 1, 0.16)], c0 = cen(raw); return raw.map((p) => lerp(p, c0, 0.075)); });+ return { h, ends, out, panels, spar, sparLine };+};++// the body, drawn in sheet space: thorax, head, the broken-out window, the key's centre+export const B = (pts: P[], seed: number): P[] => jitter(pts, 1.1, seed).map(([x, y]) => [CX + x * K, CY + y * K] as P);+export const THORAX = B([[0, -92], [30, -84], [48, -52], [52, -8], [44, 36], [24, 62], [0, 70], [-24, 62], [-45, 34], [-52, -10], [-47, -54], [-28, -85]], 31);+export const HEAD = B([[0, -130], [16, -124], [23, -109], [15, -95], [0, -91], [-15, -96], [-23, -110], [-14, -125]], 32);+export const WINDOW = B([[-30, -62], [-8, -72], [10, -66], [32, -50], [40, -8], [30, 30], [8, 36], [-6, 44], [-32, 26], [-40, -18]], 33);+export const KC: P = [CX, CY + 322 * K]; // the key at rest, withdrawn on the centre line+export const SPINDLE: P = [CX, CY + 262 * K]; // the squared end of the winding spindle it slides ontodiff --git a/example/src/canvas-core/butterfly/kit.ts b/example/src/canvas-core/butterfly/kit.tsnew file mode 100644index 0000000..2de29d1--- /dev/null+++ b/example/src/canvas-core/butterfly/kit.ts@@ -0,0 +1,54 @@+// THE DRAFTSMAN'S KIT. Every mark on the plate is made with one of these: a ruling pen that is+// never quite straight, a swung ring, section lines that start and stop inside the part, stipple,+// a gear, a leader with its arrow, a balloon. Bound to one Gfx target, so the same kit draws on+// the main canvas or into a cached layer without knowing the difference.+import { Ctx, Gfx, Medium, P, arc, jitter, line, oval, poly, rng } from "../core";+import { letter, width } from "../drafting";+import { bounds, inside } from "../riso";+import { CYAN, DIM, WHITE, lerp } from "./geom";++export const DRAFT: Medium = { nib: 1, taper: 0.6, pressure: 0.75, retrace: false, wobble: 0.5, rough: 0.55 }; // a ruling pen in a human hand+export type PenO = { color?: string; seed?: number; opacity?: number; closed?: boolean; taper?: number; wobble?: number; progress?: number };+export type Kit = ReturnType<typeof kit>;++// boil: 0 for everything the draftsman has already inked (spec 4: furniture is dead still).+// tint: the shadow pass paints the same linework in one flat colour (spec S11).+export const kit = (g: Gfx, o: { boil?: number; tint?: string | null } = {}) => {+ const boil = o.boil ?? 0, tint = o.tint ?? null, col = (c?: string) => tint ?? c ?? WHITE;+ const ink = (fn: () => void) => g.inkGroup(fn, { blur: 1.8, alpha: 0.28, textures: ["draftTooth"] }); // a faint halo under the line: white ink on blue always blooms a little+ const pen = (pts: P[], w: number, p: PenO = {}) => g.pen(pts, { w, color: col(p.color), seed: p.seed ?? 1, opacity: p.opacity ?? 0.95, closed: p.closed, taper: p.taper ?? 0.6, wobble: p.wobble ?? 0.5, boil, progress: p.progress });+ const ln = (a: P, b: P, w: number, p: PenO = {}) => pen(line(a, b, ((p.seed ?? 1) % 3) - 1), w, p); // nobody rules a dead straight line freehand+ const dash = (a: P, b: P, on: number, off: number, w: number, p: PenO = {}) => { const L = Math.hypot(b[0] - a[0], b[1] - a[1]); for (let d = 0, i = 0; d < L; d += on + off, i++) ln(lerp(a, b, d / L), lerp(a, b, Math.min(1, (d + on) / L)), w, { ...p, seed: (p.seed ?? 1) + i, taper: 0.3 }); };+ const chain = (a: P, b: P, w: number, p: PenO = {}) => { const L = Math.hypot(b[0] - a[0], b[1] - a[1]); for (let d = 0, i = 0; d < L; d += 40, i++) { ln(lerp(a, b, d / L), lerp(a, b, Math.min(1, (d + 24) / L)), w, { ...p, seed: (p.seed ?? 1) + i * 2, taper: 0.3 }); if (d + 35 < L) ln(lerp(a, b, (d + 30) / L), lerp(a, b, (d + 35) / L), w, { ...p, seed: (p.seed ?? 1) + i * 2 + 1, taper: 0.2 }); } };+ const arrow = (tip: P, ang: number, size = 13, color = WHITE) => g.fill([tip, [tip[0] - Math.cos(ang - 0.17) * size, tip[1] - Math.sin(ang - 0.17) * size], [tip[0] - Math.cos(ang) * size * 0.82, tip[1] - Math.sin(ang) * size * 0.82], [tip[0] - Math.cos(ang + 0.17) * size, tip[1] - Math.sin(ang + 0.17) * size]], col(color), 0.95);+ const fill = (pts: P[], color: string, alpha = 1) => g.fill(pts, tint ?? color, alpha);+ const ring = (cx: number, cy: number, r: number, w: number, seed: number, p: PenO = {}) => pen(jitter(oval(cx, cy, r, r * (0.96 + (seed % 5) * 0.015), 12, -1.9 + seed), r * 0.035, seed), w, { ...p, seed, closed: true, taper: 0.4 }); // hand-swung, never a true circle+ // section lines / cross-hatch: parallel strokes that start and stop inside the part+ const hatch = (pts: P[], ang: number, gap: number, w: number, seed: number, p: { color?: string; opacity?: number; progress?: number } = {}) => {+ const c = Math.cos(ang), s = Math.sin(ang), r = rng(seed), proj = pts.map(([x, y]) => -s * x + c * y), lo = Math.min(...proj), hi = Math.max(...proj), segs: [P, P, number][] = [];+ for (let off = lo + gap * 0.5, n = 0; off < hi; off += gap * (0.86 + r() * 0.28), n++) {+ const ox = -s * off, oy = c * off, ts: number[] = [];+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const a = pts[j], b = pts[i], ex = b[0] - a[0], ey = b[1] - a[1], den = c * ey - s * ex; if (Math.abs(den) < 1e-9) continue; const t = ((a[0] - ox) * ey - (a[1] - oy) * ex) / den, u = ((a[0] - ox) * s - (a[1] - oy) * c) / den; if (u >= 0 && u < 1) ts.push(t); }+ ts.sort((a, b) => a - b);+ for (let k = 0; k + 1 < ts.length; k += 2) { const t0 = ts[k] + r() * 2.5, t1 = ts[k + 1] - r() * 2.5; if (t1 - t0 < 3) continue; segs.push([[ox + c * t0, oy + s * t0], [ox + c * t1, oy + s * t1], seed + n * 7 + k]); }+ }+ const vis = (p.progress ?? 1) * segs.length; /* section lines run on one stroke at a time, the last one half made */+ segs.forEach(([a, b, sd], i) => { const q = Math.min(1, vis - i); if (q > 0) ln(a, b, w, { seed: sd, color: p.color ?? CYAN, opacity: p.opacity ?? 0.8, taper: 0.7, progress: q }); });+ };+ const stipple = (pts: P[], n: number, seed: number, dens: (x: number, y: number) => number, color = WHITE) => { const b = bounds(pts), r = rng(seed), c = g.cur; g.touch(b.x0, b.y0, b.x1, b.y1); c.fillStyle = col(color); for (let i = 0; i < n; i++) { const x = b.x0 + r() * (b.x1 - b.x0), y = b.y0 + r() * (b.y1 - b.y0); if (!inside(pts, x, y) || r() > dens(x, y)) continue; c.globalAlpha = 0.6 + r() * 0.35; c.beginPath(); c.ellipse(x, y, 0.7 + r() * 0.7, 0.6 + r() * 0.5, r() * 3, 0, Math.PI * 2); c.fill(); } c.globalAlpha = 1; };+ const gearPts = (cx: number, cy: number, rp: number, teeth: number, ph: number, seed: number, spike = false): P[] => { const r = rng(seed), out: P[] = [], add = rp * (spike ? 0.24 : 0.13), ded = rp * 0.13; for (let i = 0; i < teeth; i++) { const a = ph + (i / teeth) * Math.PI * 2, st = (Math.PI * 2) / teeth, q = (da: number, rr: number): P => [cx + Math.cos(a + da * st) * (rr + (r() - 0.5) * 0.7), cy + Math.sin(a + da * st) * (rr + (r() - 0.5) * 0.7)]; if (spike) out.push(q(0, rp - ded), q(0.62, rp - ded), q(0.92, rp + add)); else out.push(q(0, rp - ded), q(0.16, rp - ded), q(0.3, rp + add), q(0.56, rp + add), q(0.7, rp - ded)); } return out; };+ const gear = (cx: number, cy: number, rp: number, teeth: number, ph: number, seed: number, p: { spokes?: number; spike?: boolean; w?: number; progress?: number } = {}) => {+ const q = p.progress ?? 1; if (q <= 0) return;+ const n = 4 + (p.spokes ?? 5), st = (i: number) => (q >= 1 ? 1 : Math.max(0, Math.min(1, q * n - i))); /* rim, then the hub rings, then the spokes: a wheel is drawn from the outside in */+ pen(poly(gearPts(cx, cy, rp, teeth, ph, seed, p.spike), 2), p.w ?? 1.9, { seed, closed: true, taper: 0.3, wobble: 0.15, progress: st(0) });+ ring(cx, cy, rp * 0.74, 1.2, seed + 1, { color: CYAN, progress: st(1) }); ring(cx, cy, rp * 0.26, 1.6, seed + 2, { progress: st(2) }); ring(cx, cy, rp * 0.1, 1.3, seed + 3, { progress: st(3) });+ for (let i = 0; i < (p.spokes ?? 5); i++) { const a = ph + 0.3 + (i / (p.spokes ?? 5)) * Math.PI * 2, nn = a + Math.PI / 2, wv = rp * 0.06, sq = st(4 + i); [-1, 1].forEach((sd) => ln([cx + Math.cos(a) * rp * 0.27 + Math.cos(nn) * wv * sd, cy + Math.sin(a) * rp * 0.27 + Math.sin(nn) * wv * sd], [cx + Math.cos(a) * rp * 0.73 + Math.cos(nn) * wv * 0.7 * sd, cy + Math.sin(a) * rp * 0.73 + Math.sin(nn) * wv * 0.7 * sd], 1.2, { seed: seed + 10 + i * 2 + sd, progress: sq })); }+ if (q >= 1) { ln([cx - rp * 0.2, cy], [cx + rp * 0.2, cy], 0.9, { color: DIM, seed: seed + 30 }); ln([cx, cy - rp * 0.2], [cx, cy + rp * 0.2], 0.9, { color: DIM, seed: seed + 31 }); } /* centre marks go on when the wheel is finished */+ };+ const spiral = (cx: number, cy: number, r0: number, r1: number, turns: number, ph = 0): P[] => Array.from({ length: Math.ceil(turns * 14) + 1 }, (_, i) => { const t = i / (turns * 14), a = ph + t * turns * Math.PI * 2, rr = r0 + (r1 - r0) * t; return [cx + Math.cos(a) * rr, cy + Math.sin(a) * rr * 0.97] as P; });+ const text = (s: string, x: number, y: number, p: { cap?: number; color?: string; seed?: number; align?: "left" | "center" | "right"; w?: number; opacity?: number; progress?: number } = {}) => letter(g, s, x, y, { ...p, color: col(p.color ?? "#eef6fb") });+ const balloon = (n: string, at: P, to: P, seed: number, q = 1) => { if (q <= 0) return; const a = Math.atan2(to[1] - at[1], to[0] - at[0]), s3 = (i: number) => Math.min(1, Math.max(0, q * 3 - i)); ring(at[0], at[1], 13.5, 1.6, seed, { progress: s3(0) }); text(n, at[0] - 0.5, at[1] - 6.5, { cap: 13, align: "center", seed, w: 1.7, progress: s3(1) }); ln([at[0] + Math.cos(a) * 14, at[1] + Math.sin(a) * 14], to, 1.1, { seed: seed + 1, color: CYAN, progress: s3(2) }); if (q >= 1) fill(oval(to[0], to[1], 2.6, 2.6, 7), WHITE, 0.95); };+ const callout = (t: string, at: P, to: P, seed: number, align: "left" | "right" = "left", q = 1) => { if (q <= 0) return; const wd = width(t, 10.5), x0 = align === "left" ? at[0] : at[0] - wd, s3 = (i: number) => Math.min(1, Math.max(0, q * 3 - i)); /* the word first, then the rule under it, then the leader out to the part */ text(t, x0, at[1] - 11, { cap: 10.5, seed, color: WHITE, progress: s3(0) }); ln([x0 - 2, at[1] + 4], [x0 + wd + 2, at[1] + 4], 1, { seed: seed + 1, color: CYAN, progress: s3(1) }); ln(align === "left" ? [x0 - 2, at[1] + 4] : [x0 + wd + 2, at[1] + 4], to, 1, { seed: seed + 2, color: CYAN, progress: s3(2) }); if (q >= 1) arrow(to, Math.atan2(to[1] - at[1] - 4, to[0] - (align === "left" ? x0 - 2 : x0 + wd + 2)), 10, CYAN); };+ const raw = (): Ctx => g.cur;+ return { g, ink, pen, ln, dash, chain, arrow, fill, ring, hatch, stipple, gear, spiral, text, balloon, callout, raw, arc, poly, oval, jitter, rng, tint };+};diff --git a/example/src/canvas-core/butterfly/linkage.ts b/example/src/canvas-core/butterfly/linkage.tsnew file mode 100644index 0000000..e04e0e2--- /dev/null+++ b/example/src/canvas-core/butterfly/linkage.ts@@ -0,0 +1,28 @@+// THE LINKAGE. What actually drives the wings, and the reason Act 3 can be honest: a CRANK on+// the centre-wheel arbor, a CONNECTING ROD, and a rocking BELL-CRANK at each wing root that+// lifts the leading spar. `flap` is computed FROM the bell-crank angle, which is computed from+// the crank angle, so a rod and a wing can never disagree on screen.+import { P } from "../core";+import { CX, CY, THORAX, cen } from "./geom";++const O = cen(THORAX);+export const ARBOR: P = [O[0] + 2, O[1] + 4]; // the centre wheel's arbor, the same one Act 1 and 2 draw+export const RC = 17, ARM = 26, ROD = 58, OUT = 21, LAG = (8 * Math.PI) / 180; // crank throw, input arm, rod, output arm, and the starboard side's lag in crank angle+export const pivot = (side: number): P => [CX + side * 44, CY - 52]; // the bell-crank pivot, just inboard of the forewing hinge+export const crankPin = (th: number): P => [ARBOR[0] + Math.cos(th) * RC, ARBOR[1] + Math.sin(th) * RC];++// the bell-crank angle that puts the rod's far end exactly ROD from the crank pin+export const bellAngle = (side: number, th: number): number => {+ const P0 = crankPin(th - (side > 0 ? LAG : 0)), Q = pivot(side), dx = P0[0] - Q[0], dy = P0[1] - Q[1], d = Math.hypot(dx, dy) || 1;+ const c = Math.max(-1, Math.min(1, (ARM * ARM + d * d - ROD * ROD) / (2 * ARM * d)));+ return Math.atan2(dy, dx) + side * Math.acos(c); /* one branch per side, so the two arms mirror */+};+export const armEnd = (side: number, th: number): P => { const a = bellAngle(side, th), Q = pivot(side); return [Q[0] + Math.cos(a) * ARM, Q[1] + Math.sin(a) * ARM]; };+export const outEnd = (side: number, th: number): P => { const a = bellAngle(side, th) + side * Math.PI * 0.62, Q = pivot(side); return [Q[0] + Math.cos(a) * OUT, Q[1] + Math.sin(a) * OUT]; }; /* the arm that actually lifts the spar */++// the swing of the bell-crank over one revolution, measured once, so flap can be mapped onto it+const swing = (side: number) => { let lo = 1e9, hi = -1e9; for (let i = 0; i < 360; i++) { const a = bellAngle(side, (i / 360) * Math.PI * 2); lo = Math.min(lo, a); hi = Math.max(hi, a); } return [lo, hi] as const; };+const SW = [swing(-1), swing(1)];+export const flapOf = (side: number, th: number): number => { const [lo, hi] = SW[side > 0 ? 1 : 0], a = bellAngle(side, th), t = (a - lo) / (hi - lo || 1); return 1 - 0.62 * (side > 0 ? 1 - t : t); };+// the crank angle whose flap is closest to a wanted one: how Act 3 starts on Act 2's last pose+export const crankFor = (flap: number): number => { let best = 0, bd = 9; for (let i = 0; i < 720; i++) { const th = (i / 720) * Math.PI * 2, d = Math.abs(flapOf(-1, th) - flap); if (d < bd) { bd = d; best = th; } } return best; };diff --git a/example/src/canvas-core/butterfly/parts.ts b/example/src/canvas-core/butterfly/parts.tsnew file mode 100644index 0000000..39cd873--- /dev/null+++ b/example/src/canvas-core/butterfly/parts.ts@@ -0,0 +1,257 @@+// THE PARTS OF THE PLATE. Each one draws with a Kit onto whatever target that Kit is bound to,+// and takes only the state it needs. Nothing here knows about caching, films or frames.+import { P, oval, poly, sample } from "../core";+import { width } from "../drafting";+import { B, CX, CY, CYAN, DIM, GROUND, HEAD, K, KC, THORAX, WHITE, WINDOW, Wing, cen, lerp } from "./geom";+import { Kit, PenO } from "./kit";++// element i of a run of n, drawn in order, each taking `dur` of the whole: the hand works+// down the part, it does not fade things up together.+export const stagger = (p: number, n: number, dur = Math.min(1, 2 / n)) => { const step = n > 1 ? (1 - dur) / (n - 1) : 0; return (i: number) => (p >= 1 ? 1 : Math.max(0, Math.min(1, (p - i * step) / dur))); };+// WHERE THE NIB IS. `progress` cuts a stroke on sample INDEX, and samples are not evenly+// spaced in arc length, so a fitting gated on cue progress can appear on bare paper ahead of+// the line it belongs to. This measures the drawn fraction of the actual stroke, and where a+// point sits along it, both in arc length, so a knuckle or a rivet lands as the nib passes it.+export const nib = (pts: P[]) => {+ const s = sample(pts), acc = [0]; let total = 0;+ for (let i = 1; i < s.length; i++) { total += Math.hypot(s[i][0] - s[i - 1][0], s[i][1] - s[i - 1][1]); acc.push(total); }+ const L = total || 1;+ return {+ drawn: (q: number) => { if (q >= 1) return 1; const n = (s.length - 1) * q, i = Math.max(0, Math.min(s.length - 1, Math.floor(n))), f = n - i; return (acc[i] + (i + 1 < s.length ? (acc[i + 1] - acc[i]) * f : 0)) / L; },+ where: (t: P) => { let best = 0, bd = 1e9; for (let i = 0; i < s.length; i++) { const d = (s[i][0] - t[0]) ** 2 + (s[i][1] - t[1]) ** 2; if (d < bd) { bd = d; best = i; } } return acc[best] / L; },+ };+};+export const cut = (p: number, a: number, b: number) => (p >= 1 ? 1 : Math.max(0, Math.min(1, (p - a) / (b - a))));++export type Train = { centre: number; third: number; pinion: number; escape: number; fork: number }; // radians added to the plate's authored phases+export const IDLE: Train = { centre: 0, third: 0, pinion: 0, escape: 0, fork: 0 };++// ---------------------------------------------------------------- the sheet+export const sheet = (k: Kit, W: number, H: number) => {+ const c = k.g.main, e = k.g.env, dw = Math.round(W * e.scale), dh = Math.round(H * e.scale);+ c.save(); c.setTransform(1, 0, 0, 1, 0, 0); c.fillStyle = GROUND; c.fillRect(0, 0, dw, dh); c.restore(); /* the ground fills the FRAME, whatever the camera is doing */+ const glow = c.createRadialGradient(W * 0.5, H * 0.44, 60, W * 0.5, H * 0.5, W * 0.78); glow.addColorStop(0, "rgba(58,120,178,0.34)"); glow.addColorStop(0.55, "rgba(30,84,140,0.1)"); glow.addColorStop(1, "rgba(4,16,36,0.5)"); c.fillStyle = glow; c.fillRect(-W, -H, W * 3, H * 3);+ k.g.paper("blueMottle", 0.55);+ /* two old fold lines: a plate that has lived in a drawer */+ [[W * 0.5 + 3, 0, W * 0.5 - 2, H], [0, H * 0.5 - 4, W, H * 0.5 + 2]].forEach(([x0, y0, x1, y1]) => { c.strokeStyle = "rgba(190,225,245,0.07)"; c.lineWidth = 2.4; c.beginPath(); c.moveTo(x0, y0); c.lineTo(x1, y1); c.stroke(); c.strokeStyle = "rgba(2,10,26,0.16)"; c.lineWidth = 1.2; c.beginPath(); c.moveTo(x0 + 2, y0 + 2); c.lineTo(x1 + 2, y1 + 2); c.stroke(); });+};+// The detail bubble goes on the thorax BEFORE the detail is drawn: a draftsman rings what he is+// about to magnify, and it is the circle the cut to Detail B matches (spec 7).+export const bubble = (k: Kit, p = 1) => { if (p <= 0) return; k.ink(() => { const tc = cen(THORAX); k.ring(tc[0], tc[1] - 6, 62, 1.5, 336, { color: CYAN, opacity: 0.95, progress: cut(p, 0, 0.7) }); /* the circle the cut matches: it has to carry the frame, so it is rung with a confident line */ k.text("B", tc[0] + 50, tc[1] - 70, { cap: 14, seed: 337, w: 1.8, progress: cut(p, 0.6, 1) }); }); };+export const BUBBLE = (): [number, number, number] => { const tc = cen(THORAX); return [tc[0], tc[1] - 6, 62]; };++export const grid = (k: Kit, W: number, H: number, alpha = 1) => k.g.group("plain", () => { const c = k.raw(); c.globalAlpha = alpha; k.g.touch(0, 0, W, H); for (let i = 40; i < W - 30; i += 20) { const major = (i - 40) % 100 === 0; c.strokeStyle = major ? "rgba(150,208,236,0.2)" : "rgba(150,208,236,0.085)"; c.lineWidth = major ? 1 : 0.7; c.beginPath(); c.moveTo(i, 40); c.lineTo(i, H - 40); c.moveTo(40, i); c.lineTo(W - 40, i); c.stroke(); } c.globalAlpha = 1; }, { textures: ["draftTooth"] });+export const border = (k: Kit, W: number, H: number, p = 1) => { if (p <= 0) return; k.ink(() => {+ const q = stagger(cut(p, 0, 0.75), 8, 0.42); /* the sheet is ruled stroke by stroke, outer frame first, inner rule chasing it */+ [[22, 2.6], [34, 1.2]].forEach(([m, w], j) => [[[m, m], [W - m, m]], [[W - m, m], [W - m, H - m]], [[W - m, H - m], [m, H - m]], [[m, H - m], [m, m]]].forEach(([a, b], i) => k.ln(a as P, b as P, w, { seed: 900 + j * 4 + i, taper: 0.15, progress: q(i * 2 + j) })));+ const z = cut(p, 0.7, 1);+ ["A", "B", "C", "D"].forEach((t, i) => { const y = 34 + ((H - 68) * (i + 0.5)) / 4, qq = stagger(z, 8, 0.4)(i); k.text(t, 24.5, y - 4, { cap: 7, seed: 910 + i, color: CYAN, w: 1, progress: qq }); if (i) k.ln([22, 34 + ((H - 68) * i) / 4], [34, 34 + ((H - 68) * i) / 4], 1, { seed: 920 + i, progress: qq }); });+ ["1", "2", "3", "4"].forEach((t, i) => { const x = 34 + ((W - 68) * (i + 0.5)) / 4, qq = stagger(z, 8, 0.4)(i + 4); k.text(t, x, 24.5, { cap: 7, seed: 930 + i, color: CYAN, w: 1, align: "center", progress: qq }); if (i) k.ln([34 + ((W - 68) * i) / 4, 22], [34 + ((W - 68) * i) / 4, 34], 1, { seed: 940 + i, progress: qq }); });+}); };++// CONSTRUCTION. What the draftsman lays down before he inks: the centre line, the envelope each+// wing has to fit, the thorax ellipse. It is drawn in DIM, and later it is taken away the same+// way it arrived, by UN-drawing, because a construction line is erased and never faded.+export const construction = (k: Kit, w: { LF: Wing; RF: Wing; LH: Wing; RH: Wing }, p: number) => { if (p <= 0) return; k.ink(() => {+ const q = stagger(p, 7, 0.4), o: PenO = { color: DIM, opacity: 0.8, seed: 0 };+ k.chain([CX, CY - 300], [CX, CY + 380], 1, { ...o, seed: 960, progress: q(0) });+ [w.LF, w.RF, w.LH, w.RH].forEach((wg, i) => k.pen(wg.out, 1.2, { ...o, seed: 961 + i, closed: true, wobble: 1.6, progress: q(1 + i) }));+ k.pen(k.oval(CX, CY - 10, 58, 92, 12), 1.2, { ...o, seed: 966, closed: true, progress: q(5) });+ k.pen(k.oval(CX, CY - 100, 26, 22, 10), 1.1, { ...o, seed: 967, closed: true, progress: q(6) });+}); };++// ---------------------------------------------------------------- the wings+export type WingP = { skin: boolean; lift?: number; liftT?: number; line?: number; skinP?: number };+export const drawWing = (k: Kit, w: Wing, side: number, seed: number, o: WingP) => {+ const { h, ends, out, panels, spar, sparLine } = w, line = o.line ?? 1, skinP = o.skinP ?? 1;+ if (line <= 0 && skinP <= 0) return;+ // a membrane panel is a MADE part: it arrives whole along its projection lines, seats, and is+ // veined and then shaded afterwards, in that order+ const drawPanel = (pn: P[], i: number, dx = 0, dy = 0, q = 1) => {+ if (q <= 0) return;+ const p = pn.map(([x, y]) => [x + dx, y + dy] as P), base = lerp(p[0], p[6], 0.5), tip = p[3], c0 = cen(p);+ const vein = cut(q, 0.45, 0.8), tone = cut(q, 0.8, 1);+ k.fill(p, CYAN, 0.085); k.pen(p, 1.15, { seed: seed + 300 + i, closed: true, color: CYAN, wobble: 0.3 });+ if (vein <= 0) return;+ /* veining: a midrib that forks, and cross-veins running out to the panel's edges */+ const mid = (t: number): P => lerp(lerp(base, c0, t), lerp(c0, tip, t), t), vq = stagger(vein, 9, 0.45);+ k.pen([0, 0.25, 0.5, 0.75, 0.96].map(mid), 1.05, { seed: seed + 320 + i, color: WHITE, opacity: 0.85, progress: vq(0) });+ [0.28, 0.46, 0.64, 0.8].forEach((t, j) => [1, 5].forEach((e, r) => { const from = mid(t), to = lerp(lerp(p[e], p[e === 1 ? 2 : 4], t), from, 0.12); k.pen([from, lerp(lerp(from, to, 0.5), c0, -0.1), to], 0.8, { seed: seed + 340 + i * 9 + j * 2 + r, color: CYAN, opacity: 0.78, taper: 0.9, progress: vq(1 + j * 2 + r) }); }));+ if (tone > 0) k.hatch([p[6], p[5], p[4], lerp(p[4], c0, 0.34), lerp(p[5], c0, 0.3), lerp(p[6], c0, 0.3)], Math.atan2(p[4][1] - p[6][1], p[4][0] - p[6][0]) + 0.9, 4.6, 0.75, seed + 360 + i, { opacity: 0.6, progress: tone });+ };+ if (o.skin && skinP > 0) { const sq = stagger(skinP, panels.length, 0.5); panels.forEach((pn, i) => { if (i === o.lift) return; const a = cut(sq(i), 0, 0.45), f = 1 - a * a * (3 - 2 * a); drawPanel(pn, i, side * 58 * f, -60 * f, sq(i)); }); }+ if (line <= 0) return;+ const mq = cut(line, 0, 0.3), sq = stagger(cut(line, 0.2, 0.92), ends.length, 0.45), bq = cut(line, 0.85, 1);+ k.pen(out, 2.7, { seed: seed + 1, closed: true, wobble: 0.6, progress: mq }); /* the wing margin: the heaviest line on the wing, and the first */+ ends.forEach((_, i) => {+ const q = sq(i); if (q <= 0) return;+ const nrm = (t: number): P => { const a = spar(i, t - 0.02), b = spar(i, t + 0.02), l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1; return [-(b[1] - a[1]) / l, (b[0] - a[0]) / l]; }, tw = i === 0 ? 3.4 : 2.3;+ [-1, 1].forEach((sd) => k.pen(sparLine(i, 0.04, 0.985).map((p, j, arr) => { const t = 0.04 + (0.945 * j) / (arr.length - 1), n = nrm(Math.min(0.97, Math.max(0.03, t))), wv = tw * (1 - t * 0.55); return [p[0] + n[0] * wv * sd, p[1] + n[1] * wv * sd] as P; }), i === 0 ? 1.7 : 1.05, { seed: seed + 40 + i * 2 + sd, color: i === 0 ? WHITE : CYAN, opacity: i === 0 ? 0.95 : 0.85, progress: q })); /* a spar is a tapering TUBE: two lines, not one */+ const kn = spar(i, 0.44), n = nrm(0.44), nb = nib(sparLine(i, 0.04, 0.985)), tip = nb.drawn(q), hq = q >= 1 ? 1 : cut(tip - nb.where(kn), 0, 0.1); /* the knuckle rings on as the NIB passes it, not when the cue says so */+ if (hq > 0) { k.ring(kn[0], kn[1], 5.2, 1.5, seed + 60 + i, { progress: hq }); k.ring(kn[0], kn[1], 1.8, 1.1, seed + 70 + i, { progress: hq }); k.ln([kn[0] - n[0] * 8, kn[1] - n[1] * 8], [kn[0] + n[0] * 8, kn[1] + n[1] * 8], 1.1, { seed: seed + 80 + i, progress: hq }); }+ for (let j = 1; j <= (i === 0 ? 9 : 3); j++) { const t = i === 0 ? 0.08 + j * 0.095 : 0.2 + j * 0.2, p = spar(i, t), rq = q >= 1 ? 1 : cut(tip - nb.where(p), 0, 0.08); if (rq <= 0) continue; k.ring(p[0], p[1], 1.7, 0.9, seed + 100 + i * 12 + j, { color: WHITE, progress: rq }); } /* rivets, each one as the nib reaches it */+ if (i && bq > 0) [0.44, 0.74].forEach((t, j) => k.pen([spar(i - 1, t), lerp(lerp(spar(i - 1, t), spar(i, t), 0.5), h, -0.03), spar(i, t)], 1.15, { seed: seed + 200 + i * 2 + j, color: WHITE, opacity: 0.85, progress: stagger(bq, 2, 0.7)(j) })); /* cross-braces last */+ });+ const jq = cut(line, 0.1, 0.3);+ if (jq > 0) { k.ring(h[0], h[1], 8.5, 2, seed + 90, { progress: jq }); k.ring(h[0], h[1], 3.2, 1.4, seed + 91, { progress: jq }); if (jq >= 1) k.stipple(oval(h[0], h[1], 8, 8, 10), 60, seed + 92, () => 0.5); }+ if (o.skin && o.lift !== undefined && skinP > 0) { /* the lifted panel goes on last and is knocked out, so it reads as a plate floating above the wing */+ const t = o.liftT ?? 1, pn = panels[o.lift], dx = side * 58 * t, dy = -60 * t, up = pn.map(([x, y]) => [x + dx, y + dy] as P), lq = stagger(skinP, panels.length, 0.5)(o.lift);+ if (lq > 0) {+ if (t > 0.02) { k.pen(pn, 0.9, { seed: seed + 380, closed: true, color: DIM, opacity: 0.6, progress: lq }); k.fill(up.map((q) => lerp(q, cen(up), -0.04)), GROUND, 0.94); [0, 2, 4, 6].forEach((j) => k.dash(pn[j], up[j], 7, 5, 1, { seed: seed + 390 + j, color: CYAN, opacity: 0.9, progress: lq })); }+ drawPanel(pn, o.lift, dx, dy, lq); k.pen(up, 1.9, { seed: seed + 399, closed: true, wobble: 0.3, progress: lq });+ }+ }+};++// ---------------------------------------------------------------- body: abdomen, thorax, head+export const bodyMask = (k: Kit, on = true) => { if (!on) return; k.g.group("plain", () => { k.fill(THORAX, GROUND, 1); k.fill(HEAD, GROUND, 1); }); }; // the body sits OVER the wing roots+export const abdomen = (k: Kit, p = 1) => { if (p <= 0) return; k.ink(() => {+ const segs = 7, y0 = 70, y1 = 238, hw = (t: number) => 23 * (1 - t) ** 0.8 + 6.5;+ const edge = (sd: number): P[] => B(Array.from({ length: 15 }, (_, j) => { const t = j / 14; return [sd * (hw(t) + Math.sin(t * segs * Math.PI) * 1.6), y0 + (y1 - y0) * t] as P; }), 34 + sd);+ const L = edge(-1), R = edge(1), wq = cut(p, 0, 0.3), sq = stagger(cut(p, 0.22, 0.72), segs, 0.4), tq = cut(p, 0.6, 0.94), eq = cut(p, 0.9, 1);+ if (p >= 1) k.g.group("plain", () => k.fill([...L, ...[...R].reverse()], GROUND, 1)); else if (wq >= 1) k.g.group("plain", () => k.fill([...L, ...[...R].reverse()], GROUND, 1));+ k.pen(L, 2.4, { seed: 35, progress: wq }); k.pen(R, 2.8, { seed: 36, progress: wq }); /* both flanks run down from the thorax */+ for (let a = 1; a < segs; a++) { const q = sq(a - 1); if (q <= 0) continue; const t = a / segs, y = y0 + (y1 - y0) * t, w = hw(t); k.pen(B([[-w, y], [0, y + 5.5], [w, y]], 40 + a), 1.5, { seed: 40 + a, progress: q }); k.pen(B([[-w * 0.94, y + 4], [0, y + 9], [w * 0.94, y + 4]], 50 + a), 0.9, { seed: 50 + a, color: CYAN, opacity: 0.8, progress: q }); [-0.55, 0.55].forEach((r, j) => { const c0 = B([[w * r, y - 8]], 60 + a * 2 + j)[0]; k.ring(c0[0], c0[1], 1.8, 0.9, 60 + a * 2 + j, { progress: cut(q, 0.6, 1) }); }); } /* segments stack, rivets ripple after each */+ if (tq > 0) for (let a = 0; a < segs; a++) { const t0 = a / segs, t1 = (a + 1) / segs, ya = y0 + (y1 - y0) * t0 + 7, yb = y0 + (y1 - y0) * t1 + 1, q = stagger(tq, segs, 0.45)(a); if (q <= 0) continue; k.hatch(B([[hw(t0) * 0.34, ya], [hw(t0) * 0.98, ya], [hw(t1) * 0.98, yb], [hw(t1) * 0.34, yb + 3]], 70 + a), 0.78, 3.4, 0.75, 70 + a, { opacity: 0.7, progress: q }); if (a % 2 === 0) k.hatch(B([[hw(t0) * 0.62, ya], [hw(t0) * 0.98, ya], [hw(t1) * 0.98, yb], [hw(t1) * 0.62, yb + 3]], 80 + a), -0.78, 3.6, 0.7, 80 + a, { opacity: 0.6, progress: q }); }+ if (eq > 0) { const tip = B([[0, 238], [0, 262]], 90); [-1, 1].forEach((sd) => k.ln([tip[0][0] + sd * 3.4, tip[0][1] - 3], [tip[1][0] + sd * 2.6, tip[1][1]], 1.5, { seed: 91 + sd, progress: eq })); k.ln([tip[1][0] - 2.6, tip[1][1]], [tip[1][0] + 2.6, tip[1][1]], 1.4, { seed: 93, progress: cut(eq, 0.6, 1) }); } /* winding spindle, squared end */+}); };++// thorax housing, its opened window with the train running inside, head and antennae.+// One ink block, exactly as the approved plate draws it, so the halo matches.+export const thoraxShell = (k: Kit, p: { shell?: number; head?: number } = {}) => { const sp = p.shell ?? 1, hp = p.head ?? 1; if (sp <= 0 && hp <= 0) return; k.ink(() => {+ if (sp > 0) {+ const cq = cut(sp, 0, 0.28), wq = cut(sp, 0.22, 0.45), bq = cut(sp, 0.42, 0.66), tq = cut(sp, 0.62, 1);+ k.pen(THORAX, 3.1, { seed: 100, closed: true, progress: cq });+ const wall = THORAX.map((q, i) => lerp(q, cen(THORAX), 0.13 + (i % 3) * 0.006)); k.pen(wall, 1.2, { seed: 101, closed: true, color: CYAN, progress: wq });+ k.pen(WINDOW, 1.25, { seed: 102, closed: true, wobble: 2.4, progress: bq }); /* the break line is drawn freehand, on purpose, and slower than the rest */+ k.hatch([...THORAX.slice(2, 8), ...wall.slice(2, 8).reverse()], 0.78, 3.6, 0.85, 103, { opacity: 0.85, progress: stagger(tq, 2, 0.75)(0) }); k.hatch([...THORAX.slice(8), THORAX[0], wall[0], ...wall.slice(8).reverse()], 0.78, 3.6, 0.85, 104, { opacity: 0.6, progress: stagger(tq, 2, 0.75)(1) });+ }+ if (hp <= 0) return;+ /* head: compound eyes stippled, a hairspring proboscis, coiled-wire antennae ending in a flat spiral club */+ const hq = cut(hp, 0, 0.25), eq = cut(hp, 0.2, 0.45), pq = cut(hp, 0.4, 0.6), aq = cut(hp, 0.5, 1);+ k.pen(HEAD, 2.5, { seed: 150, closed: true, progress: hq });+ if (eq > 0) [-1, 1].forEach((sd) => { const e = B(k.oval(sd * 17, -112, 8.5, 12, 9), 151 + sd), q = stagger(eq, 2, 0.8)(sd < 0 ? 0 : 1); k.pen(e, 1.5, { seed: 152 + sd, closed: true, progress: q }); if (q >= 1) k.stipple(e, 150, 153 + sd, (x, y) => 0.25 + 0.6 * Math.max(0, (x - e[0][0]) / 20 + (y - e[0][1]) / 40)); });+ if (pq > 0) { const pr = B([[0, -146]], 155)[0]; k.pen(k.spiral(pr[0], pr[1], 1.5, 11.5, 3.2, 1.4), 1.2, { seed: 156, progress: pq }); k.ln([pr[0], pr[1] + 11], [pr[0], pr[1] + 17], 1.2, { seed: 157, progress: cut(pq, 0.7, 1) }); }+ if (aq > 0) [-1, 1].forEach((sd) => { const q = stagger(aq, 2, 0.85)(sd < 0 ? 0 : 1); if (q <= 0) return; const a0 = B([[sd * 8, -127]], 160)[0], a1 = B([[sd * 56, -206]], 161)[0], a2 = B([[sd * 124, -246]], 162)[0], qq = (u: number): P => lerp(lerp(a0, a1, u), lerp(a1, a2, u), u), pts: P[] = []; for (let j = 0; j <= 150; j++) { const u = (j / 150) * 0.9, pt = qq(u), p2 = qq(u + 0.01), dx = p2[0] - pt[0], dy = p2[1] - pt[1], l = Math.hypot(dx, dy) || 1, ph = j * 0.92, amp = 3.6 - u * 1.4; pts.push([pt[0] + (-dy / l) * Math.sin(ph) * amp + (dx / l) * Math.cos(ph) * amp * 0.55, pt[1] + (dx / l) * Math.sin(ph) * amp + (dy / l) * Math.cos(ph) * amp * 0.55]); } k.pen(pts.filter((_, j) => j % 2 === 0), 1.05, { seed: 163 + sd, wobble: 0.1, taper: 0.3, progress: cut(q, 0, 0.8) }); const e = qq(0.9), cl = qq(1); k.pen(k.spiral(cl[0], cl[1], 1.2, 9.5, 2.6, Math.atan2(e[1] - cl[1], e[0] - cl[0])).reverse(), 1.3, { seed: 165 + sd, progress: cut(q, 0.75, 1) }); }); /* the wire coils out from the base, the club winds on at the end */+}); };++// the three wheels seen through the broken-out window: the same train Detail B magnifies, so+// they turn by the same angles. Its own layer, because the housing around it never moves.+export const thoraxTrain = (k: Kit, t: Train, p = 1) => { if (p <= 0) return; k.ink(() => {+ const c = k.raw(), o = cen(THORAX), q = stagger(p, 4, 0.5); c.save(); k.g.path(c, WINDOW); c.clip();+ k.gear(o[0] + 2, o[1] + 4, 23, 16, 0.2 + t.centre, 110, { spokes: 4, w: 1.5, progress: q(1) }); k.gear(o[0] - 14, o[1] - 33, 13, 10, 0.5 + t.third, 120, { spokes: 3, w: 1.3, progress: q(2) }); k.gear(o[0] + 21, o[1] - 26, 9, 8, 0.1 + t.pinion, 130, { spokes: 3, w: 1.2, progress: q(3) }); k.pen(k.spiral(o[0] - 4, o[1] + 34, 2, 13, 3.4, -t.centre * 0.25), 1, { seed: 140, color: CYAN, progress: q(0) });+ c.restore(); k.g.touch(o[0] - 50, o[1] - 80, o[0] + 50, o[1] + 70);+}); };++// ---------------------------------------------------------------- the key, on its centre line+// y: 0 withdrawn (the approved plate), 1 seated on the spindle. turn: radians about the spindle+// axis, which in PLAN VIEW foreshortens the two bows to a line and back, never an in-plane spin.+export const key = (k: Kit, s: { y: number; turn: number; axis?: number; body?: number; note?: number }) => {+ const dy = -38 * s.y, cs = Math.cos(s.turn), still = s.y === 0 && s.turn === 0, ax = s.axis ?? 1, bp = s.body ?? 1, np = s.note ?? 1;+ if (ax <= 0 && bp <= 0 && np <= 0) return;+ const T = (p: P): P => (still ? p : [KC[0] + (p[0] - KC[0]) * cs, p[1] + dy]);+ k.ink(() => {+ k.chain([CX, CY - 168 * K], [CX, CY + 372 * K], 0.9, { seed: 170, color: DIM, opacity: 0.85, progress: ax }); /* the axis of symmetry: long dash, short dash */+ if (bp > 0) {+ const kc: P = still ? KC : [KC[0], KC[1] + dy], sq = cut(bp, 0, 0.3), rq = cut(bp, 0.25, 0.45), wq = cut(bp, 0.4, 1);+ [-1, 1].forEach((sd) => k.ln([kc[0] + sd * 3.2, kc[1] - 34], [kc[0] + sd * 3.2, kc[1] - 6], 1.6, { seed: 171 + sd, progress: sq })); k.ln([kc[0] - 3.2, kc[1] - 34], [kc[0] + 3.2, kc[1] - 34], 1.4, { seed: 173, progress: sq }); k.ring(kc[0], kc[1], 6.5, 1.8, 174, { progress: rq });+ [-1, 1].forEach((sd) => { const q = stagger(wq, 2, 0.75)(sd < 0 ? 0 : 1); if (q <= 0) return; const bow = k.jitter(k.oval(KC[0] + sd * 21, KC[1] + 3, 16, 21, 11, 0.4), 0.9, 175 + sd).map(T); k.pen(bow, 2.2, { seed: 176 + sd, closed: true, progress: cut(q, 0, 0.5) }); k.pen(bow.map((pt) => lerp(pt, cen(bow), 0.42)), 1.3, { seed: 178 + sd, closed: true, progress: cut(q, 0.4, 0.75) }); k.hatch([...bow.slice(3, 9), ...bow.slice(3, 9).map((pt) => lerp(pt, cen(bow), 0.42)).reverse()], 0.78, 3.2, 0.75, 180 + sd, { opacity: 0.75, progress: cut(q, 0.7, 1) }); });+ }+ if (np > 0) { const a: P = [CX + 30, CY + 268 * K], b: P = [CX + 30, CY + 292 * K]; k.ln(b, a, 1.1, { seed: 182, color: CYAN, progress: np }); if (np >= 1) k.arrow(a, -Math.PI / 2, 10, CYAN); } /* INSERT: the note stays put while the key moves */+ });+};++// ---------------------------------------------------------------- drafting furniture on the view+export const furniture = (k: Kit, w: { LF: Wing; RF: Wing; RH: Wing }, p = 1) => { if (p <= 0) return; k.ink(() => {+ const { LF, RF, RH } = w, N = 10, q = stagger(p, N, 0.32); /* the draftsman dimensions the drawing in the order he would: overall size, details, then the notes */+ const a0q = q(0), a1q = q(1), a2q = q(2), a3q = q(3), a4q = q(4);+ /* overall span, with witness lines that stand clear of the object */+ const la = LF.ends[0], ra = RF.ends[0], y = 102; k.ln([la[0], la[1] - 8], [la[0], y - 8], 0.95, { seed: 300, color: CYAN, progress: cut(a0q, 0, 0.4) }); k.ln([ra[0], ra[1] - 8], [ra[0], y - 8], 0.95, { seed: 301, color: CYAN, progress: cut(a0q, 0.2, 0.6) });+ const t = "WINGSPAN 184", tw = width(t, 12.5); k.ln([la[0], y], [CX - tw / 2 - 10, y], 0.95, { seed: 302, color: CYAN, progress: cut(a0q, 0.4, 0.8) }); k.ln([CX + tw / 2 + 10, y], [ra[0], y], 0.95, { seed: 303, color: CYAN, progress: cut(a0q, 0.4, 0.8) }); if (a0q >= 1) { k.arrow([la[0], y], Math.PI, 13); k.arrow([ra[0], y], 0, 13); } k.text(t, CX, y - 6.5, { cap: 12.5, align: "center", seed: 304, progress: cut(a0q, 0.7, 1) });+ /* key width, arrows outside the witness lines because the space between is too tight for them */+ const ky = KC[1] + 46, kx0 = KC[0] - 38, kx1 = KC[0] + 38; k.ln([kx0, KC[1] + 28], [kx0, ky + 6], 0.9, { seed: 310, color: CYAN, progress: cut(a1q, 0, 0.4) }); k.ln([kx1, KC[1] + 28], [kx1, ky + 6], 0.9, { seed: 311, color: CYAN, progress: cut(a1q, 0.2, 0.6) }); k.ln([kx0 - 30, ky], [kx1 + 30, ky], 0.95, { seed: 312, color: CYAN, progress: cut(a1q, 0.4, 0.8) }); if (a1q >= 1) { k.arrow([kx0, ky], 0, 11); k.arrow([kx1, ky], Math.PI, 11); } k.text("22", kx1 + 36, ky - 6, { cap: 11, seed: 314, progress: cut(a1q, 0.7, 1) });+ /* hinge sweep: the folded position in phantom line, and the arc between */+ const rh = RF.h, re = RF.ends[0], b0 = Math.atan2(re[1] - rh[1], re[0] - rh[0]), b1 = b0 - 1.0, R = 150; k.dash(rh, [rh[0] + Math.cos(b1) * 205, rh[1] + Math.sin(b1) * 205], 12, 6, 0.95, { seed: 320, color: DIM, opacity: 0.8, progress: cut(a2q, 0, 0.45) }); k.pen(k.arc(rh[0], rh[1], R, R, b1, b0, 9), 0.95, { seed: 321, color: CYAN, progress: cut(a2q, 0.35, 0.8) }); if (a2q >= 1) { k.arrow([rh[0] + Math.cos(b0) * R, rh[1] + Math.sin(b0) * R], b0 + Math.PI / 2, 10, CYAN); k.arrow([rh[0] + Math.cos(b1) * R, rh[1] + Math.sin(b1) * R], b1 - Math.PI / 2, 10, CYAN); } k.text("57o SWEEP", rh[0] + 12, rh[1] - 226, { cap: 10.5, seed: 322, progress: cut(a2q, 0.75, 1) });+ /* cutting plane A-A through the third abdominal segment, and the detail bubble on the thorax */+ const ya = CY + 146 * K; k.chain([CX - 92, ya], [CX + 92, ya], 1.7, { seed: 330, progress: cut(a3q, 0, 0.5) }); [-1, 1].forEach((sd) => { const qq = cut(a3q, 0.45, 0.85); k.ln([CX + sd * 92, ya], [CX + sd * 92, ya + 26], 2, { seed: 331 + sd, progress: qq }); if (a3q >= 1) k.arrow([CX + sd * 92, ya + 30], Math.PI / 2, 13); k.text("A", CX + sd * 92 + (sd < 0 ? -22 : 10), ya - 4, { cap: 15, seed: 333 + sd, w: 1.9, progress: cut(a3q, 0.8, 1) }); });+ const tc = cen(THORAX); /* the detail bubble is drawn earlier, with the thorax it rings */+ /* parts balloons, in number order */+ const bq = q(5), bs = stagger(bq, 6, 0.45);+ k.balloon("1", [118, 250], LF.spar(1, 0.62), 340, bs(0)); k.balloon("2", [92, 470], cen(LF.panels[3]), 342, bs(1)); k.balloon("3", [968, 128], RF.spar(0, 0.44), 344, bs(2)); k.balloon("4", [676, 700], [tc[0] + 16, tc[1] + 8], 346, bs(3)); k.balloon("5", [420, 742], [KC[0] - 24, KC[1] + 8], 348, bs(4)); k.balloon("6", [960, 640], RH.spar(2, 0.44), 350, bs(5));+ /* notes in the draftsman hand, one line at a time */+ const cq = stagger(Math.max(0, Math.min(1, (p - 0.6) / 0.4)), 6, 0.35);+ k.callout("ANTENNA - COILED WIRE, 2 OFF", [690, 140], [CX + 116 * K, CY - 236 * K], 360, "left", cq(0)); k.callout("PROBOSCIS HAIRSPRING", [468, 140], [CX - 10, CY - 150 * K], 362, "right", cq(1));+ k.callout("PANEL LIFTED", [930, 400], [cen(RF.panels[2])[0] + 84, cen(RF.panels[2])[1] - 30], 364, "left", cq(2)); k.callout("MEMBRANE OMITTED THIS SIDE", [776, 756], RH.spar(4, 0.78), 366, "left", cq(3)); k.callout("INSERT KEY & WIND 7 TURNS", [250, 700], [KC[0] - 40, KC[1] - 4], 368, "right", cq(4));+ k.callout("RIVETS x 96", [176, 140], LF.spar(0, 0.62), 370, "right", cq(5));+}); };++// ---------------------------------------------------------------- SECTION A-A+export const sectionAA = (k: Kit, p = 1) => { if (p <= 0) return; k.ink(() => {+ const c: P = [142, 880], q = stagger(p, 7, 0.36);+ k.ring(c[0], c[1], 56, 2.6, 400, { progress: q(0) }); k.ring(c[0], c[1], 45, 1.5, 401, { progress: q(1) }); k.hatch([...k.oval(c[0], c[1], 56, 56, 28), ...k.oval(c[0], c[1], 45, 45, 28).reverse()], 0.78, 4.2, 0.85, 402, { opacity: 0.9, progress: q(2) }); /* the shell, cut: section-lined */+ k.ring(c[0], c[1], 13, 1.8, 403, { progress: q(3) }); k.hatch(k.oval(c[0], c[1], 13, 13, 16), -0.78, 3.4, 0.8, 404, { opacity: 0.9, progress: q(3) }); /* the shaft is a different part, so its lines run the other way */+ k.gear(c[0], c[1], 30, 14, 0.3, 405, { spokes: 0, w: 1.4, progress: q(4) }); [[-32, -32], [32, -32], [-32, 32], [32, 32]].forEach(([x, y], i) => { k.ring(c[0] + x * 1.13, c[1] + y * 1.13, 3, 1.1, 410 + i, { progress: stagger(q(5), 4, 0.6)(i) }); });+ k.ln([c[0] - 70, c[1]], [c[0] + 70, c[1]], 0.85, { seed: 415, color: DIM, progress: q(5) }); k.ln([c[0], c[1] - 70], [c[0], c[1] + 70], 0.85, { seed: 416, color: DIM, progress: q(5) });+ k.text("SECTION A-A", c[0], c[1] + 70, { cap: 12, align: "center", seed: 417, progress: q(6) }); k.text("SCALE 4 : 1", c[0], c[1] + 92, { cap: 9, align: "center", seed: 418, color: CYAN, progress: cut(q(6), 0.5, 1) });+ k.ln([c[0] - 54, c[1] + 87], [c[0] + 54, c[1] + 87], 1, { seed: 419, progress: cut(q(6), 0.4, 0.9) });+}); };++const DB: P = [392, 898], DR = 100;+const wheels = (): { g1: P; g2: P; g3: P; ew: P; br: P } => { const g1: P = [DB[0] - 22, DB[1] + 16], a2 = -0.87, g2: P = [g1[0] + Math.cos(a2) * 72, g1[1] + Math.sin(a2) * 72]; return { g1, g2, g3: [g2[0] + Math.cos(0.35) * 40, g2[1] + Math.sin(0.35) * 40], ew: [DB[0] + 56, DB[1] + 50], br: [DB[0] - 56, DB[1] - 62] }; };++// DETAIL B, the going train, at 8:1. Live: the four wheels, the mainspring coil and the fork.+export const detailTrain = (k: Kit, t: Train, p = 1) => { if (p <= 0) return; k.ink(() => {+ const { g1, g2, g3, ew, br } = wheels(), cg = k.raw(), q = stagger(p, 6, 0.42); /* one part per beat, in the order a watchmaker lays a train down */+ cg.save(); k.g.path(cg, k.oval(DB[0], DB[1], DR - 3, DR - 3, 40)); cg.clip();+ k.pen(k.spiral(br[0], br[1], 3, 26, 5.2, 0.6 - t.centre * 0.25), 1.15, { seed: 442, progress: q(0) }); /* the mainspring unwinds as the train runs */+ k.gear(g1[0], g1[1], 46, 24, 0.12 + t.centre, 450, { spokes: 5, progress: q(1) }); k.gear(g2[0], g2[1], 26, 14, 0.36 + t.third, 460, { spokes: 4, progress: q(2) }); k.gear(g3[0], g3[1], 14, 8, 0.2 + t.pinion, 470, { spokes: 0, progress: q(3) }); k.gear(ew[0], ew[1], 23, 15, 0.1 + t.escape, 480, { spokes: 4, spike: true, progress: q(4) }); /* centre wheel, third wheel, pinion, escape wheel */+ /* pallet fork astride the escape wheel: it rocks to the opposite side on every tick */+ const fq = q(5); if (fq > 0) { const pv: P = [ew[0] + 4, ew[1] - 36], fc = Math.cos(t.fork), fs = Math.sin(t.fork), F = (x: number, y: number): P => (t.fork === 0 ? [pv[0] + x, pv[1] + y] : [pv[0] + x * fc - y * fs, pv[1] + x * fs + y * fc]);+ k.ring(pv[0], pv[1], 3.4, 1.4, 490, { progress: cut(fq, 0, 0.3) }); [[-25, 16, -21, 25], [24, 12, 27, 22]].forEach(([x, y, x2, y2], i) => { const aq = stagger(cut(fq, 0.25, 1), 2, 0.7)(i); k.pen([pv, F(x * 0.55, y * 0.2), F(x, y)], 1.9, { seed: 491 + i, progress: aq }); k.ln(F(x, y), F(x2, y2), 2.6, { seed: 493 + i, taper: 0.2, progress: cut(aq, 0.7, 1) }); }); }+ cg.restore(); k.g.touch(DB[0] - DR, DB[1] - DR, DB[0] + DR, DB[1] + DR);+}); };++// Static: the boundary, the barrel shell, the bridge over the arbors, the tone and the notes.+export const detailPlate = (k: Kit, p = 1, notes = 1) => { if (p <= 0) return; k.ink(() => {+ const { g1, g2, br, ew } = wheels(), cg = k.raw(), q = stagger(p, 6, 0.4);+ k.pen(k.jitter(k.oval(DB[0], DB[1], DR, DR, 16), 1.2, 430), 1.5, { seed: 430, closed: true, wobble: 1.2, progress: q(0) });+ cg.save(); k.g.path(cg, k.oval(DB[0], DB[1], DR - 3, DR - 3, 40)); cg.clip();+ const bq = q(1); k.ring(br[0], br[1], 31, 2, 440, { progress: cut(bq, 0, 0.4) }); k.ring(br[0], br[1], 27, 1, 441, { color: CYAN, progress: cut(bq, 0.3, 0.6) }); k.ring(br[0], br[1], 3.4, 1.4, 443, { progress: cut(bq, 0.5, 0.7) }); k.hatch([...k.oval(br[0], br[1], 31, 31, 24), ...k.oval(br[0], br[1], 27, 27, 24).reverse()], 0.78, 3, 0.7, 444, { progress: cut(bq, 0.6, 1) }); /* mainspring barrel */+ const gq = q(2), bridge: P[] = [[g1[0] - 8, g1[1] - 9], [g2[0] - 6, g2[1] - 10], [g2[0] + 8, g2[1] + 6], [g1[0] + 9, g1[1] + 9]]; k.pen(poly(bridge, 3), 1.3, { seed: 496, closed: true, color: CYAN, wobble: 0.3, progress: cut(gq, 0, 0.6) }); [lerp(g1, g2, 0.33), lerp(g1, g2, 0.67)].forEach((pt, i) => { const sq = stagger(cut(gq, 0.5, 1), 2, 0.7)(i); k.ring(pt[0], pt[1], 3.6, 1.2, 497 + i, { progress: sq }); k.ln([pt[0] - 2.6, pt[1] - 1.4], [pt[0] + 2.6, pt[1] + 1.4], 1.1, { seed: 499 + i, progress: cut(sq, 0.6, 1) }); }); /* the bridge that carries the arbors, with its two screws */+ if (q(3) >= 1) { k.stipple(k.oval(g1[0], g1[1], 12, 12, 12), 120, 500, () => 0.55); k.stipple(k.oval(g2[0], g2[1], 7, 7, 10), 60, 501, () => 0.55); }+ cg.restore(); k.g.touch(DB[0] - DR, DB[1] - DR, DB[0] + DR, DB[1] + DR);+ const lq = q(4); k.text("DETAIL B", DB[0] + DR + 6, DB[1] - 100, { cap: 12, seed: 510, progress: cut(lq, 0, 0.5) }); k.text("SCALE 8 : 1", DB[0] + DR + 6, DB[1] - 79, { cap: 9, seed: 511, color: CYAN, progress: cut(lq, 0.4, 0.8) }); k.ln([DB[0] + DR + 4, DB[1] - 83.5], [DB[0] + DR + 92, DB[1] - 83.5], 1, { seed: 512, progress: cut(lq, 0.7, 1) });+ const cq = stagger(notes, 4, 0.5); /* the tooth counts are notes, and notes are written in the notes phase */+ k.callout("24 T", [DB[0] + DR + 14, DB[1] + 4], [g1[0] + 44, g1[1] + 14], 513, "left", cq(0)); k.callout("14 T", [DB[0] + DR + 14, DB[1] - 36], [g2[0] + 22, g2[1] + 4], 515, "left", cq(1)); k.callout("ESCAPE WHEEL 15 T", [DB[0] + DR - 4, DB[1] + 86], [ew[0] + 18, ew[1] + 14], 517, "left", cq(2)); k.callout("MAINSPRING", [DB[0] - DR - 6, DB[1] - 112], [br[0] - 8, br[1] - 24], 519, "left", cq(3));+}); };++// ---------------------------------------------------------------- scale bar, parts list, cartouche+export const scaleBar = (k: Kit, p = 1) => { if (p <= 0) return; k.ink(() => { const x = 64, y = 1016, u = 26, q = stagger(p, 7, 0.4); for (let i = 0; i < 5; i++) { const a: P = [x + i * u, y], b: P = [x + (i + 1) * u, y], qq = q(i); if (qq <= 0) continue; if (i % 2 === 0 && qq >= 1) k.fill([[a[0], y - 7], [b[0], y - 7], [b[0], y], [a[0], y]], WHITE, 0.92); k.ln([a[0], y - 7], [b[0], y - 7], 1.2, { seed: 600 + i, progress: qq }); k.ln(a, b, 1.2, { seed: 610 + i, progress: qq }); k.ln([b[0], y - 11], [b[0], y], 1.2, { seed: 620 + i, progress: qq }); } k.ln([x, y - 11], [x, y], 1.2, { seed: 630, progress: q(0) }); ["0", "10", "20", "30", "40", "50"].forEach((t, i) => k.text(t, x + i * u, y - 26, { cap: 8, align: "center", seed: 640 + i, color: CYAN, w: 1, progress: stagger(q(5), 6, 0.5)(i) })); k.text("MM", x + 5 * u + 14, y - 9, { cap: 8.5, seed: 650, color: CYAN, w: 1, progress: q(6) }); }); };++export const partsList = (k: Kit, p = 1) => { if (p <= 0) return; k.ink(() => {+ const x0 = 650, x1 = 1026, y0 = 772, rowH = 15.5, rows: [string, string, string][] = [["1", "WING SPAR, HINGED", "13"], ["2", "MEMBRANE PANEL", "11"], ["3", "KNUCKLE HINGE & PIN", "13"], ["4", "GOING TRAIN ASSY", "1"], ["5", "WINDING KEY", "1"], ["6", "SPAR, HINDWING", "7"]];+ const yb = y0 + rowH * (rows.length + 1), fq = cut(p, 0, 0.3), hq = cut(p, 0.25, 0.45), rq = cut(p, 0.4, 1);+ [[[x0, y0], [x1, y0]], [[x1, y0], [x1, yb]], [[x1, yb], [x0, yb]], [[x0, yb], [x0, y0]]].forEach(([a, b], i) => k.ln(a as P, b as P, 1.7, { seed: 700 + i, taper: 0.15, progress: stagger(fq, 4, 0.5)(i) })); k.ln([x0, y0 + rowH], [x1, y0 + rowH], 1.5, { seed: 705, progress: hq }); [x0 + 34, x1 - 48].forEach((x, i) => k.ln([x, y0], [x, yb], 1, { seed: 706 + i, color: CYAN, progress: hq }));+ [["NO.", x0 + 17], ["DESCRIPTION", (x0 + 34 + x1 - 48) / 2], ["QTY", x1 - 24]].forEach(([t, x], i) => k.text(t as string, x as number, y0 + 3.2, { cap: 8.5, align: "center", seed: 710 + i, color: CYAN, w: 1.05, progress: stagger(hq, 3, 0.6)(i) }));+ const rs = stagger(rq, rows.length, 0.4);+ rows.forEach(([n, d, q], i) => { const y = y0 + rowH * (i + 1), qq = rs(i); if (qq <= 0) return; if (i) k.ln([x0, y], [x1, y], 0.8, { seed: 720 + i, color: DIM, opacity: 0.7, progress: cut(qq, 0, 0.3) }); k.text(n, x0 + 17, y + 3.4, { cap: 8.5, align: "center", seed: 730 + i, w: 1.05, progress: cut(qq, 0.2, 0.45) }); k.text(d, x0 + 42, y + 3.4, { cap: 8.5, seed: 740 + i, w: 1.05, progress: cut(qq, 0.3, 0.85) }); k.text(q, x1 - 24, y + 3.4, { cap: 8.5, align: "center", seed: 750 + i, w: 1.05, progress: cut(qq, 0.8, 1) }); });+}); };++// A draftsman rules the title block early and letters it last of all, so the box and the+// lettering are two different jobs on two different cues.+export const cartouche = (k: Kit, box = 1, text = 1) => { if (box <= 0 && text <= 0) return; k.ink(() => {+ const x0 = 650, x1 = 1026, y0 = 890, y1 = 1026, bq = cut(box, 0, 0.55), lq = cut(box, 0.45, 1);+ [[0, 2.8], [5, 1.1]].forEach(([m, w], j) => [[[x0 + m, y0 + m], [x1 - m, y0 + m]], [[x1 - m, y0 + m], [x1 - m, y1 - m]], [[x1 - m, y1 - m], [x0 + m, y1 - m]], [[x0 + m, y1 - m], [x0 + m, y0 + m]]].forEach(([a, b], i) => k.ln(a as P, b as P, w, { seed: 800 + j * 4 + i, taper: 0.12, progress: stagger(bq, 8, 0.42)(i * 2 + j) })));+ k.ln([x0 + 5, y0 + 62], [x1 - 5, y0 + 62], 1.2, { seed: 812, progress: cut(lq, 0, 0.5) }); k.ln([x0 + 5, y0 + 99], [x1 - 5, y0 + 99], 1, { seed: 813, color: CYAN, progress: cut(lq, 0.3, 0.8) }); [x0 + 128, x0 + 252].forEach((x, i) => k.ln([x, y0 + 62], [x, y1 - 5], 1, { seed: 814 + i, color: CYAN, progress: cut(lq, 0.5, 1) }));+ if (text <= 0) return;+ /* fields first, then the strapline, and the plate's name last of all */+ const f1 = cut(text, 0, 0.3), f2 = cut(text, 0.25, 0.55), sq = cut(text, 0.5, 0.72), tq = cut(text, 0.68, 1);+ ([["PLATE", "I", x0 + 66], ["SCALE", "2 : 1", x0 + 190], ["SHEET", "1 OF 1", x0 + 314]] as [string, string, number][]).forEach(([a, v, x], i) => { const qq = stagger(f1, 3, 0.55)(i); k.text(a, x, y0 + 67, { cap: 7, align: "center", seed: 820 + i, color: CYAN, w: 0.95, progress: cut(qq, 0, 0.5) }); k.text(v, x, y0 + 79, { cap: 12.5, align: "center", seed: 823 + i, w: 1.6, progress: cut(qq, 0.4, 1) }); });+ ([["DRAWN", "F.B.", x0 + 66], ["DIMENSIONS", "MILLIMETRES", x0 + 190], ["DATE", "20 IX 2026", x0 + 314]] as [string, string, number][]).forEach(([a, v, x], i) => { const qq = stagger(f2, 3, 0.55)(i); k.text(a, x, y0 + 104, { cap: 7, align: "center", seed: 830 + i, color: CYAN, w: 0.95, progress: cut(qq, 0, 0.5) }); k.text(v, x, y0 + 116, { cap: 9.5, align: "center", seed: 833 + i, w: 1.2, progress: cut(qq, 0.4, 1) }); });+ k.text("CLOCKWORK BUTTERFLY - GENERAL ARRANGEMENT", (x0 + x1) / 2, y0 + 45, { cap: 8.6, align: "center", seed: 811, color: CYAN, w: 1.05, progress: sq });+ k.text("MECHANICAL LEPIDOPTERA", (x0 + x1) / 2, y0 + 16, { cap: 17, align: "center", seed: 810, w: 2.1, progress: tq });+}); };++// ---------------------------------------------------------------- the surface: dust, then tooth+export const dust = (k: Kit, W: number, H: number) => k.g.group("plain", () => { const c = k.raw(), r = k.rng(77); k.g.touch(0, 0, W, H); for (let i = 0; i < 260; i++) { c.globalAlpha = 0.1 + r() * 0.3; c.fillStyle = r() < 0.75 ? "#dff1fb" : "#06142c"; c.beginPath(); c.arc(r() * W, r() * H, 0.4 + r() * r() * 1.8, 0, Math.PI * 2); c.fill(); } c.globalAlpha = 1; });+export const tooth = (k: Kit) => { k.g.paper("paper", 0.34); k.g.paper("coldpress", 0.2); };diff --git a/example/src/canvas-core/butterfly/plate.ts b/example/src/canvas-core/butterfly/plate.tsnew file mode 100644index 0000000..376190d--- /dev/null+++ b/example/src/canvas-core/butterfly/plate.ts@@ -0,0 +1,83 @@+// THE COMPOSER. Draws PLATE I for one state, part by part, each part on its own surface so a+// part that did not change is not redrawn (spec 6.3). A cache entry's key names everything its+// pixels depend on, which is why caching stays inside the pure-function contract: a cold frame+// and a cached frame of the same number are the same pixels.+import { Ctx, Env, Gfx, Layer, Medium } from "../core";+import { FW, FW_H, FW_T, HW, HW_H, HW_T, Pose, REST, Wing, posed, wingGeom } from "./geom";+import { DRAFT, Kit, kit } from "./kit";+import { IDLE, Train, abdomen, bodyMask, border, bubble, cartouche, construction, detailPlate, detailTrain, drawWing, dust, furniture, grid, key, partsList, scaleBar, sectionAA, sheet, thoraxShell, thoraxTrain, tooth } from "./parts";++// How much of each part is on the sheet. 0 = the draftsman has not started it, 1 = finished.+export type Parts = { grid: number; border: number; construct: number; shell: number; head: number; window: number; detail: number; detailPlate: number; detailNotes: number; bubble: number; wing: [number, number, number, number]; skin: [number, number, number, number]; abdomen: number; axis: number; key: number; note: number; furniture: number; section: number; scale: number; list: number; cartouche: number; lettering: number };+export const FULL: Parts = { grid: 1, border: 1, construct: 0, shell: 1, head: 1, window: 1, detail: 1, detailPlate: 1, detailNotes: 1, bubble: 1, wing: [1, 1, 1, 1], skin: [1, 1, 1, 1], abdomen: 1, axis: 1, key: 1, note: 1, furniture: 1, section: 1, scale: 1, list: 1, cartouche: 1, lettering: 1 };+export const EMPTY: Parts = { grid: 0, border: 0, construct: 0, shell: 0, head: 0, window: 0, detail: 0, detailPlate: 0, detailNotes: 0, bubble: 0, wing: [0, 0, 0, 0], skin: [0, 0, 0, 0], abdomen: 0, axis: 0, key: 0, note: 0, furniture: 0, section: 0, scale: 0, list: 0, cartouche: 0, lettering: 0 };++// `boil` is the hero linework's breath. `inkedBoil` is the breath of everything the draftsman has+// ALREADY inked: the sheet, the grid, the border, the furniture, the cartouche. At the desk that is+// 0, because finished furniture is dead still (spec 4); once the drawing comes alive the whole sheet+// breathes with it. It is a field rather than a constant because the two moments want opposite+// answers, and a field is the only way a cache KEY can name it.+export type PlateState = { wings: Pose; lift: number; keyY: number; keyTurn: number; train: Train; shadow: [number, number]; boil: number; inkedBoil: number; boilIndex: number; p: Parts; view: View };+export const PLATE_REST: PlateState = { wings: REST, lift: 1, keyY: 0, keyTurn: 0, train: IDLE, shadow: [0, 0], boil: 0, inkedBoil: 0, boilIndex: 0, p: FULL, view: WIDE };+const SHADOW = "#061a30";+import { View, WIDE, blit as blitL, kk, part as partL, slotOf } from "./surface";+// A close shot must not fatten the line. The canvas transform multiplies width by the zoom, so+// the nib is divided back out and re-multiplied by zoom^0.35: a 3.3x push gets a line about+// 1.5x heavier, which is what a draftsman's pen looks like magnified (spec 6.4).+const nibFor = (z: number): Medium => (z === 1 ? DRAFT : { ...DRAFT, nib: (DRAFT.nib * Math.pow(z, 0.35)) / z });+const blit = (ctx: Ctx, L: Layer | null, dx = 0, dy = 0, alpha = 1) => blitL(ctx, L, dx, dy, alpha);++export const drawPlate = (ctx: Ctx, env: Env, s: PlateState) => {+ const W = env.W, H = env.H, dw = Math.round(W * env.scale), dh = Math.round(H * env.scale), p = s.p;+ // A surface drawn at some boil carries that boil in its PIXELS, so it must carry it in its KEY, or a+ // later frame at a different boil silently reuses the slot and the film stops being a function of the+ // frame number alone. Kit, boil frame and key term are all derived from the one number, together.+ const bfOf = (boil: number) => (boil > 0 ? s.boilIndex * 4 : 0);+ const keyOf = (boil: number) => kk(boil, boil > 0 ? s.boilIndex : 0);+ const bf = bfOf(s.boil), K = (g: Gfx, tint?: string) => kit(g, { boil: s.boil, tint });+ // The already-inked parts hold ONE boil phase rather than cycling: a sheet that has been drawn on+ // settles, it does not flutter. So their boil frame is always 0 and their key needs only the amount.+ const bf0 = 0, K0 = (g: Gfx, tint?: string) => kit(g, { boil: s.inkedBoil, tint });+ const v = s.view, vk = kk(v.cx, v.cy, v.zoom), med = nibFor(v.zoom);+ const part = (name: string, key: string, boilFrame: number, fn: (g: Gfx) => void): Layer => partL(env, med, name, key + "|" + vk, boilFrame, fn, v);+ const live = (name: string, key: string, fn: (g: Gfx) => void): Layer => part(name, key + "|" + b, bf, fn); /* draws with K, breathes */+ const still = (name: string, key: string, fn: (g: Gfx) => void): Layer => part(name, key + "|" + b0, bf0, fn); /* draws with K0, already inked */+ const b = keyOf(s.boil), b0 = kk(s.inkedBoil), t = kk(s.train.centre, s.train.escape, s.train.fork);+ const wings = (pose: Pose): Wing[] => [wingGeom(-1, HW, HW_H, HW_T, 2000, pose), wingGeom(1, HW, HW_H, HW_T, 2600, pose), wingGeom(-1, FW, FW_H, FW_T, 1000, pose), wingGeom(1, FW, FW_H, FW_T, 1600, pose)];+ const w = wings(s.wings), wr = posed(s.wings) ? wings(REST) : w, rest = { LH: wr[0], RH: wr[1], LF: wr[2], RF: wr[3] }; /* the furniture was inked on the resting drawing and stays where it was put */+ const on = (v: number) => v > 0;++ const drawWings = (g: Gfx, tint?: string) => {+ const k = K(g, tint);+ k.ink(() => { drawWing(k, w[0], -1, 2000, { skin: true, line: p.wing[0], skinP: p.skin[0] }); drawWing(k, w[1], 1, 2600, { skin: false, line: p.wing[1], skinP: p.skin[1] }); });+ k.ink(() => { drawWing(k, w[2], -1, 1000, { skin: true, line: p.wing[2], skinP: p.skin[2] }); drawWing(k, w[3], 1, 1600, { skin: true, lift: 2, liftT: s.lift, line: p.wing[3], skinP: p.skin[3] }); });+ };+ const anyWing = p.wing.some(on) || p.skin.some(on);++ const back = still("back", kk("back", p.grid, p.border), (g) => { const k = K0(g); sheet(k, W, H); grid(k, W, H, p.grid); border(k, W, H, p.border); });+ const constructL = on(p.construct) ? still("construct", kk(p.construct), (g) => construction(K0(g), { LF: rest.LF, RF: rest.RF, LH: rest.LH, RH: rest.RH }, p.construct)) : null;+ const wingL = anyWing ? live("wings", kk("w", p.wing.join(","), p.skin.join(","), s.lift, s.wings.flap, s.wings.sweep), drawWings) : null;+ const bodyL = on(p.abdomen) || on(p.shell) ? live("body", kk(p.abdomen, p.shell > 0 ? 1 : 0), (g) => { const k = K(g); bodyMask(k, on(p.shell)); abdomen(k, p.abdomen); }) : null;+ const shellL = on(p.shell) || on(p.head) ? live("shell", kk(p.shell, p.head), (g) => thoraxShell(K(g), { shell: p.shell, head: p.head })) : null;+ const windowL = on(p.window) ? live("window", kk(p.window, t), (g) => thoraxTrain(K(g), s.train, p.window)) : null;+ const keyL = on(p.axis) || on(p.key) || on(p.note) ? live("key", kk(p.axis, p.key, p.note, s.keyY, s.keyTurn), (g) => key(K(g), { y: s.keyY, turn: s.keyTurn, axis: p.axis, body: p.key, note: p.note })) : null;+ const frontOn = on(p.furniture) || on(p.section) || on(p.scale) || on(p.list) || on(p.cartouche) || on(p.lettering);+ const front = still("front", kk("f", p.furniture, p.section, p.scale, p.list, p.cartouche, p.lettering), (g) => { const k = K0(g); if (frontOn) { furniture(k, rest, p.furniture); sectionAA(k, p.section); scaleBar(k, p.scale); partsList(k, p.list); cartouche(k, p.cartouche, p.lettering); } dust(k, W, H); });+ const bubbleL = on(p.bubble) ? still("bubble", kk(p.bubble), (g) => bubble(K0(g), p.bubble)) : null;+ const detailL = on(p.detail) ? live("detail", kk(p.detail, t), (g) => detailTrain(K(g), s.train, p.detail)) : null;+ const detailFurn = on(p.detailPlate) ? still("detailPlate", kk(p.detailPlate, p.detailNotes), (g) => detailPlate(K0(g), p.detailPlate, p.detailNotes)) : null;++ blit(ctx, back); blit(ctx, constructL);+ if (s.shadow[0] || s.shadow[1]) { /* the drawing lifts off its own paper: one flat copy of the hero linework, offset */+ const sh = slotOf(env, "shadow", dw, dh).L, c = sh.ctx;+ c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; c.globalCompositeOperation = "source-over"; c.clearRect(0, 0, dw, dh);+ [wingL, bodyL, shellL, windowL, keyL].forEach((L) => L && c.drawImage(L.canvas as CanvasImageSource, 0, 0));+ c.globalCompositeOperation = "source-in"; c.fillStyle = SHADOW; c.fillRect(0, 0, dw, dh); c.globalCompositeOperation = "source-over";+ blit(ctx, sh, Math.round(s.shadow[0] * env.scale), Math.round(s.shadow[1] * env.scale), 0.7);+ }+ [wingL, bodyL, shellL, windowL, keyL, bubbleL, front, detailL, detailFurn].forEach((L) => blit(ctx, L));+ tooth(kit(new Gfx(ctx, env, 0, DRAFT))); /* the sheet's tooth is on the FRAME, so it neither swims nor blows up when the camera moves */+};++// The approved plate: every part finished, nothing running. Frame 0 of the motion test is this.+export const drawStill = (ctx: Ctx, _frame: number, env: Env) => drawPlate(ctx, env, PLATE_REST);diff --git a/example/src/canvas-core/butterfly/surface.ts b/example/src/canvas-core/butterfly/surface.tsnew file mode 100644index 0000000..614fddb--- /dev/null+++ b/example/src/canvas-core/butterfly/surface.ts@@ -0,0 +1,25 @@+// PART SURFACES. Every part of a plate draws onto its own persistent surface and is composited+// in order. A surface is redrawn only when its KEY changes, and the key names everything the+// pixels depend on, so a cached frame and a cold frame of the same number are identical.+import { Ctx, Env, Gfx, Layer, Medium } from "../core";++export const kk = (...v: (number | string)[]) => v.map((x) => (typeof x === "number" ? x.toFixed(4) : x)).join("|");+export type Slot = { L: Layer; key: string | null };+export const slotOf = (env: Env, name: string, dw: number, dh: number): Slot => {+ const id = `plate:${name}:${dw}x${dh}`; let s = env.cache.get(id) as Slot | undefined;+ if (!s) { s = { L: env.canvas(dw, dh), key: null }; env.cache.set(id, s); }+ return s;+};+export type View = { cx: number; cy: number; zoom: number };+export const WIDE: View = { cx: 540, cy: 540, zoom: 1 };+export const part = (env: Env, medium: Medium, name: string, key: string, boilFrame: number, fn: (g: Gfx) => void, view?: View): Layer => {+ const dw = Math.round(env.W * env.scale), dh = Math.round(env.H * env.scale), s = slotOf(env, name, dw, dh);+ if (s.key !== key) {+ s.L.ctx.setTransform(1, 0, 0, 1, 0, 0); s.L.ctx.globalAlpha = 1; s.L.ctx.globalCompositeOperation = "source-over"; s.L.ctx.clearRect(0, 0, dw, dh);+ const g = new Gfx(s.L.ctx, env, boilFrame, medium);+ if (view && view.zoom !== 1) g.push(env.W / 2 - view.zoom * view.cx, env.H / 2 - view.zoom * view.cy, view.zoom); /* the camera moves the CONTROL POINTS through the transform stack, never the finished pixels */+ fn(g); s.key = key;+ }+ return s.L;+};+export const blit = (ctx: Ctx, L: Layer | null, dx = 0, dy = 0, alpha = 1, op: GlobalCompositeOperation = "source-over") => { if (!L) return; ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = alpha; ctx.globalCompositeOperation = op; ctx.drawImage(L.canvas as CanvasImageSource, dx, dy); ctx.restore(); };diff --git a/example/src/canvas-core/mechanicalLepidoptera.ts b/example/src/canvas-core/mechanicalLepidoptera.tsnew file mode 100644index 0000000..af42f04--- /dev/null+++ b/example/src/canvas-core/mechanicalLepidoptera.ts@@ -0,0 +1,29 @@+// MECHANICAL LEPIDOPTERA. The whole film: 1800 frames, 60.0 s at 30 fps, 120 bpm, 1080x1080.+//+// ACT 1 frames 0- 540 BLUEPRINT: the plate drafts itself, with camera. LOCKED.+// MOVEMENT 2 frames 540-1800 ALIVE: one continuous coming-to-life, macro to wide.+//+// Act 1 is reused exactly as it was approved: its own cue table, its own composer, not a line+// changed. Movement 2 is one shot on top of it. The score is section 8, generated in pure JS on+// the same beat grid, so every onset sits on the frame that caused it.+import { DURATION as ACT1, SHOTS, gridProblems as act1Grid, stateAt } from "./butterfly/act1cues";+import { drawPlate } from "./butterfly/plate";+import { gridProblems as aliveGrid, LOCAL } from "./butterfly/alive/cues";+import { drawAlive } from "./butterfly/alive/movement2";+import { aliveScore, scoreProblems } from "./butterfly/alive/score";+import type { Film } from "./film";++const problems = [...act1Grid(), ...aliveGrid(), ...scoreProblems()];+if (problems.length) throw new Error("the film is off the grid:\n " + problems.join("\n "));++export const TOTAL = ACT1 + LOCAL; // 1800++export const mechanicalLepidoptera: Film = {+ meta: { title: "mechanicalLepidoptera", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: TOTAL },+ assets: { images: {} },+ shots: [+ ...SHOTS.map(([id, start, end]) => ({ id, start, end, draw: (ctx: CanvasRenderingContext2D, local: number, env: Parameters<typeof drawPlate>[1]) => drawPlate(ctx, env, stateAt(start + local)) })),+ { id: "movement2", start: ACT1, end: TOTAL, draw: (ctx, local, env) => drawAlive(ctx, env, local) },+ ],+ audio: aliveScore(TOTAL),+};diff --git a/example/src/hosts/page-mechanicalLepidoptera.ts b/example/src/hosts/page-mechanicalLepidoptera.tsnew file mode 100644index 0000000..34ed590--- /dev/null+++ b/example/src/hosts/page-mechanicalLepidoptera.ts@@ -0,0 +1,3 @@+import { mechanicalLepidoptera } from "../canvas-core/mechanicalLepidoptera";+import { mountFilm } from "./page";+mountFilm(mechanicalLepidoptera);diff --git a/references/backends-and-adapters.md b/references/backends-and-adapters.mdnew file mode 100644index 0000000..998b135--- /dev/null+++ b/references/backends-and-adapters.md@@ -0,0 +1,82 @@+# Backends and adapters++One art core, four backends, and the core cannot see any of them. An adapter is the only thing+that knows how a film becomes pixels.++## The interface++Every adapter exports the same four things, so `tools/gate.mjs` can hold any of them to the same+bar without knowing which it has:++```js+export const name = "html-player";+export const describe = () => "one sentence: what this adapter DELIVERS";+export const probe = () => ({ ok, why }); // can it run here, and if not, why not+export const open = async (film, { scale, workers }) => session;+```++A session is:++```js+{ workers, // how many independent draw contexts it actually opened+ info(), // -> film.meta+ frame(n, w), // -> { png: Buffer, shot, drawMs }+ hash(n, w), // -> stable digest of the drawn pixels+ audio(sampleRate), // -> { sampleRate, frames, pcm16 } | null+ artifact(), // -> the adapter's own deliverable, or null+ close() }+```++`workers` is the number of independent contexts, and the gate uses it to redraw the same frames a+different way. That is a stronger test than it sounds: each instance has its own texture tiles,+its own layer pool and its own cache, so two instances agreeing means the caches are genuinely+keyed on what the pixels depend on and not on the order somebody happened to ask for frames in.++## The four++| Adapter | Delivers | Needs |+|---|---|---|+| `playwright` | frames, as a means to an MP4 | playwright + a chromium build |+| `html-player` | **the page**: one self-contained offline HTML file | playwright + a chromium build |+| `remotion` | frames through a Remotion `<Composition>` | `remotion`, `@remotion/bundler`, `@remotion/renderer` |+| `hyperframes` | frames seeked in headless Chrome by the Hyperframes engine | `@hyperframes/engine`, Node >= 22, ffmpeg |++## Warm and cold catch different bugs++This is the one thing to carry away.++- **`html-player` shares one warm cache across frames.** It can catch a cache key that fails to+ name everything its pixels depend on, because it draws frame 512 and then frame 128 into the+ same session and compares.+- **`remotion` renders every frame COLD** — each still is its own page, its own module state, its+ own cache. It proves frame N owes nothing to the frames before it, and it **cannot** catch a+ stale cache, because there never is one.++On this film a real order-dependence sat in the plate composer: five cached surfaces baked the+line's "boil" into their pixels while leaving it out of their key. The warm adapter found it and+named the poisoning frame. The cold adapter passed happily. **Run both. Neither is the whole bar.**++## Writing a new one++Ninety percent of an adapter is plumbing; the film is already a pure function of the frame number,+which is what every one of these backends actually wants. Two traps, both paid for:++- **Remotion screenshots when React commits**, and a committed `<canvas>` is a blank one until the+ effect runs. Hold the frame with `delayRender` / `continueRender` around the draw or you will+ ship empty plates that pass every hash check, because they are consistently empty.+- **Do not pass the film through props.** A `Film` carries functions (every shot's `draw`, the+ score) and most frameworks serialize props. Close over it instead.++For a backend that drives a **seekable page** rather than a component, the page-side contract is+small and this engine already satisfies it: a finite frame count, forward, backward and random+seeks, and the same state whenever the same frame is asked for again. `window.FILM.seek(n)` is the+whole implementation. `tools/verify-frame-adapter.mjs` holds such an adapter to that contract+using playwright, which means you can prove the page-side half **before** the backend is installed.++## If a backend is not installed++Say so. Keep every reference behind a dynamic import inside `open()` so the file imports clean,+make `probe()` name what is missing and how to get it, and let the gate report `CANNOT RUN`+(exit 2) rather than failing. Then check that the module really exports what you are about to+call, and if it does not, say what it exported instead. A backend that is not installed should+report that it is not installed — it should never quietly produce a wrong answer.diff --git a/references/determinism-and-contract.md b/references/determinism-and-contract.mdnew file mode 100644index 0000000..edca569--- /dev/null+++ b/references/determinism-and-contract.md@@ -0,0 +1,46 @@+# Determinism, or it is not a film, it is a performance++> Doctrine earned making MECHANICAL LEPIDOPTERA, the worked example in `example/`. Every rule+> below was paid for on that film; where a mistake was the director's own it says so, because+> a rule with its scar attached is one people keep.++**Why.** "Backend-agnostic" is a promise that a frame is a fact. Frame 731 is the same pixels on a laptop, in CI, inside Remotion at concurrency 8, rendered first or last or alone. Every convenience you allow yourself breaks that promise somewhere you will not be looking: parallel renderers draw frames out of order, Safari has no `ctx.filter`, a fetched font arrives late once in fifty runs.++**The contract.**+1. `renderFrame(frame, env)` is PURE. No state carried between frames, no module-level mutable state that touches pixels. Audio is the same: samples are a pure function of the sample rate.+2. Randomness only from `rng(seed)`. Never `Math.random`. Never `Date`, never `performance.now` in the core; timing belongs to hosts.+3. A restricted canvas: paths, fill, stroke, clip, transforms, alpha, composite operations, patterns, gradients, `drawImage`, image data, `fillText` with a preloaded font. **No `ctx.filter` in any form.** No DOM, no `window`, no `new OffscreenCanvas` or `new Image`; surfaces come from `env.canvas()`.+4. **No assets.** No images, no fonts from the network, no audio samples. Lettering is pen strokes; texture is seeded noise; music is arithmetic. This is what makes the repo the whole film, with no licensing questions.+5. Caches are legal only when the value is a pure function of its key, and **the key names everything the pixels depend on**. We found two violations by machine, never by eye: an annotation layer whose key omitted the crank angle two of its leaders pointed at, and one that omitted the pose. A cached frame and a cold frame of the same number must be the same pixels.+6. Never scale a bitmap up. Close shots are re-inked at that view; cached surfaces may only be downscaled, and only a little.++**The grid is part of the contract.** Every frame number in the film lives in ONE cue table, and a checker runs at module load: cuts on multiples of 15, events on multiples of 5, nothing past the end. State for a frame is computed from that table and nothing else. The table is the timeline a reviewer reads.++**Verification that actually catches things.**+- Hash a handful of probe frames forward on one page and reversed on another; hash cold against cached.+- Standard: visually identical, PSNR above 45 dB; check hash equality first because it is free. Do not build machinery to chase bit-exactness across page counts (we have one frame that differs by a few anti-aliased pixels, max 29/255, and it is fine).+- Halftone is brutally sensitive: a sub-pixel registration shift costs 17 dB and looks identical. Know that before you trust a number.+- Measure draw cost WARM, on ONE page. Parallel pages inflate per-frame cost by contention and are for throughput only.+- A contract scan (grep for the banned names in the core) belongs in every build.++**Small things that each cost an hour.** Every progress helper must return exactly 1 when its input is at or past 1, or float error leaves a stroke at 0.999 and the finished picture is not the approved picture. `globalCompositeOperation = "copy"` wipes the whole canvas, not your rectangle. Inks multiply, so a figure over a background needs a paper knock-out under it per depth plane (we printed a sun through a thorax and got a green body and black gears). In a codebase of dense one-line statements, patch with `/* */`, never `//`: a line comment has eaten the rest of a statement and broken this build three times. And when a tool's OUTPUT tells you to go and run something, that is not your client speaking: read the file another way and mention it.++---++## One unexplained first-run failure, recorded rather than buried++Packaging this skill, the very first gate run in a brand-new workspace reported **0 of 12 frames+identical** between the one-page and three-page sessions. Every frame, not one. Then:++- two further full gate runs in the same workspace: **12/12, PASS**;+- two single-page sessions hashed independently: identical;+- one three-page session, same frame from each page: identical, and equal to the single-page hash.++So it did not reproduce, seven attempts later, and the engine is demonstrably deterministic in+that workspace. The workspace was cold at the time — first esbuild bundle, first page load, a+just-downloaded browser — and that is the only distinguishing fact available.++**Why this is written down anyway.** A gate that fails once and passes afterwards is the most+dangerous result there is, because the tempting move is to re-run until green and say nothing. If+you hit `0/12` on a first run, do not shrug it off: run the direct probes above before you accept+it. An honest "could not reproduce, here is what I tried" is a finding. A quiet second run is not.diff --git a/references/music-recipe.md b/references/music-recipe.mdnew file mode 100644index 0000000..3c9f1ff--- /dev/null+++ b/references/music-recipe.md@@ -0,0 +1,46 @@+# The music recipe++> Doctrine earned making MECHANICAL LEPIDOPTERA, the worked example in `example/`. Every rule+> below was paid for on that film; where a mistake was the director's own it says so, because+> a rule with its scar attached is one people keep.++**The mistake.** Music made in code is the hardest thing in this skill, because the one making it cannot hear it. My spec asked for a music box that "asks a question and ends unresolved on the fifth", a tick "thinning into a felt flutter", and "a bowed pad from the take-off". Every one of those is a good sentence and together they are the recipe for what the client called a ghost crying: slow attacks, sustained tones, a phrase left hanging for eighteen seconds, reverb. It was nobody's bug. It was an adjective brief, and adjective briefs produce atmosphere, and synthesized atmosphere is a haunted house.++**The rule: never "make it good". Ship this.**++**Banned, all of it, always:** minor keys and modes; any sustained pad, bowed or blown tone, drone or sub-bass; attack times over 10 ms; reverb tails, feedback delays, convolution; detuning, pitch glides, vibrato; filtered noise "wind" or swells; a phrase left unresolved for more than four bars; a gap with nothing sounding for more than one beat once the music has started.++**The instrument: a music box / celesta pluck.** Per note at frequency `f`:+- partials: sine at `f` gain 1.0, `2f` 0.35, `3f` 0.12, plus a strike "ping" at about `5.4f` gain 0.08 that dies in 60 ms;+- envelope: 2 ms linear attack, then pure exponential decay, no sustain. Time constant `tau = 0.45 * sqrt(440 / f)` seconds, so high notes are short and sparkly and low notes ring a little;+- velocity: strong beats 1.0, others 0.7, grace notes 0.45.+- bass: same pluck one to two octaves down with only the first two partials, gain 0.5. It is still a pluck. It never sustains.+- "room": ONE early reflection, 30 ms late, 14 dB down. No tail.++**Key, register, harmony.** C, G or D major. Melody between C5 and C7, bass C3 to G3. One chord per bar, **I, IV, V, I**, and nothing cleverer. If you want a lift for the payoff, go up a whole step and play the same thing.++**Melody.** Chord tones and the major pentatonic (1 2 3 5 6). Mostly steps, leaps only onto chord tones. Four-bar phrases in pairs: the QUESTION ends on the 5th over V, the ANSWER ends on the root over I, **and the answer follows immediately.** The story may hold its resolution back for a minute; the tune may not. What you hold back is the ARRANGEMENT: the octave doubling, the full arpeggio and the bell arrive with the payoff.++**Rhythm.** At 120 bpm and 30 fps a beat is 15 frames and a straight eighth is 7.5 frames, which does not exist. Use triplet eighths, 5 frames: 12/8, which is what a music box plays anyway. Accompaniment is a rolling 1-5-3-5 arpeggio on the triplets; melody mostly on beats. Every onset is a row in a cue table with its FRAME, and the module asserts at load that each sample index equals `round(frame / fps * sampleRate)`.++**Sound events ride on top, quietly:** a tick is a 2 ms noise burst through a band-pass at 3 kHz, the tock at 2 kHz, 20 dB under the melody. A landing is one soft pluck on its beat. The DING is a bell on the tonic (partials 1, 2, 3, 4.2, tau 1.2 s, doubled an octave down) on the final downbeat, with at least four beats of film after it.++**Arc without pads.** Act by act: melody alone; add bass; add the arpeggio; add octave sparkle; bell. More notes, never longer notes.++**Master.** Normalise to a peak of -3 dBFS, soft-clip with `tanh`, RMS near -18 dBFS.++**Verification, since you are deaf.** Print the score as text, bar by bar, note names and chords, so a human can read it. Measure from the DECODED file: peak, RMS per bar, longest silence, and spectral centroid (a bright pluck score sits well above 1.5 kHz; a number near 400 Hz means a pad got in). Then the only test that counts: **one 8-second sample to the client before you score the film.** It is the music's look-still. We skipped it and scored sixty seconds of the wrong thing.++---++## What is verified here, and what is not++Flagged by the director when this doctrine was written, and carried forward unchanged because it+still applies: the "what went wrong" above rests on the **client's description** of the render plus the+director's own spec, which had asked for exactly the ingredients she named. The director could not+hear it either. **The synthesis numbers are a good starting point, not a frozen answer** — confirm+them with one human listening pass before you trust them on a new film.++The related `doodle-film` skill's score advice (detune the loop flatter on each repeat, a hush and+a heartbeat kick) is tuned for a wistful film and contradicts several bans above. Neither is wrong;+they are for different moods. Say which mood you are in before you pick.diff --git a/references/realism-and-craft.md b/references/realism-and-craft.mdnew file mode 100644index 0000000..2a065db--- /dev/null+++ b/references/realism-and-craft.md@@ -0,0 +1,44 @@+# State the realism, and make texture by hand++> Doctrine earned making MECHANICAL LEPIDOPTERA, the worked example in `example/`. Every rule+> below was paid for on that film; where a mistake was the director's own it says so, because+> a rule with its scar attached is one people keep.++**The mistake, in four rounds.** Asked for "the butterfly, alive, in watercolour", we produced:++1. **Abstract.** Wings as long flat pink ribbons between ruled grey bars, a blue capsule for a body, antennae as lines with dots, no legs. My own spec line was "wings as stained glass". That sentence produced those panels. I withdrew it in writing.+2. **Washed out.** Anatomically improved and so pale it sat behind its own flowers. Watercolour is not "low opacity". It is thin FIRST washes with full-strength pigment dropped in where form turns. The client had to ask for "real pigment depth" as a hard requirement. That should have been in the brief.+3. **Stepped on.** The first side view folded the wing about its own midline with a single `abs()` in the transform, which turns one wing into a symmetrical moth lying flat: a butterfly somebody trod on. Then the body was drawn OVER the closed wings, the abdomen stuck out behind, and it read as a mosquito.+4. **Real**, once the brief said what real meant.++**Why.** A model asked for a subject draws the ICON of the subject, the thing a road sign would use. Icons are symmetrical, flat, outlined and built from primitives. Realism is a list of specific departures from the icon, and if the list is not written down, none of them happen.++**The rules.**++- **Name the anatomy, part by part.** For our creature: two true wing pairs with the forewing overlapping the hindwing's leading third; a closed discal cell; veins that fork, never cross and thin toward a margin scalloped between their ends; a fringe; a furred thorax; seven or eight tapering abdominal segments with paler bands; compound eyes with a highlight; palps; ringed antennae ending in true clubs; a coiled proboscis; six jointed legs that grip when perched and tuck in flight; an underside pattern that is different and quieter than the upper side. A specialist should be able to name every part on your still.+- **Open reference and say which.** The rebuild's file header names the four images actually looked at (a labelled venation plate, a generic wing for topology, a lateral photograph for the underside, a head macro). Borrow structure, never a real species' pattern: the subject stays original.+- **When the subject is a transformation, write the mapping.** Ours was a table: spar → vein, panel → wing cell, rivet → submarginal spot, housing → furred thorax, coiled wire → antenna, hairspring → proboscis. The mapping IS the shot. Without it we got "gears on the left, colour on the right", which the client rejected on sight. With it, every frame of the change is already anatomy.+- **"Keeps its position" means literally.** The first veins left the cell on bearings of their own and read as ruled lines in a new colour. The vein runs where the spar ran; what is new is the cell and the forks.+- **Avoid the hard collapsed profile.** A flat thing seen exactly edge-on is a line, and a winged thing seen exactly side-on with wings shut is a smear. Prefer three-quarter views and half-open poses. If the story truly needs the side view (ours did: butterflies sip with wings closed), AUTHOR it as a second view with its own control points. A closed wing is the same wing stood up, not a folded one. Draw the body under the wings. Never derive a profile by squashing the top view.+- **Form, then colour.** One named light direction for the whole film. Core shadow, reflected light, cast shadow onto whatever it touches, contact. Translucent things let 15 to 20 percent of what is behind them through. A subject with no cast shadow is pasted on, however well it is drawn.+- **Prove realism on ONE still: the specimen plate.** The subject alone, large, on plain paper, top view and side view together, like a page from a natural-history folio. No scene, no motion, no excuses. It is the cheapest image you will make and it settles the animal before it is put into forty shots. We made ours late, after two rounds of scene stills that were really arguments about the animal.+- **The same goes for every recurring subject.** Our ranunculus got its own section: petals painted from the centre out as overlapping C-strokes with slivers of bare paper between them, a tight green button, five authored views, and a rejected-on-sight list (concentric scalloped circles, a mathematical spiral, a pompom, straight stems). The first pass still came back with faceted low-poly centres and a magenta pompom, which tells you the list is necessary and not sufficient: you still have to look.++---++## Texture without filters++**Why no filters.** `ctx.filter` does not exist in Safari, is not guaranteed in headless or offscreen contexts, and SVG filters compute in linear RGB on a schedule of their own. A film that depends on them is not backend-agnostic. And, to be plain about it, filters are also how machine-drawn work gets its plastic look: one Gaussian blur over everything. Doing texture by hand is a constraint that improves the picture.++**The method.**+- **Seeded, tileable noise tiles**, built once per environment and cached by key: periodic gradient noise summed over octaves, 512 px, one tile per material (paper tooth, cold-press, ink tooth, wash granulation, riso speck, blueprint mottle). Same seed, same tile, every machine. Building them costs most of a second per page, so warm up before you measure anything.+- **Composite per layer, by meaning.** Alpha textures go on with `destination-in` (the ink only exists where the tooth lets it). Paper goes on with `multiply`. Patterns draw in the current transform, which is how texture scales with a subject; do not "fix" that.+- **Anything that was a displacement filter becomes displaced GEOMETRY.** Jitter the control points, roughen the ribbon's edge, let a wash miss its outline. Transform points and then ink them, so line weight survives foreshortening and zoom (we use `weight x zoom^0.35`, so a 3x close-up is about 1.5x heavier, not 3x).+- **Blur without `filter`:** draw small and draw back up, or stack offset copies at low alpha. A halo is one blurred copy of linework you already drew, not the group drawn twice (that change alone took a 187 ms frame to under 100).+- **Anchor texture to the WORLD, not the screen.** Screen-fixed grain crawls over the drawing the moment the camera moves and reads as noise. Bring up a finer octave as you zoom in, or close-ups go soft.+- **Texture belongs to its material.** We multiplied cream-stock grain over a whole frame that was still half blueprint, and the cut that was supposed to be invisible measured 28.8 dB. Clipped to the printed region it measured 41.+- **Scale-aware marks.** A wash that displaces its outline by a fixed thirteen units is right for a wing panel, turns a twenty-pixel petal into porridge and turns a thousand-pixel macro panel into an airbrushed ribbon. Size every mark relative to the thing it is drawing, and check the look at the closest AND the widest scale the film uses.+- **Ported from SVG?** Convert grey tiles from linear to sRGB or the grain comes out visibly greyer.+- **Medium-true motion comes from the same place.** Misregistered ink that lags a fast move and catches up; halftone dots that swell with wing speed; a wash that spreads from where the brush touched and pools at its wet edge; paint that trails its pencil by a few pixels. Each is a texture parameter driven by the cue table. That is how a medium moves, and it is worth more than any amount of generic easing.++---diff --git a/references/storytelling.md b/references/storytelling.mdnew file mode 100644index 0000000..19f6775--- /dev/null+++ b/references/storytelling.md@@ -0,0 +1,32 @@+# The story is the point++> Doctrine earned making MECHANICAL LEPIDOPTERA, the worked example in `example/`. Every rule+> below was paid for on that film; where a mistake was the director's own it says so, because+> a rule with its scar attached is one people keep.++**The mistake.** The brief we started from was "one clockwork butterfly, drawn four ways": blueprint, risograph, watercolour, editorial cutaway. Four acts, four lovely looks. We built three of them. Each one opened on a blank sheet, made its picture, flapped five times and held. It was a style reel with a butterfly in it. Nobody was moved, because nothing happened to anybody. The client's correction was one sentence, and it is the best note in this document: *it is BUILT, then it comes ALIVE and outgrows its own blueprint.* The editorial act was cut whole. The riso act was cut a few hours later. The film got better each time something beautiful was removed.++**Why it works this way.** An audience forgives a rough drawing in a story and resents a gorgeous one without. Style is how you say it. If there is no "it", style is a screensaver.++**What a film needs, even at 60 seconds:**++- **A transformation you can state as two words with an arrow.** Ours: built → alive. If yours is a list ("then we see it in riso"), it is not a story yet.+- **A hook in the first three seconds.** Ours: a bare sheet starts drawing itself. A question is planted: what is it making? No logos, no blank holds, no "establishing" anything.+- **A turn you can point to on the timeline.** Ours is frame 545: one drop of water lands on the blueprint. Everything before is a hand making a drawing; everything after is the drawing doing what no hand did. The turn should be caused by something IN the world of the film. Water develops cyanotypes and lifts their blue, so water is an honest bridge from blueprint to watercolour. We had no honest bridge from printer's ink to watercolour, which is how we knew the riso act did not belong.+- **An escalation that is physical.** Ours is one continuous pull-back, macro to wide, and every widening is released by a take-off. The camera is not decorating the story, it IS the story: the world gets bigger because the creature does.+- **A visual token that comes back changed.** Ours: the blueprint sheet. It is the whole world in Act 1. At the end it is a small blue rectangle lying in the grass with a butterfly-shaped blank where the drawing used to be, and the winding key left on it, no longer needed. Nobody points at it. The audience finds it, and that is the payoff. Plant the token early, never explain it, bring it back small.+- **A flaw that heals.** In Act 1 one wing panel never seats. It hangs on its projection lines through the whole blueprint. When the creature wakes, that panel slides home and stays a different colour for ever: the blueprint's blue, carried into life. One imperfection, set up and paid off, does more than any amount of polish.+- **A resolve, then room.** The signature lands on the final downbeat and then there are five beats to read it. End on the beat, then let it breathe. Never end ON the last event.++**Before / after.**++| | Before | After |+|---|---|---|+| Logline | One creature drawn four ways | It is built, then it comes alive and leaves its blueprint behind |+| Structure | 4 acts x (blank, build, flap, hold) | Act 1 builds it. One unbroken shot brings it to life and opens the world |+| Medium changes | 3, because we had 4 styles | 1, because the story has 2 states |+| Ending | Hold on finished print | The sheet in the grass, the key left behind, a signature |++**Tests before you build.** Say it in three sentences. Name the frame of the turn. Name the token and the two frames where it appears. For every shot ask "what changed for the character"; a shot where the answer is "the rendering style" is a shot to cut. And: every element in frame gets a one-line reason. In our meadow each flower colour, the footpath and the sun all had one. The oval bokeh blobs had none, and they were the first thing the eye caught as fake.++**No dead air.** The first riso and watercolour acts were static for half their length and opened on three seconds of empty stock. The rule since: something visibly moves in every second, from frame 0, and a "hold" means the camera creeps while the subject keeps living. Check it with a tool (per-frame changed-pixel fraction, no identical consecutive frames, no 15-frame window under half a percent) and ALSO by eye: a creeping camera changes every pixel and satisfies the tool while the eye sees a still. We shipped a second of exactly that before I caught it on the contact sheet.diff --git a/references/working-method.md b/references/working-method.mdnew file mode 100644index 0000000..c551219--- /dev/null+++ b/references/working-method.md@@ -0,0 +1,42 @@+# One still, then the whole film — and how two roles share one tree++> Doctrine earned making MECHANICAL LEPIDOPTERA, the worked example in `example/`. Every rule+> below was paid for on that film; where a mistake was the director's own it says so, because+> a rule with its scar attached is one people keep.++**The mistake, and it is mine.** Revision 3 of my spec had eight gates. Revision 4 had seven, stills first, each reviewed before the next began: a ranunculus sheet, six metamorphosis stills, three sheet stills, a re-approval of the destination. It felt rigorous. What it did was make the client approve fragments of a film she could not yet watch, round after round, while the thing she actually wanted, a film, stayed at zero frames. She called the gate off and asked for the finished film. She was right. The film that came back had problems no still would have shown (timing, flow, whether the pull-back felt motivated) and none of the problems the stills had been arguing about.++**Why one still earns its keep and seven do not.** A still answers exactly one question: is this the LOOK. Line, fill, palette, density, realism, medium. That question is cheap to ask (a still renders in under a minute) and ruinous to get wrong late (our first cast on the earlier film was rejected after scenes had been built on it; our first butterfly was rejected after it had been put into two scenes). So you ask it once, properly. Everything else, story, pacing, camera, continuity, music, only exists in motion, and you learn it fastest from a rough whole.++**The rule.**+- **ONE look still**, the hardest frame in the film: hero subject large, in its world, in the final medium, final light. Add a specimen plate if the subject is a real-world thing (`realism-and-craft.md`). Add one more still ONLY for a genuinely different look (we had two media, so two). That is the ceiling: three images.+- **Critique it yourself first**, in writing, against the craft table, and say what is still wrong when you show it.+- ✋ One approval.+- **Then build end to end without stopping.** A rough complete film on day one beats a perfect first act. Mechanical checks run continuously and need nobody's approval: types, grid, contract scan, draw budget, determinism probe, dead air.+- **Review the whole, once.** From the rendered file itself: a contact sheet at one tile per beat, each cut as a before/after pair with a difference measure, the dead-air numbers, a few full-resolution frames where the sheet raises a doubt. One numbered fix list, ranked. One rebuild.+- **Approval is a budget.** Each gate spends the client's attention and your tokens. Spend them where being wrong is expensive, which is the look, the music sample and the final film. Three, not thirty.++**What a good review looks like** (this part of the over-gated process was worth keeping): freeze a copy of the file and note its hash before looking, because the builder may be re-rendering under you (it was, twice). Report what works first, so it survives the fixes. Give causes, not impressions: not "the body is green" but "the sun disc prints over the thorax, blue times yellow". Correct your own spec in the same breath when the fault was yours (a 5-frame wing lag that I specified became antiphase on a 10-frame beat: one wing folded while the other was spread).++---++## Two roles, written handoffs, and the reset++**Why split at all.** The one who builds a shot cannot see it fresh, and the one who reviews their own work grades the effort. Separating director (story, spec, look, review) from builder (engine, determinism, the contract, the render) gave us a reviewer who had never seen the code's excuses and a builder who was never asked to have taste on a deadline. The client stays the approver and the relay.++**The pattern that worked.**+- **The spec is the single source of intent**, and it is rewritten WHOLE when the story changes, never patched into a palimpsest. Ours went through four revisions in a day; revision 2 was a "section 12 supersedes sections 5 and 9" patch, and everyone, including me, misread it. Mark every line that is the director's own call (we used FABLE) so the client can veto it in one line without hunting.+- **The builder keeps a running decisions log** in the project: design decisions, deviations, tradeoffs, open questions, appended after each batch, with numbers and hashes. It is how the director learns what was actually built, and it is where the best lessons in this document were found.+- **Reviews are files**: `reviews/<thing>-r<N>.md`, numbered items, ranked, self-contained enough to relay verbatim.+- **Two agents, one working tree, will collide.** The builder re-rendered over the file I was reviewing; I patched a source file it had open. The protocol that ended it: the director reviews a frozen COPY (record the hash), writes only review files, and never touches shared source or outputs while the builder is active. Small director patches are allowed only when the builder is idle, and each carries a comment saying who and why.+- **A green checkmark is a claim.** Re-run it. The builder's "G-AIR PASS" was true and the second of near-stillness was also true.++**The reset.** Long sessions rot. Ours showed it plainly: the client's messages began arriving with their first half cut off, context was being summarised underneath me, and I caught myself about to rebuild a plan on a half-sentence. The tell is any of these: you are guessing at what was asked; you re-derive something already decided; your answers get longer and less certain; the harness itself reports low context quality.++Do not push through. Reset:+1. **Write state to disk first.** Spec current, decisions log current, open review filed, and a short memory note: roles, the story in three sentences, the hard rules, where everything lives, the known environment traps.+2. **Clear the session.**+3. **Re-brief in one message with a READ-FIRST list**: the spec, the contract section, the built modules, the memory note. Roles stated in the first line. The task last.+4. **The fresh session verifies before it trusts.** Read the files, check the disk, say what disagrees with the briefing. (Ours found that the "already built" camera was not in the source, in the first five minutes.)++A reset cost us about ten minutes because the state was in files. It would have cost the project if the state had been in the conversation. And when a message arrives truncated, look for the full text in the session transcript before you guess; twice the missing half changed the job.