Skip to content

A Claude skill and TypeScript library for animated line-art SVG components: ink figures that walk and react, scenes with a day/night cycle.

Line-art animation skill, TypeScript library and examples

JDhruv14c43d698913cf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..37c3eab
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+node_modules/
+dist/
+.DS_Store
+*.log
+captures/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ab4bb8d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 JDhruv14
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..29e8f96
--- /dev/null
+++ b/README.md
@@ -0,0 +1,134 @@
+# line-art-animation
+
+A Claude skill and a small TypeScript library for animated line-art components:
+ink-on-paper figures that walk, ride and react, in scenes that run from day to night.
+Everything is drawn live in SVG, so it stays sharp at any size and responds to the
+pointer.
+
+![A Japanese street drawn in line art, going from late afternoon to night](media/village.gif)
+
+| Day | Night |
+|---|---|
+| ![The village at midday](media/day.png) | ![The village at night with lit windows](media/night.png) |
+
+## What's in the repo
+
+| | |
+|---|---|
+| `SKILL.md`, `references/` | The skill: workflow, the rules that make the style work, and guides for style, motion, scenes, verification, matching a reference clip and rendering video. |
+| `lib/` | Four dependency-free TypeScript modules: drawing primitives (`ink.ts`), a walk/run solver (`gait.ts`), springs, pendulums and wind (`motion.ts`), and a time-of-day palette (`daynight.ts`). |
+| `examples/walker/` | One figure in about 150 lines: a man with a briefcase walks across the card; click him and he tips his hat. |
+| `examples/village/` | A full scene: a street of machiya, a tea house and a bath house by a canal, villagers on schedules, a cat, birds, a boatman, lit windows and reflections, about a dozen interactions. |
+| `scripts/` | Deterministic frame capture for video, and tools for measuring a reference clip. |
+
+## Install the skill
+
+For Claude Code, clone it into your skills folder:
+
+```sh
+git clone https://github.com/JDhruv14/line-art-animation ~/.claude/skills/line-art-animation
+```
+
+or into `.claude/skills/` inside a single project. Then ask for what you want, for example:
+
+- "Make a line art animation of a bakery at dawn: a baker carrying trays, steam from the oven, a cat in the window."
+- "Turn this clip into a looping line-art component, matching its walk exactly." (attach or link the clip)
+- "Add a day-night cycle to the scene and render a 30-second 1080p video."
+
+Claude reads `SKILL.md`, copies `lib/` into your project, shows one figure for approval
+before building the rest, and checks motion frame by frame before handing it over.
+
+## Run the examples
+
+Requires Node 22.18 or newer.
+
+```sh
+npm install
+npm run dev # http://localhost:5173
+```
+
+In the village, drag the sun or moon across the sky to change the time, move the pointer
+to make wind, and click people, windows, lanterns, the wind chime, the cat, the birds or
+the water. URL flags: `?start=0.9` sets the starting time (0 is midnight, 0.5 noon),
+`?tau=0.5` pins it, `?day=30` makes a full day last 30 seconds, `?debug` steps time by hand.
+
+```sh
+npm run typecheck # strict for lib/ and the walker
+npm run build
+```
+
+## The library in brief
+
+![The walker example: a man with a briefcase and a red scarf walking past a lamp post](media/walker.gif)
+
+Figures are drawn in their own space, about 95 units tall with feet on y = 120, and placed
+into a scene with a transform. Limbs are two open pen strokes around a curve through the
+joints, which is most of what makes the drawing read as hand-inked.
+
+A complete program that draws a pair of legs walking across the page (the walker
+example adds the body, arms, clothes and the click reaction):
+
+```ts
+import { el, limb, shoe, place, inkDefs, run } from './lib/ink.ts';
+import { gait } from './lib/gait.ts';
+
+const svg = el('svg', { viewBox: '0 0 480 240' });
+document.body.append(svg);
+const fig = el('g', { filter: inkDefs(svg).filter }, svg);
+const legs = [limb(fig, 4.2), limb(fig, 4.2)];
+const shoes = [el('path', {}, fig), el('path', {}, fig)];
+
+const walk = gait({ kind: 'walk' });
+let phase = 0, x = 60;
+run((t, dt) => {
+ phase += dt / walk.period;
+ x += walk.speed * 1.25 * dt; // move at the gait's speed and the feet stay planted
+ place(fig, x % 520 - 20, 196, 1, 1.25);
+ const p = walk.pose(phase);
+ p.feet.forEach((foot, i) => {
+ legs[i].draw([p.hip, foot.knee, foot.ankle]);
+ shoe(shoes[i], foot.ankle, foot.pitch);
+ });
+});
+```
+
+`gait()` solves the legs rather than animating them: the planted foot slides back at
+exactly the travel speed, the swing follows a minimum-jerk path, the heel peels off the
+toe before each step, and hip height comes from what the planted legs can reach, so the
+body rises over each step and dips when both feet are down. Clothes are then drawn
+around the knees and ankles, so a coat or kimono opens and closes with the stride.
+
+`palette(τ)` gives sky, paper and ink colours for any time of day. Ink is `currentColor`
+and paper fills carry a `pp` class, so `applyPalette()` can turn the whole drawing into
+pale ink on indigo at night while windows and lanterns glow.
+
+## Render a video
+
+```sh
+npm run dev
+node scripts/capture.ts "http://localhost:5173/examples/village/?debug&capture&day=30&start=0.3" \
+ captures/village 900 30 1920 1080
+ffmpeg -framerate 30 -i captures/village/f%04d.png -c:v libx264 -preset slow -crf 15 \
+ -pix_fmt yuv420p -movflags +faststart -tune animation village.mp4
+```
+
+The capture script drives headless Chrome over the DevTools protocol, with no npm
+dependencies, and advances the scene by exactly one frame between screenshots, so the
+result doesn't depend on machine speed. It finds a local Chrome or Chromium, or uses
+`$CHROME`. Needs ffmpeg.
+
+## Match a reference clip
+
+```sh
+node scripts/clip.ts period clip.mp4 X Y W H # loop length of a region
+node scripts/clip.ts blobs clip.mp4 X Y W H Y0 Y1 # dark blobs per frame, e.g. feet
+scripts/frames.sh clip.mp4 X Y W H out/ # frames with a measuring grid
+```
+
+`references/matching.md` covers the rest: why to resample by time (most social clips
+are variable-frame-rate), reading poses off the grid, and an overlay mode for checking
+your drawing against the clip.
+
+## License
+
+MIT
diff --git a/SKILL.md b/SKILL.md
new file mode 100644
index 0000000..d75a16e
--- /dev/null
+++ b/SKILL.md
@@ -0,0 +1,97 @@
+---
+name: line-art-animation
+description: Build animated line-art components in SVG and TypeScript — thin ink lines on paper, people and animals that walk, run, cycle and react, scenes with wind, lit windows and a day/night cycle, exported to video if needed. Use this whenever someone asks for a line art (or ink, pen, doodle, hand-drawn) animation, an animated illustration or scene component, little characters doing everyday things, a living street/village/shop/park, a day-night cycle illustration, "make it like this clip" for a drawn animation, or a video of such a component — even if they never say "SVG" or "line art".
+---
+
+# Line-art animation
+
+Animated illustration components: everything is drawn with one thin pen on paper,
+built live in SVG from TypeScript, so it stays crisp at any size, responds to the
+pointer, and can be stepped frame by frame for checking or video export.
+
+This skill ships a small library (`lib/`), two examples (`examples/walker`, a single
+figure in ~150 lines; `examples/village`, a full scene) and tools (`scripts/`).
+Read the example that's closest to the request before writing anything.
+
+## How people judge this work
+
+They look at it like an animator would: frame by frame, at zoom, against life or
+against a reference. These were all rejected in practice, and each has a rule below:
+
+- walks that bob on a sine wave, feet that slide, gaits sped up to fit a time-lapse
+- limbs drawn as closed tubes; ruler-straight lines; rigid clothes that ignore the legs
+- a whole set of components built in one go that all look alike ("AI slop")
+- interactions that feel like UI instead of the world reacting
+- a page whose background changes with the scene ("looks like a video, not a component")
+- reusing characters from a reference clip when asked for something new
+- leftover props nobody asked for (they asked to remove hanging laundry)
+
+## Workflow
+
+1. **Pin the look** before anything moves. Read `references/style.md`. Decide the pen
+ weight, paper colour, figure proportions and the one or two flat accent colours.
+2. **Set up the project.** Copy `lib/` into the project (it's four dependency-free
+ `.ts` files) and use Vite + TypeScript (`package.json`, `tsconfig.json` and
+ `vite.config.ts` in this repo show the setup). Components are plain DOM/SVG — no framework needed.
+3. **Build one figure or one corner first** and show it (screenshot or a short clip,
+ next to the reference if there is one). Get a yes before building the rest. A
+ full set built at once comes back as generic; one good piece shows the bar.
+4. **Make it move** with `references/motion.md`: `gait()` for walking and running,
+ `spring()` / `pendulum()` for anything attached or hanging, keyed poses with
+ `curve()` or `sequence()` for gestures. Never animate a figure with free sines.
+5. **Compose the scene** with `references/scenes.md`: a self-contained card on a fixed
+ page background, layers, a time-of-day palette from `lib/daynight.ts`, lights,
+ wind, people arriving on schedules, interactions that are reactions.
+6. **Verify** with `references/verify.md` before showing anything: typecheck,
+ `?debug` stepping, zoomed frame strips of every moving thing, interactions
+ triggered and stepped through, 60 fps in a real tab.
+7. **If there's a reference clip to match**, follow `references/matching.md` — measure
+ timing and poses from the clip instead of guessing, and check with an overlay.
+8. **If they want a video**, follow `references/video.md` (deterministic headless
+ capture with `scripts/capture.ts`, then ffmpeg).
+
+## Rules that make it work
+
+- **Limbs are two open strokes.** `limb()` draws a paper-filled band between two pen
+ lines that stop short of each other at the far end. This is the style's signature.
+- **Lines curve.** Joints are rounded, edges bow slightly, nothing is ruler-straight.
+- **Draw each figure in its own space** — ~95 units tall, feet on y = 120, facing +x,
+ standing at x = 40 — and place it with `place(g, x, y, dir, scale)`. Proportions,
+ pen weight and the gait presets all assume this space.
+- **Clothes are drawn around the skeleton.** Solve the legs (even if hidden), then
+ draw the coat or kimono hem from the forward knee and the ankles so the cloth opens
+ and closes with the stride. Sleeves, scarves and bags swing on springs.
+- **Feet are planted.** Move a walker by exactly `gait.speed × scale` per second and
+ the stance foot stays still on the ground. Don't speed a gait up to match a
+ compressed clock; compress arrivals instead.
+- **Ink is `currentColor`, paper is `.pp`.** Retint the whole drawing with
+ `applyPalette()` (day: dark ink on warm paper; night: pale ink on indigo, warm
+ windows). Solid-colour limb fills must use `solid()`, or the paper CSS wins.
+- **The component is a card.** The page around it never changes colour.
+- **Interactions are the world reacting**: a person bows or tips a hat, a cat wakes and
+ stretches, a lantern swings, birds scatter, a fish jumps. Pointer movement is wind.
+ No buttons inside the scene; a single faint hint line is enough.
+- **New means new.** If the brief is "like this but new", keep the medium, pen,
+ proportions and timing feel; invent the characters, activities and props.
+
+## Library at a glance
+
+| module | what it gives you |
+|---|---|
+| `lib/ink.ts` | `pen` `shape` `blot` `paint` `limb` `solid` `joint` `hang` `curve` `shoe` `place` `toScene` `inkDefs` `run` |
+| `lib/gait.ts` | `gait({ kind: 'walk' \| 'shuffle' \| 'run', …overrides })` → `{ speed, period, pose(phase, go) }` |
+| `lib/motion.ts` | `spring` `pendulum` `pointerWind` `sequence` `seeded` `wobble` `ease` `minJerk` … |
+| `lib/daynight.ts` | `palette(τ)` → sky, paper, ink, `lamp`, `night`, `sunset`; `applyPalette` `nightTint` |
+
+`run(draw)` drives everything with `draw(t, dt)`. Two URL flags matter for checking:
+`?t=1.25` freezes time; `?debug` disables rAF and exposes `window.__step(seconds)`
+for exact stepping (background and headless tabs throttle rAF, so always verify in debug mode).
+
+## Scripts
+
+- `scripts/capture.ts <url?debug> <outDir> <frames> <fps> [w] [h] [setupJs] [frameJs]` — deterministic PNG frames from headless Chrome
+- `scripts/clip.ts period|blobs …` — loop length of a region; dark-blob tracking per frame
+- `scripts/frames.sh <clip> x y w h outDir` — grid-overlaid frames for reading poses off a clip
+
+All run with Node ≥ 22.18 (TypeScript is stripped natively) plus ffmpeg; `capture.ts`
+finds a local Chrome/Chromium or uses `$CHROME`.
diff --git a/examples/village/canal.ts b/examples/village/canal.ts
new file mode 100644
index 0000000..bf7fe1a
--- /dev/null
+++ b/examples/village/canal.ts
@@ -0,0 +1,164 @@
+// Street surface, canal wall, water, reflections, willow, koi, fireflies.
+import { el, pen, shape, blot, f, pt, PAPER } from '../../lib/ink.ts';
+import { W, H, BASE, EDGE, WATER, SP, rnd, srnd, clamp, lerp, smooth, ease, oval, rgb, hex, mix, wobble } from './kit.ts';
+
+const WARM = hex('#ffcf7e');
+
+export function buildCanal({ ground, canalL, willowL, glow }, defs) {
+ // ---------- street surface and gutter
+ el('path', { d: `M-10 ${BASE} L${W + 10} ${BASE} L${W + 10} ${EDGE} L-10 ${EDGE}Z`, fill: PAPER }, ground);
+
+ // ---------- canal wall: coping stones then two courses of masonry
+ const wall = el('g', {}, canalL);
+ shape(wall, SP).setAttribute('d', `M-10 ${EDGE} L${W + 10} ${EDGE} L${W + 10} ${WATER} L-10 ${WATER}Z`);
+ const d = [`M-10 ${EDGE + 5} L${W + 10} ${EDGE + 5}`, `M-10 ${EDGE + 10.5} Q${W / 2} ${EDGE + 10} ${W + 10} ${EDGE + 10.6}`];
+ for (let x = srnd(0, 20); x < W; x += srnd(28, 44)) d.push(`M${f(x)} ${EDGE} l0.4 5`);
+ [[EDGE + 5, EDGE + 10.5, 0], [EDGE + 10.5, WATER, 8]].forEach(([y0, y1, o]) => {
+ for (let x = srnd(0, 14) + o; x < W; x += srnd(12, 24)) d.push(`M${f(x)} ${f(y0 + 0.4)} Q${f(x + srnd(-1, 1))} ${f((y0 + y1) / 2)} ${f(x + srnd(-0.6, 0.6))} ${f(y1 - 0.4)}`);
+ });
+ for (let i = 0; i < 40; i++) { const x = srnd(4, W - 4), y = srnd(EDGE + 6, WATER - 2); d.push(`M${f(x)} ${f(y)} l${f(srnd(1, 2.6))} ${f(srnd(-0.3, 0.3))}`); }
+ pen(wall, SP * 0.5).setAttribute('d', d.join(' '));
+ // moss tufts hanging over the coping
+ const moss = [];
+ for (let i = 0; i < 26; i++) { const x = srnd(0, W); moss.push(`M${f(x)} ${EDGE + 5} q-1 3 0.4 5 M${f(x + 2)} ${EDGE + 5} q1 2.6 -0.2 4.4`); }
+ pen(wall, SP * 0.45).setAttribute('d', moss.join(' '));
+
+ // ---------- water
+ const water = el('path', { d: `M-10 ${WATER} L${W + 10} ${WATER} L${W + 10} ${H + 10} L-10 ${H + 10}Z` }, canalL);
+ pen(canalL, SP * 0.8).setAttribute('d', `M-10 ${WATER} L${W + 10} ${WATER}`);
+ const reflG = el('g', {}, canalL);
+ const ripG = el('g', {}, canalL);
+ const lines = Array.from({ length: 46 }, (_, i) => ({ x: rnd(-40, W), y: WATER + 5 + (i % 9) * 8.4 + rnd(-2, 2), len: rnd(10, 34), v: rnd(4, 9), n: pen(ripG, SP * 0.5) }));
+ const rings = [];
+ const ringG = el('g', {}, canalL);
+ const ring = (x, y, n = 1, big = 1) => { for (let i = 0; i < n; i++) rings.push({ x, y, t: -i * 0.22, big, n: el('ellipse', { fill: 'none', stroke: 'currentColor', 'stroke-width': SP * 0.55 }, ringG) }); };
+
+ // reflections: light streaks under each lit source
+ const refl = [];
+ const addRefl = (src, x, w, warm = true) => {
+ const strokes = Array.from({ length: 9 }, (_, k) => el('path', { stroke: warm ? '#ffcf7e' : '#f3ecd6', 'stroke-width': 1.4 - k * 0.08, 'stroke-linecap': 'round', fill: 'none' }, reflG));
+ refl.push({ src, x, w, strokes, warm });
+ };
+
+ // floating petals land here
+ const floating = [];
+ const floatG = el('g', {}, canalL);
+
+ // ---------- koi (jumps where you click, or now and then)
+ const koiG = el('g', { opacity: 0 }, canalL);
+ const koiBody = el('path', { fill: '#f4ede0', stroke: 'currentColor', 'stroke-width': SP * 0.8 }, koiG);
+ const koiSpots = el('path', { fill: '#d4552f' }, koiG);
+ const koiFin = shape(koiG, SP * 0.6), koiEye = el('circle', { r: 0.9, fill: 'currentColor' }, koiG);
+ let koi = null;
+ const jump = (x) => { if (koi) return; koi = { x: clamp(x, 60, W - 60), t: 0, dir: Math.random() < 0.5 ? -1 : 1 }; ring(koi.x, WATER + 14, 2); };
+
+ // ---------- weeping willow on the near bank (left)
+ const willow = el('g', {}, willowL);
+ shape(willow, SP).setAttribute('d', 'M14 384 Q20 340 16 300 Q12 262 34 236 Q46 222 40 206 L46 206 Q54 226 42 244 Q24 270 28 306 Q32 344 28 384Z');
+ pen(willow, SP * 0.8).setAttribute('d', 'M36 238 Q66 214 104 212 M30 260 Q60 246 86 252 M40 222 Q22 204 -4 202 M42 214 Q56 196 82 190');
+ pen(willow, SP * 0.45).setAttribute('d', 'M20 330 q3 -6 0 -12 M24 290 q-3 -6 1 -12 M18 360 q2 -4 -1 -8');
+ const strands = [];
+ const roots = [[104, 212], [86, 252], [-4, 202], [82, 190], [64, 216], [52, 252], [20, 206], [70, 196], [94, 230], [40, 226], [6, 214]];
+ roots.forEach(([rx, ry], i) => {
+ const n = 4;
+ for (let k = 0; k < n; k++) {
+ const x = rx + srnd(-10, 10), y = ry + srnd(-3, 5), len = srnd(80, 150);
+ strands.push({ x, y, len, ph: srnd(0, 6), stiff: srnd(0.7, 1.3), n: pen(willow, SP * 0.5), leaves: pen(willow, SP * 0.45), a: 0, v: 0 });
+ }
+ });
+ let willowKick = 0;
+
+ // ---------- fireflies (night) and moths at the street lamp
+ const flies = Array.from({ length: 22 }, (_, i) => ({ cx: srnd(20, W - 20), cy: srnd(300, 460), ph: srnd(0, 50), sp: srnd(0.4, 0.9), blink: srnd(2, 5),
+ n: el('circle', { r: 5.5, fill: 'url(#v-fly)' }, glow), dot: el('circle', { r: 0.9, fill: '#f1ffb4' }, glow) }));
+ const fly = el('radialGradient', { id: 'v-fly' }, defs);
+ el('stop', { offset: 0, 'stop-color': '#e9ff9a', 'stop-opacity': 0.9 }, fly);
+ el('stop', { offset: 1, 'stop-color': '#c8ff6a', 'stop-opacity': 0 }, fly);
+ const moths = Array.from({ length: 4 }, () => ({ ph: rnd(0, 6), r: rnd(5, 12), sp: rnd(3, 6), n: el('circle', { r: 0.7, fill: '#fff4d2' }, glow) }));
+
+ return {
+ ring, jump, addRefl,
+ floatPetal(p) { floating.push({ x: p.x, y: WATER + rnd(3, 40), r: p.r, life: 0, n: el('ellipse', { rx: 1.5, ry: 0.7, fill: '#f6dfe4', stroke: 'currentColor', 'stroke-width': SP * 0.4 }, floatG) }); },
+ poke(x, y) { if (y > WATER) { if (Math.random() < 0.7 || !koi) jump(x); ring(x, y, 3); } },
+ willowPoke() { willowKick = 1; strands.forEach((s) => (s.v += rnd(1.5, 3))); },
+ draw(t, dt, P, wind, lights, tau, lampOn, moonX?: number) {
+ water.setAttribute('fill', rgb(mix(P.paper, P.inkT > 0.5 ? hex('#0f1730') : hex('#bfd0d8'), P.inkT > 0.5 ? 0.45 : 0.32)));
+ lines.forEach((l) => {
+ l.x += (l.v + wind * 4) * dt; if (l.x > W + 20) l.x = -40; if (l.x < -50) l.x = W + 10;
+ const y = l.y + Math.sin(t * 1.3 + l.x * 0.04) * 0.7;
+ l.n.setAttribute('d', `M${f(l.x)} ${f(y)} Q${f(l.x + l.len / 2)} ${f(y - 1.2)} ${f(l.x + l.len)} ${f(y)}`);
+ });
+ if (Math.random() < dt * 0.5) ring(rnd(40, W - 40), rnd(WATER + 10, H - 10), 1, 0.6);
+ if (P.night < 0.5 && Math.random() < dt * 0.03) jump(rnd(120, W - 120));
+ for (let i = rings.length - 1; i >= 0; i--) {
+ const r = rings[i]; r.t += dt;
+ if (r.t < 0) { r.n.setAttribute('opacity', 0); continue; }
+ r.n.setAttribute('cx', f(r.x)); r.n.setAttribute('cy', f(r.y));
+ r.n.setAttribute('rx', f((2 + r.t * 12) * r.big)); r.n.setAttribute('ry', f((0.6 + r.t * 2.2) * r.big));
+ r.n.setAttribute('opacity', f(Math.max(0, 1 - r.t / 1.6)));
+ if (r.t > 1.6) { r.n.remove(); rings.splice(i, 1); }
+ }
+ // reflections
+ refl.forEach((r) => {
+ const lit = r.src();
+ r.strokes.forEach((s, k) => {
+ if (lit < 0.02) { s.setAttribute('d', ''); return; }
+ const y = WATER + 6 + k * 6.5, jit = Math.sin(t * 2.2 + k * 1.7 + r.x * 0.1) * (2 + k * 0.5);
+ const w = r.w * (1 - k * 0.07) * (0.7 + 0.3 * Math.sin(t * 1.7 + k));
+ s.setAttribute('d', `M${f(r.x - w / 2 + jit)} ${f(y)} L${f(r.x + w / 2 + jit)} ${f(y)}`);
+ s.setAttribute('opacity', f(lit * (0.75 - k * 0.07)));
+ });
+ });
+ // floating petals drift downstream
+ for (let i = floating.length - 1; i >= 0; i--) {
+ const p = floating[i]; p.life += dt; p.x += (6 + wind * 3) * dt; p.r += dt * 0.3;
+ p.n.setAttribute('cx', f(p.x)); p.n.setAttribute('cy', f(p.y + Math.sin(t + p.x * 0.05) * 0.6));
+ p.n.setAttribute('transform', `rotate(${f(p.r * 40)} ${f(p.x)} ${f(p.y)})`);
+ p.n.setAttribute('opacity', f(Math.min(1, (12 - p.life) / 2)));
+ if (p.life > 12 || p.x > W + 10) { p.n.remove(); floating.splice(i, 1); }
+ }
+ // koi leap: arc out of the water, flip, splash back in
+ if (koi) {
+ koi.t += dt;
+ const u = koi.t / 1.1;
+ if (u >= 1) { ring(koi.x + koi.dir * 30, WATER + 14, 3, 1.2); koi = null; koiG.setAttribute('opacity', 0); }
+ else {
+ const x = koi.x + koi.dir * 30 * u, y = WATER + 14 - 26 * Math.sin(Math.PI * u);
+ const ang = Math.atan2(-26 * Math.PI * Math.cos(Math.PI * u), 30) * 57.3;
+ const bend = Math.sin(u * 18) * 2;
+ koiG.setAttribute('opacity', 1);
+ koiG.setAttribute("transform", `translate(${f(x)} ${f(y)}) rotate(${f(ang * koi.dir)}) scale(${koi.dir} 1)`);
+ koiBody.setAttribute('d', `M-11 0 Q-4 -5.4 6 -3.6 Q11 -2 12 0 Q11 2 6 3.6 Q-4 5.4 -11 0Z M-11 0 L-17 ${f(-4.5 + bend)} Q-15 0 -17 ${f(4.5 + bend)}Z`);
+ koiSpots.setAttribute('d', `${oval(2, -1.5, 3.2, 1.8)} ${oval(-5, 1, 2.6, 1.6)} ${oval(8.6, -0.8, 1.6, 1.2)}`);
+ koiFin.setAttribute('d', `M-1 3 L-4 7.5 L2 4Z`);
+ koiEye.setAttribute('cx', 9); koiEye.setAttribute('cy', -0.8);
+ if (u > 0.08 && u < 0.12 && !koi.dripped) { koi.dripped = true; ring(koi.x, WATER + 12, 2, 0.9); }
+ }
+ }
+ // willow strands: pendulums driven by the wind
+ willowKick = Math.max(0, willowKick - dt);
+ strands.forEach((s) => {
+ s.v += (-s.a * 3.2 * s.stiff + wind * 0.32 + wobble(t * 0.6 + s.ph) * 0.12 - s.v * 0.9) * dt; s.a += s.v * dt;
+ const pts = [];
+ for (let k = 0; k <= 10; k++) {
+ const u = k / 10, sway = s.a * s.len * u * u * 0.9 + Math.sin(t * 1.6 + s.ph + u * 3) * 1.2 * u;
+ pts.push([s.x + sway + u * 2, s.y + s.len * u - Math.abs(s.a) * s.len * u * u * 0.12]);
+ }
+ s.n.setAttribute('d', 'M' + pts.map(pt).join('L'));
+ s.leaves.setAttribute('d', pts.slice(2).map(([x, y], k) => `M${f(x)} ${f(y)} l${k % 2 ? 2 : -2} 2.4`).join(' '));
+ });
+ // fireflies: drift on slow noise, blink, only after dark
+ flies.forEach((fl, i) => {
+ const tt = t * fl.sp + fl.ph;
+ const x = fl.cx + Math.sin(tt * 0.7) * 30 + Math.sin(tt * 1.9) * 8, y = fl.cy + Math.sin(tt * 0.9 + 1) * 16 + Math.cos(tt * 2.3) * 5;
+ const b = Math.pow(Math.max(0, Math.sin(t * fl.blink + fl.ph)), 3);
+ fl.n.setAttribute('cx', f(x)); fl.n.setAttribute('cy', f(y)); fl.dot.setAttribute('cx', f(x)); fl.dot.setAttribute('cy', f(y));
+ fl.n.setAttribute('opacity', f(P.night * b)); fl.dot.setAttribute('opacity', f(P.night * (0.3 + 0.7 * b)));
+ });
+ moths.forEach((m, i) => {
+ const a = t * m.sp + m.ph, x = 446 + Math.cos(a) * m.r + Math.sin(a * 2.7) * 3, y = 240 + Math.sin(a * 1.3) * m.r * 0.6;
+ m.n.setAttribute('cx', f(x)); m.n.setAttribute('cy', f(y)); m.n.setAttribute('opacity', f(lampOn * (0.6 + 0.4 * Math.sin(a * 5))));
+ });
+ },
+ };
+}
diff --git a/examples/village/critters.ts b/examples/village/critters.ts
new file mode 100644
index 0000000..14967a0
--- /dev/null
+++ b/examples/village/critters.ts
@@ -0,0 +1,233 @@
+// Cat, sparrows, swallows, cherry petals, chimney smoke.
+import { el, pen, shape, blot, f, pt, PAPER } from '../../lib/ink.ts';
+import { W, BASE, EDGE, WATER, SP, rnd, pick, clamp, lerp, smooth, ease, oval, rgb, hex, mix, wobble } from './kit.ts';
+
+const L2 = (a, b, t) => [lerp(a[0], b[0], t), lerp(a[1], b[1], t)];
+
+// ===================================================================== calico cat on the bench
+// Pose = a handful of points; the cat blends between keyed poses.
+const POSES = {
+ sleep: { S: [-7, -6.4], H: [7, -6.6], Bc: [0, -9.4], C: [-9, -0.2], Bt: [9.6, -0.2], hd: [-10.6, -3.6], tilt: 30, ear: 0.4, eye: 0, mouth: 0, F1: [-11, 0], F2: [-8.6, 0], T0: [9, -2], T1: [6, 3], T2: [-5, 1.2], paw: 0 },
+ sit: { S: [-4.4, -12.6], H: [4.6, -5.4], Bc: [2.2, -11.4], C: [-6.4, -1.4], Bt: [6.6, -0.2], hd: [-5.4, -17.6], tilt: 0, ear: 1, eye: 1, mouth: 0, F1: [-5.6, 0], F2: [-3.4, 0], T0: [6.6, -1], T1: [13, 0.6], T2: [15.6, -4.4], paw: 0 },
+ yawn: { S: [-4.4, -12.8], H: [4.6, -5.4], Bc: [2.2, -11.6], C: [-6.4, -1.4], Bt: [6.6, -0.2], hd: [-5.6, -18.6], tilt: -18, ear: 0.6, eye: 0, mouth: 1, F1: [-5.6, 0], F2: [-3.4, 0], T0: [6.6, -1], T1: [13, 0.6], T2: [15.6, -4.4], paw: 0 },
+ stretch: { S: [-9.4, -4.6], H: [5.4, -11.6], Bc: [-1, -8.6], C: [-11, -1], Bt: [7.4, -3.6], hd: [-15.6, -6.6], tilt: -6, ear: 0.7, eye: 0.3, mouth: 0, F1: [-17.6, 0], F2: [-15, 0], T0: [7, -9.6], T1: [10, -17], T2: [8.6, -22], paw: 0 },
+ groom: { S: [-4.4, -12.6], H: [4.6, -5.4], Bc: [2.2, -11.4], C: [-6.4, -1.4], Bt: [6.6, -0.2], hd: [-5.2, -16.4], tilt: 22, ear: 1, eye: 0, mouth: 0, F1: [-5.6, 0], F2: [-6.6, -13.6], T0: [6.6, -1], T1: [13, 0.6], T2: [15.6, -3.4], paw: 1 },
+};
+const lerpPose = (a, b, t) => { const o = {}; for (const k in a) o[k] = Array.isArray(a[k]) ? L2(a[k], b[k], t) : lerp(a[k], b[k], t); return o; };
+const SEQ: Array<[string, number]> = [['sit', 0.7], ['yawn', 0.9], ['sit', 0.4], ['stretch', 1.5], ['sit', 0.6], ['groom', 0.45], ['sit', 0.35], ['groom', 0.45], ['sit', 0.35], ['groom', 0.45], ['sit', 0.9], ['sleep', 1.1]];
+
+export function createCat(parent, glow, { x, y }) {
+ const g = el('g', { style: 'cursor:pointer' }, parent);
+ const tailOut = el('path', { fill: 'none', stroke: 'currentColor', 'stroke-width': 3.1, 'stroke-linecap': 'round' }, g);
+ const tailIn = el('path', { fill: 'none', stroke: '#d08a4a', 'stroke-width': 1.5, 'stroke-linecap': 'round' }, g);
+ const legs = pen(g, SP * 1.6);
+ const body = shape(g, SP);
+ const patch = el('path', { fill: '#d08a4a' }, g), patch2 = blot(g);
+ const paws = shape(g, SP * 0.7);
+ const headG = el('g', {}, g);
+ const ears = el('path', { fill: PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.9, 'stroke-linejoin': 'round' }, headG);
+ el('ellipse', { cx: 0, cy: 0, rx: 4.6, ry: 4.1, fill: PAPER, stroke: 'currentColor', 'stroke-width': SP }, headG);
+ const capPatch = blot(headG);
+ const face = pen(headG, SP * 0.6);
+ const mouth = el('path', { fill: '#6a2a2a', stroke: 'currentColor', 'stroke-width': SP * 0.5 }, headG);
+ const eyesGlow = [0, 1].map(() => el('circle', { r: 2.4, fill: 'url(#v-cateye)', opacity: 0 }, glow));
+ let seqT = -1, idle = 0, flick = 0, ear = 0;
+ const hit = el('rect', { x: x - 20, y: y - 26, width: 42, height: 28, fill: 'transparent' }, g);
+ return {
+ g, hit,
+ poke() { if (seqT < 0) seqT = 0; },
+ draw(t, dt, P) {
+ // which pose now?
+ const awakeAtNight = P.night > 0.55;
+ let pose;
+ if (seqT >= 0) {
+ seqT += dt;
+ let acc = 0, prev = awakeAtNight ? 'sit' : 'sleep', cur = SEQ[0][0], u = 1;
+ for (let i = 0; i < SEQ.length; i++) {
+ const [name, d] = SEQ[i];
+ if (seqT < acc + d) { cur = name; u = (seqT - acc) / d; break; }
+ acc += d; prev = name; cur = name;
+ }
+ if (seqT > SEQ.reduce((a, s) => a + s[1], 0)) seqT = -1;
+ pose = lerpPose(POSES[prev], POSES[cur], ease(Math.min(1, u * 1.6)));
+ } else pose = lerpPose(POSES.sleep, POSES.sit, ease(clamp((P.night - 0.4) * 4, 0, 1)));
+ // breathing, tail tip flick, ear twitch
+ const breathe = Math.sin(t * 1.8) * 0.35;
+ idle -= dt; if (idle < 0) { idle = rnd(2, 6); if (Math.random() < 0.6) flick = 1; else ear = 1; }
+ flick = Math.max(0, flick - dt * 1.6); ear = Math.max(0, ear - dt * 3);
+ const X = (p) => x + p[0], Y = (p) => y + p[1];
+ const S = [X(pose.S), Y(pose.S) - breathe], H = [X(pose.H), Y(pose.H) - breathe * 0.6], Bc = [X(pose.Bc), Y(pose.Bc) - breathe * 1.2];
+ const C = [X(pose.C), Y(pose.C)], Bt = [X(pose.Bt), Y(pose.Bt)];
+ body.setAttribute('d', `M${pt(C)} Q${f(C[0] - 2)} ${f((C[1] + S[1]) / 2)} ${pt(S)} Q${pt(Bc)} ${pt(H)} Q${f(H[0] + 4)} ${f((H[1] + Bt[1]) / 2)} ${pt(Bt)} Q${f((Bt[0] + C[0]) / 2)} ${f(Math.max(Bt[1], C[1]) + 1)} ${pt(C)}Z`);
+ const mid = L2(S, H, 0.55);
+ patch.setAttribute('d', `M${f(mid[0] - 3.4)} ${f(mid[1] + 0.6)} Q${f(mid[0])} ${f(mid[1] - 3)} ${f(mid[0] + 4)} ${f(mid[1] + 0.2)} Q${f(mid[0] + 1)} ${f(mid[1] + 3.6)} ${f(mid[0] - 3.4)} ${f(mid[1] + 0.6)}Z`);
+ patch.setAttribute('fill', rgb(mix(hex('#d08a4a'), hex('#5a3a28'), P.inkT * 0.6)));
+ tailIn.setAttribute('stroke', rgb(mix(hex('#d08a4a'), hex('#5a3a28'), P.inkT * 0.6)));
+ const hb = L2(S, H, 0.85);
+ patch2.setAttribute('d', oval(hb[0], hb[1] + 1.4, 1.8, 1.2));
+ const fl = Math.sin(t * 14) * 2.5 * flick;
+ const T0 = [X(pose.T0), Y(pose.T0)], T1 = [X(pose.T1), Y(pose.T1)], T2 = [X(pose.T2) + fl, Y(pose.T2) - fl * 0.4];
+ tailOut.setAttribute('d', `M${pt(T0)} Q${pt(T1)} ${pt(T2)}`); tailIn.setAttribute('d', `M${pt(T0)} Q${pt(T1)} ${pt(T2)}`);
+ const sh = [S[0] + 1.4, S[1] + 4];
+ const F1 = [X(pose.F1), Y(pose.F1)], F2 = [X(pose.F2), Y(pose.F2)];
+ legs.setAttribute('d', `M${pt(sh)} L${pt(F1)} M${f(sh[0] + 1.6)} ${f(sh[1])} L${pt(F2)}`);
+ paws.setAttribute('d', `${oval(F1[0] - 0.4, F1[1] - 0.6, 1.5, 0.9)} ${oval(F2[0] - 0.4, F2[1] - 0.6, 1.5, 0.9)}`);
+ // head
+ const hd = [X(pose.hd), Y(pose.hd) - breathe];
+ headG.setAttribute('transform', `translate(${pt(hd)}) rotate(${f(pose.tilt)})`);
+ const e = pose.ear, tw = ear * 0.6;
+ ears.setAttribute('d', `M-4 -2 L${f(-4.2 - (1 - e) * 1.4)} ${f(-7.4 + (1 - e) * 3 + tw)} L-1 -3.6Z M1.4 -3.8 L${f(3.6 + (1 - e) * 1.6)} ${f(-7.2 + (1 - e) * 3)} L4.4 -1.8Z`);
+ capPatch.setAttribute('d', 'M-4.4 -1.2 Q-3.6 -3.8 -0.6 -4 Q-1.6 -1.6 -4.4 -1.2Z');
+ const open = pose.eye;
+ face.setAttribute('d', (open > 0.5 ? 'M-2.6 -0.4 a0.6 0.8 0 1 0 0.1 0 M1 -0.4 a0.6 0.8 0 1 0 0.1 0' : 'M-3.2 -0.2 q0.7 0.7 1.4 0 M0.6 -0.2 q0.7 0.7 1.4 0') + ' M-1.2 1.4 l0.6 0.5 l0.6 -0.5 M-4.4 1.6 l-3.6 -0.4 M-4.4 2.4 l-3.4 0.8 M2.6 1.8 l3.4 -0.2');
+ mouth.setAttribute('d', pose.mouth > 0.1 ? oval(-0.6, 2.6, 1.2 * pose.mouth, 1.5 * pose.mouth) : '');
+ eyesGlow.forEach((n, i) => { n.setAttribute('cx', f(hd[0] - 2.2 + i * 3.6)); n.setAttribute('cy', f(hd[1] - 0.4)); n.setAttribute('opacity', f(P.night * (open > 0.5 ? 0.9 : 0))); });
+ },
+ };
+}
+
+// ===================================================================== sparrows on the wire
+export function createSparrows(parent, { wireY, count = 7 }) {
+ const g = el('g', {}, parent);
+ const spots = [540, 575, 610, 660, 720, 790, 850, 905];
+ const birds = Array.from({ length: count }, (_, i) => {
+ const bg = el('g', {}, g);
+ return {
+ x: spots[i] + rnd(-6, 6), dir: Math.random() < 0.5 ? -1 : 1, state: 'perch', t: 0, next: rnd(1, 5), hopT: -1, tail: 0, peck: 0,
+ g: bg, tailN: pen(bg, SP * 0.9), body: shape(bg, SP * 0.7), cap: el('path', { fill: '#7a5a3c' }, bg), cheek: blot(bg), beak: blot(bg), wing: pen(bg, SP * 0.5), legs: pen(bg, SP * 0.4), wings: pen(bg, SP * 0.8),
+ fx: 0, fy: 0, path: null, hopFrom: 0, hopTo: 0,
+ };
+ });
+ const hit = el('path', { fill: 'transparent', style: 'cursor:pointer', d: '' }, g);
+ const flush = () => birds.forEach((b) => { if (b.state === 'perch') takeOff(b, false); });
+ function takeOff(b, away) {
+ const y0 = wireY(b.x) - 2.5;
+ const nx = away ? (Math.random() < 0.5 ? -40 : 1000) : clamp(spots[(Math.random() * spots.length) | 0] + rnd(-8, 8), 520, 930);
+ const up = rnd(40, 80);
+ b.path = { p0: [b.x, y0], c1: [b.x + rnd(-80, 80), y0 - up], c2: [nx + rnd(-60, 60), y0 - up * rnd(0.6, 1.2)], p1: [nx, away ? rnd(20, 80) : wireY(nx) - 2.5], dur: rnd(1.8, 3.2), away };
+ b.state = 'fly'; b.t = 0;
+ }
+ const bez = (p, u) => { const a = 1 - u; return [0, 1].map((k) => a * a * a * p.p0[k] + 3 * a * a * u * p.c1[k] + 3 * a * u * u * p.c2[k] + u * u * u * p.p1[k]); };
+ return {
+ g, hit, flush,
+ draw(t, dt, P) {
+ const roost = P.night > 0.5;
+ hit.setAttribute('d', `M520 ${wireY(520) - 14} L940 ${wireY(940) - 14} L940 ${wireY(940) + 6} L520 ${wireY(520) + 6}Z`);
+ birds.forEach((b, i) => {
+ if (b.state === 'perch' && roost) takeOff(b, true);
+ if (b.state === 'gone') { if (!roost && Math.random() < dt * 0.5) { b.x = spots[i]; b.path = { p0: [rnd(0, 1) < 0.5 ? -30 : 990, rnd(30, 90)], c1: [rnd(300, 700), rnd(40, 100)], c2: [b.x + rnd(-60, 60), wireY(b.x) - 50], p1: [b.x, wireY(b.x) - 2.5], dur: rnd(2.2, 3.4) }; b.state = 'fly'; b.t = 0; } b.g.setAttribute('opacity', 0); return; }
+ b.g.setAttribute('opacity', 1);
+ let x, y, flying = false, ang = 0;
+ if (b.state === 'fly') {
+ b.t += dt; const u = clamp(b.t / b.path.dur, 0, 1);
+ [x, y] = bez(b.path, ease(u));
+ const [x2] = bez(b.path, ease(Math.min(1, u + 0.02)));
+ b.dir = x2 >= x ? 1 : -1;
+ flying = u < 0.97;
+ if (u >= 1) { if (b.path.away) { b.state = 'gone'; } else { b.state = 'perch'; b.x = x; b.next = rnd(0.6, 3); } }
+ } else {
+ // idle life on the wire: hop, turn, peck/preen, flick the tail
+ b.next -= dt;
+ if (b.next < 0) {
+ b.next = rnd(0.8, 3.6);
+ const r = Math.random();
+ if (r < 0.35) { b.hopT = 0; b.hopFrom = b.x; b.hopTo = clamp(b.x + b.dir * rnd(4, 9), 520, 935); }
+ else if (r < 0.6) b.dir *= -1;
+ else if (r < 0.8) b.peck = 1;
+ else b.tail = 1;
+ }
+ if (b.hopT >= 0) { b.hopT += dt / 0.22; b.x = lerp(b.hopFrom, b.hopTo, ease(Math.min(1, b.hopT))); if (b.hopT >= 1) b.hopT = -1; }
+ x = b.x; y = wireY(b.x) - 2.5 - (b.hopT >= 0 ? Math.sin(Math.PI * b.hopT) * 3.2 : 0);
+ }
+ b.peck = Math.max(0, b.peck - dt * 2); b.tail = Math.max(0, b.tail - dt * 3);
+ const d = b.dir, pk = Math.sin(Math.PI * b.peck) * 1.6;
+ const X = (dx) => f(x + dx * d);
+ b.body.setAttribute('d', oval(x, y - 2.8, 3.1, 2.4));
+ b.cap.setAttribute('d', `M${X(0.8)} ${f(y - 5.6 + pk)} a2 1.8 0 0 1 ${f(3.6 * d)} 0Z`);
+ b.cap.setAttribute('fill', rgb(mix(hex('#7a5a3c'), hex('#3a2c22'), P.inkT * 0.5)));
+ b.cheek.setAttribute('d', oval(x + 2.6 * d, y - 4.4 + pk, 0.6, 0.6));
+ b.beak.setAttribute('d', `M${X(4.4)} ${f(y - 5.2 + pk)} L${X(6)} ${f(y - 4.8 + pk)} L${X(4.4)} ${f(y - 4.3 + pk)}Z`);
+ const tf = Math.sin(b.tail * 20) * 1.6 * b.tail;
+ b.tailN.setAttribute('d', `M${X(-2.4)} ${f(y - 2.6)} L${X(-6)} ${f(y - 0.6 - tf)}`);
+ b.wing.setAttribute('d', flying ? '' : `M${X(-1.6)} ${f(y - 3.6)} Q${X(0.6)} ${f(y - 2.2)} ${X(-2.2)} ${f(y - 1.4)}`);
+ b.legs.setAttribute('d', flying ? '' : `M${X(-0.4)} ${f(y - 0.6)} l0 1.2 M${X(0.8)} ${f(y - 0.6)} l0 1.2`);
+ const fl = Math.sin(t * 34 + i) * 4;
+ b.wings.setAttribute('d', flying ? `M${X(0)} ${f(y - 3.4)} L${X(-2)} ${f(y - 3.4 - fl)} M${X(0.6)} ${f(y - 3)} L${X(2.4)} ${f(y - 3 - fl * 0.8)}` : '');
+ });
+ },
+ };
+}
+
+// ===================================================================== swallows (day)
+export function createSwallows(parent) {
+ const birds = [0, 1].map((i) => ({ n: blot(parent), a: rnd(0, 6), b: rnd(0, 6), sp: rnd(0.8, 1.1) * (i ? -1 : 1), lx: 0, ly: 0 }));
+ return {
+ draw(t, dt, P) {
+ birds.forEach((s) => {
+ const tt = t * 0.32 * s.sp;
+ const x = 480 + 440 * Math.sin(tt + s.a), y = 150 + 55 * Math.sin(tt * 2.3 + s.b) + 18 * Math.sin(tt * 5.1);
+ const vx = x - (s.lx || x), vy = y - (s.ly || y); s.lx = x; s.ly = y;
+ const ang = Math.atan2(vy, vx) * 57.3;
+ const flap = Math.sin(t * 22 + s.a) > 0.4 ? 0.55 : 1;
+ s.n.setAttribute('d', `M7 0 L2.4 -1 L${-3} ${-6.4 * flap} L-0.6 -1.2 L-7 -2.6 L-4.6 0 L-7 2.6 L-0.6 1.2 L${-3} ${6.4 * flap} L2.4 1Z`);
+ s.n.setAttribute('transform', `translate(${f(x)} ${f(y)}) rotate(${f(ang)}) scale(0.8)`);
+ s.n.setAttribute('opacity', f(1 - P.night));
+ });
+ },
+ };
+}
+
+// ===================================================================== cherry petals
+export function createPetals(parent, { blossoms, canal }) {
+ const petals = [];
+ const add = (burst) => {
+ const [x, y] = blossoms[(Math.random() * blossoms.length) | 0];
+ const toWater = Math.random() < 0.35;
+ petals.push({ x, y, vx: rnd(-6, 6), vy: burst ? rnd(-10, 2) : rnd(2, 7), r: rnd(0, 6), ph: rnd(0, 6), life: 0, rest: 0,
+ land: toWater ? WATER + rnd(4, 40) : rnd(BASE + 2, EDGE - 2), toWater,
+ n: el('path', { fill: '#f6dfe4', stroke: 'currentColor', 'stroke-width': SP * 0.4 }, parent) });
+ };
+ return {
+ burst(n = 40) { for (let i = 0; i < n; i++) add(true); },
+ draw(t, dt, P, wind) {
+ if (Math.random() < dt * (1.4 + Math.abs(wind) * 1.4)) add(false);
+ for (let i = petals.length - 1; i >= 0; i--) {
+ const p = petals[i]; p.life += dt;
+ if (p.y < p.land) {
+ p.vy = lerp(p.vy, 11, dt * 1.4);
+ p.x += (p.vx + wind * 22 + Math.sin(p.life * 2.6 + p.ph) * 9) * dt; p.y += p.vy * dt; p.r += dt * 3.4;
+ } else if (p.toWater) { canal.floatPetal(p); p.n.remove(); petals.splice(i, 1); continue; }
+ else p.rest += dt;
+ const op = p.rest > 3 ? Math.max(0, 1 - (p.rest - 3)) : 1;
+ const sx = Math.abs(Math.cos(p.r * 1.3)) * 0.8 + 0.25;
+ p.n.setAttribute('d', `M${f(p.x - 1.8 * sx)} ${f(p.y)} Q${f(p.x)} ${f(p.y - 1.4)} ${f(p.x + 1.8 * sx)} ${f(p.y)} L${f(p.x + 1.2 * sx)} ${f(p.y + 0.4)} L${f(p.x + 1.8 * sx)} ${f(p.y + 0.9)} Q${f(p.x)} ${f(p.y + 1.6)} ${f(p.x - 1.8 * sx)} ${f(p.y)}Z`);
+ p.n.setAttribute('transform', `rotate(${f(Math.sin(p.r) * 70)} ${f(p.x)} ${f(p.y)})`);
+ p.n.setAttribute('opacity', f(op));
+ p.n.setAttribute('fill', rgb(mix(hex('#f6dfe4'), hex('#8a7480'), P.inkT * 0.6)));
+ if (op <= 0 || p.x > W + 20 || p.x < -20) { p.n.remove(); petals.splice(i, 1); }
+ }
+ },
+ };
+}
+
+// ===================================================================== smoke from the bath-house chimney
+export function createSmoke(parent, [cx, cy]) {
+ const puffs = [];
+ let acc = 0;
+ return {
+ draw(t, dt, P, wind, tau) {
+ const firing = tau > 0.55 || tau < 0.08; // the bath fires up in the afternoon
+ acc += dt;
+ if (firing && acc > 0.55) { acc = 0; puffs.push({ x: cx + rnd(-2, 2), y: cy, r: rnd(3, 4.5), life: 0, ph: rnd(0, 6), n: shape(parent, SP * 0.7) }); }
+ for (let i = puffs.length - 1; i >= 0; i--) {
+ const p = puffs[i]; p.life += dt;
+ p.x += (4 + wind * 10 + Math.sin(p.life * 1.2 + p.ph) * 2) * dt; p.y -= (9 - p.life * 0.6) * dt; p.r += dt * 2.2;
+ const pts = [];
+ for (let k = 0; k <= 14; k++) { const a = (k / 14) * Math.PI * 2; const rr = p.r * (1 + 0.16 * Math.sin(a * 3 + p.ph + p.life)); pts.push([p.x + Math.cos(a) * rr, p.y + Math.sin(a) * rr * 0.8]); }
+ p.n.setAttribute('d', 'M' + pts.map(pt).join('L') + 'Z');
+ p.n.setAttribute('opacity', f(Math.max(0, 0.9 - p.life / 7)));
+ if (p.life > 6.3) { p.n.remove(); puffs.splice(i, 1); }
+ }
+ },
+ };
+}
diff --git a/examples/village/houses.ts b/examples/village/houses.ts
new file mode 100644
index 0000000..4fa5d54
--- /dev/null
+++ b/examples/village/houses.ts
@@ -0,0 +1,476 @@
+// The street: four machiya-style buildings and an alley, drawn once, plus the
+// parts that live (windows that light, noren and lanterns in the wind, the
+// fūrin, a sliding shoji someone opens).
+import { el, pen, shape, blot, f, pt, limb, PAPER } from '../../lib/ink.ts';
+import { BASE, SP, srnd, lerp, clamp, smooth, ease, oval, rgb, hex, mix, wobble } from './kit.ts';
+
+const JP = '"Hiragino Mincho ProN","Yu Mincho","YuMincho","Noto Serif JP","Songti SC",serif';
+const RED = hex('#b3412d'), RED_NIGHT = hex('#6e2a22'), WARM = hex('#ffcf7e'), WARM_DEEP = hex('#f3a54d');
+
+// ------------------------------------------------------------------ drawing kit
+const P = (g, d, w = SP) => { const n = pen(g, w); n.setAttribute('d', d); return n; };
+const S = (g, d, w = SP) => { const n = shape(g, w); n.setAttribute('d', d); return n; };
+const B = (g, d) => { const n = blot(g); n.setAttribute('d', d); return n; };
+const rect = (x0, y0, x1, y1) => `M${x0} ${y0} L${x1} ${y0} L${x1} ${y1} L${x0} ${y1}Z`;
+function text(g, x, y, s, size, { vertical = false, weight = 600, anchor = 'middle', fill = 'currentColor' } = {}) {
+ const n = el('text', { x, y, 'font-size': size, 'font-family': JP, 'font-weight': weight, fill, 'text-anchor': anchor, 'dominant-baseline': 'central' }, g);
+ if (vertical) { n.setAttribute('writing-mode', 'vertical-rl'); n.setAttribute('glyph-orientation-vertical', '0'); }
+ n.textContent = s;
+ return n;
+}
+
+/** Tiled roof seen from the street: sweeping eave (sori), round tile ends, rafters, stacked ridge with oni tiles. */
+function roof(g, { x0, x1, eave, ridge, inset, tile = 5.6, sori = 2.8, depth = 2.6, oni = true, rafters = true }) {
+ const cx = (x0 + x1) / 2;
+ const eaveY = (x) => eave - sori * Math.pow(Math.abs(x - cx) / ((x1 - x0) / 2), 2.2);
+ S(g, `M${x0} ${eaveY(x0)} Q${cx} ${eave + sori * 0.6} ${x1} ${eaveY(x1)} L${x1 - inset} ${ridge} L${x0 + inset} ${ridge}Z`);
+ // tile channels: a line from each round tile end up to the ridge, slightly concave
+ const ch = [], ends = [];
+ for (let x = x0 + tile * 0.8; x < x1 - tile * 0.4; x += tile) {
+ const t = (x - x0) / (x1 - x0), ey = eaveY(x) - 0.4;
+ const top = lerp(x0 + inset, x1 - inset, t);
+ ch.push(`M${f(x)} ${f(ey - 1.6)} Q${f(lerp(x, top, 0.5) + (t - 0.5) * 2)} ${f(lerp(ey, ridge, 0.55))} ${f(top)} ${ridge + 1}`);
+ ends.push(oval(x, ey, 1.35, 1.35));
+ }
+ P(g, ch.join(' '), SP * 0.5);
+ const tiles = el('path', { d: ends.join(' '), fill: PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.55 }, g);
+ // fascia + rafter ends under the eave
+ P(g, `M${x0 + 1} ${eaveY(x0) + depth} Q${cx} ${eave + sori * 0.6 + depth} ${x1 - 1} ${eaveY(x1) + depth}`, SP * 0.7);
+ if (rafters) {
+ const r = [];
+ for (let x = x0 + 5; x < x1 - 3; x += 4.2) r.push(`M${f(x)} ${f(eaveY(x) + depth + 0.6)} l0 1.8`);
+ P(g, r.join(' '), SP * 0.6);
+ }
+ // ridge: stacked noshi tiles
+ const rx0 = x0 + inset - 4, rx1 = x1 - inset + 4;
+ S(g, rect(rx0, ridge - 5.5, rx1, ridge + 0.5), SP * 0.9);
+ P(g, `M${rx0} ${ridge - 2.6} L${rx1} ${ridge - 2.6}`, SP * 0.5);
+ if (oni) [rx0, rx1].forEach((x, i) => {
+ const s = i ? 1 : -1;
+ S(g, `M${x} ${ridge + 0.5} L${x} ${ridge - 6} Q${x + s * 0.5} ${ridge - 11} ${x + s * 4.5} ${ridge - 12} Q${x + s * 6.5} ${ridge - 9} ${x + s * 5} ${ridge - 6} L${x + s * 5} ${ridge + 0.5}Z`, SP * 0.85);
+ P(g, `M${x + s * 1.6} ${ridge - 4} q${s * 1.4} -1 ${s * 1.8} 1`, SP * 0.5);
+ });
+ return { tiles };
+}
+
+/** Sen-bon kōshi: fine vertical slats with a rhythm, rails top and bottom, short kiriko slats above the upper rail. */
+function koshi(g, x0, x1, y0, y1, { gap = 2.3 } = {}) {
+ const top = y0 + (y1 - y0) * 0.16;
+ S(g, rect(x0, y0, x1, y1), SP * 0.9);
+ const d = [`M${x0} ${f(top)} L${x1} ${f(top)}`, `M${x0} ${y1 - 3} L${x1} ${y1 - 3}`];
+ let k = 0;
+ for (let x = x0 + gap; x < x1 - 0.5; x += gap, k++) {
+ if (k % 4 === 3) d.push(`M${f(x)} ${y0} L${f(x)} ${y1}`);
+ else d.push(`M${f(x)} ${f(top)} L${f(x)} ${y1 - 3}`);
+ }
+ P(g, d.join(' '), SP * 0.55);
+}
+
+/** Plaster window with fat vertical bars (mushiko-mado). */
+function mushiko(g, x0, y0, x1, y1) {
+ S(g, `M${x0 + 3} ${y0} L${x1 - 3} ${y0} Q${x1} ${y0} ${x1} ${y0 + 3} L${x1} ${y1 - 3} Q${x1} ${y1} ${x1 - 3} ${y1} L${x0 + 3} ${y1} Q${x0} ${y1} ${x0} ${y1 - 3} L${x0} ${y0 + 3} Q${x0} ${y0} ${x0 + 3} ${y0}Z`, SP);
+ const d = [];
+ for (let x = x0 + 4; x < x1 - 3; x += 5) d.push(`M${x} ${y0 + 2.5} Q${x - 0.6} ${(y0 + y1) / 2} ${x} ${y1 - 2.5} M${x + 2.4} ${y0 + 2.5} Q${x + 1.8} ${(y0 + y1) / 2} ${x + 2.4} ${y1 - 2.5}`);
+ P(g, d.join(' '), SP * 0.55);
+}
+
+/** Inuyarai: curved bamboo fence along the base of the wall. */
+function inuyarai(g, x0, x1, y0) {
+ const d = [`M${x0} ${y0 + 1} Q${(x0 + x1) / 2} ${y0 - 1} ${x1} ${y0 + 1}`, `M${x0 - 1} ${BASE - 1} L${x1 + 1} ${BASE - 1}`];
+ for (let x = x0 + 1.5; x < x1; x += 2.6) d.push(`M${f(x)} ${y0 + 1} Q${f(x + 0.4)} ${f((y0 + BASE) / 2 + 3)} ${f(x - 0.6)} ${BASE - 1}`);
+ P(g, d.join(' '), SP * 0.5);
+}
+
+/** A window pane that lights up at night (drawn first; lattice goes on top). */
+function pane(g, glowG, x0, y0, x1, y1, { thr = srnd(0.15, 0.6), lateOff = srnd(0, 1) < 0.45 ? srnd(0.93, 1.12) : 9, warmth = srnd(0, 1) } = {}) {
+ const n = el('path', { d: rect(x0, y0, x1, y1), fill: PAPER }, g);
+ const glow = el('ellipse', { cx: (x0 + x1) / 2, cy: (y0 + y1) / 2, rx: (x1 - x0) * 0.9 + 10, ry: (y1 - y0) * 0.9 + 10, fill: 'url(#v-warmglow)', opacity: 0 }, glowG);
+ return { n, glow, thr, lateOff, warmth, x0, y0, x1, y1, lit: 0 };
+}
+
+/** Wind-blown noren hanging from a rod. */
+function noren(g, x0, x1, y, len, panels, label, { open = [0.28, 0.88], red = false } = {}) {
+ const grp = el('g', {}, g);
+ P(grp, `M${x0 - 2} ${y} L${x1 + 2} ${y}`, SP * 1.2);
+ const w = (x1 - x0) / panels;
+ const cloth = Array.from({ length: panels }, (_, i) => ({ x: x0 + i * w, w: w - 0.8, n: el('path', { fill: red ? rgb(RED) : PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.8, 'stroke-linejoin': 'round' }, grp), a: 0, v: 0, ph: srnd(0, 6) }));
+ const label_ = text(grp, (x0 + x1) / 2, y + len * 0.48, label, Math.min(len * 0.42, w * 0.95), { weight: 700, fill: red ? '#fbf3e6' : 'currentColor' });
+ return { grp, cloth, label: label_, y, len, open, red, x0, x1, show: 1,
+ draw(t, dt, wind, tau, P_) {
+ const [o0, o1] = this.open;
+ const isOpen = o1 > 1 ? tau > o0 || tau < o1 - 1 : tau > o0 && tau < o1;
+ this.show = this.first === undefined ? (this.first = 1, isOpen ? 1 : 0) : clamp(this.show + (isOpen ? dt : -dt) * 0.8, 0, 1);
+ this.grp.setAttribute('opacity', f(this.show));
+ this.grp.setAttribute('transform', `translate(0 ${f(-(1 - ease(this.show)) * 6)})`);
+ if (this.red) this.cloth.forEach((c) => c.n.setAttribute('fill', rgb(mix(RED, RED_NIGHT, P_.inkT))));
+ let sw = 0;
+ this.cloth.forEach((c, i) => {
+ c.v += (-c.a * 22 + wind * 2.2 + Math.sin(t * 1.7 + c.ph) * 0.6 - c.v * 3.2) * dt;
+ c.a += c.v * dt;
+ const s = c.a * this.len * 0.45, flt = Math.sin(t * 3.1 + i) * 0.5;
+ c.n.setAttribute('d', `M${f(c.x)} ${this.y} L${f(c.x + c.w)} ${this.y} Q${f(c.x + c.w + s * 0.4)} ${f(this.y + this.len * 0.6)} ${f(c.x + c.w + s + flt)} ${f(this.y + this.len)} L${f(c.x + s + flt)} ${f(this.y + this.len - 0.6)} Q${f(c.x + s * 0.4)} ${f(this.y + this.len * 0.6)} ${f(c.x)} ${this.y}Z`);
+ sw += s;
+ });
+ this.label.setAttribute('transform', `translate(${f(sw / this.cloth.length * 0.6)} 0)`);
+ },
+ poke() { this.cloth.forEach((c) => (c.v += 3 + Math.random() * 2)); },
+ };
+}
+
+/** Chōchin lantern hanging from a hook, swinging, glowing at night. */
+function chochin(g, glowG, x, y, { r = 7, h = 16, label = '', red = false } = {}) {
+ const grp = el('g', {}, g);
+ const body = el('path', { d: `M${-r * 0.75} 4 Q${-r * 1.18} ${4 + h / 2} ${-r * 0.75} ${4 + h} L${r * 0.75} ${4 + h} Q${r * 1.18} ${4 + h / 2} ${r * 0.75} 4Z`, fill: red ? rgb(RED) : PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.8 }, grp);
+ const ribs = [];
+ for (let k = 1; k < 5; k++) { const yy = 4 + (h * k) / 5, wv = r * (1.18 - 0.3 * Math.abs(k / 5 - 0.5) * 2); ribs.push(`M${f(-wv * 0.95)} ${f(yy)} Q0 ${f(yy + 1)} ${f(wv * 0.95)} ${f(yy)}`); }
+ P(grp, ribs.join(' '), SP * 0.4);
+ B(grp, `M${-r * 0.6} 2 L${r * 0.6} 2 L${r * 0.6} 4.4 L${-r * 0.6} 4.4Z M${-r * 0.6} ${4 + h - 0.4} L${r * 0.6} ${4 + h - 0.4} L${r * 0.6} ${6.4 + h} L${-r * 0.6} ${6.4 + h}Z`);
+ P(grp, 'M0 -4 L0 2', SP * 0.5);
+ const lbl = label ? text(grp, 0, 4 + h / 2, label, h * 0.42, { vertical: label.length > 1, weight: 700, fill: red ? '#fbf3e6' : 'currentColor' }) : null;
+ const glow = el('circle', { r: 30 + r, fill: 'url(#v-warmglow)', opacity: 0 }, glowG);
+ return { grp, body, glow, lbl, x, y, h, red, a: srnd(-0.05, 0.05), v: 0, ph: srnd(0, 6), thr: srnd(0.1, 0.3),
+ draw(t, dt, wind, P_) {
+ this.v += (-this.a * 10 + wind * 0.5 + Math.sin(t * 0.9 + this.ph) * 0.15 - this.v * 1.1) * dt;
+ this.a += this.v * dt;
+ this.grp.setAttribute('transform', `translate(${this.x} ${this.y}) rotate(${f(-this.a * 57.3)})`);
+ const lit = smooth(this.thr, this.thr + 0.2, P_.lamp);
+ const base = this.red ? mix(RED, RED_NIGHT, P_.inkT * (1 - lit)) : P_.paper;
+ this.body.setAttribute('fill', rgb(mix(base, this.red ? hex('#ff8a4a') : WARM, lit * 0.95)));
+ const cx = this.x + Math.sin(this.a) * -(this.h / 2 + 4), cy = this.y + Math.cos(this.a) * (this.h / 2 + 4);
+ this.glow.setAttribute('cx', f(cx)); this.glow.setAttribute('cy', f(cy));
+ this.glow.setAttribute('opacity', f(lit * (0.85 + 0.15 * Math.sin(t * 7 + this.ph) * Math.sin(t * 3.3))));
+ },
+ poke() { this.v += (Math.random() < 0.5 ? -1 : 1) * (1.8 + Math.random()); },
+ };
+}
+
+// ------------------------------------------------------------------ the street
+export function buildStreet(layers, defs) {
+ const { back, houses: hg, front, glow } = layers;
+ const g = (parent) => el('g', {}, parent);
+ const glowGrad = el('radialGradient', { id: 'v-warmglow' }, defs);
+ el('stop', { offset: 0, 'stop-color': '#ffd58a', 'stop-opacity': 0.75 }, glowGrad);
+ el('stop', { offset: 0.45, 'stop-color': '#ffb85c', 'stop-opacity': 0.28 }, glowGrad);
+ el('stop', { offset: 1, 'stop-color': '#ffb85c', 'stop-opacity': 0 }, glowGrad);
+
+ const windows = [], lanterns = [], norens = [];
+
+ // ---------- cherry tree behind the roofs (canopy rises above the alley)
+ const tree = g(back);
+ P(tree, 'M452 344 Q450 300 446 268 Q440 236 420 214 M462 344 Q463 300 468 262 Q474 236 500 214 M447 262 Q458 248 456 226 Q455 206 462 192', SP * 1.1);
+ P(tree, 'M430 224 l-10 -6 M490 222 l12 -4 M456 212 l-8 -10 M468 236 q10 -4 14 -12', SP * 0.7);
+ const canopy = g(tree);
+ const blossoms = [];
+ [[414, 206, 26], [502, 200, 28], [458, 176, 30], [434, 186, 22], [486, 180, 22], [460, 204, 26], [520, 216, 18], [400, 222, 18]].forEach(([cx, cy, r]) => {
+ const pts = [];
+ for (let i = 0; i <= 60; i++) { const a = (i / 60) * Math.PI * 2; const rr = r + 2 * Math.abs(Math.sin(a * 6.5)) - 0.6 * Math.sin(a * 3); pts.push([cx + rr * Math.cos(a), cy + rr * 0.78 * Math.sin(a)]); }
+ S(canopy, 'M' + pts.map(pt).join('L') + 'Z', SP * 0.8);
+ });
+ const fl = [];
+ for (let i = 0; i < 110; i++) {
+ const a = srnd(0, 6.28), d = Math.sqrt(srnd(0, 1));
+ const [cx, cy, r] = [[458, 196, 54], [414, 210, 26], [502, 204, 28]][i % 3];
+ const x = cx + Math.cos(a) * r * d * 0.95, y = cy + Math.sin(a) * r * 0.62 * d;
+ blossoms.push([x, y]);
+ const s = srnd(0.8, 1.3);
+ fl.push(`M${f(x)} ${f(y - s)} l${f(s * 0.95)} ${f(s * 0.7)} l${f(-s * 0.4)} ${f(s * 1.1)} l${f(-s * 1.1)} 0 l${f(-s * 0.4)} ${f(-s * 1.1)}Z`);
+ }
+ P(canopy, fl.join(' '), SP * 0.45);
+
+ // ---------- alley between H2 and H3: stone path to a small gate and a lantern
+ const alley = g(back);
+ S(alley, rect(432, 250, 482, BASE), SP * 0.6);
+ // side walls receding to a small gate; plank lines follow the perspective
+ S(alley, 'M432 258 L449 286 L449 306 L432 344Z', SP * 0.6);
+ S(alley, 'M482 258 L465 286 L465 306 L482 344Z', SP * 0.6);
+ P(alley, 'M436 265 L436 337 M440 271 L440 330 M444 278 L444 322 M478 265 L478 337 M474 271 L474 330 M470 278 L470 322', SP * 0.4);
+ S(alley, rect(449, 288, 465, 306), SP * 0.7);
+ S(alley, 'M446 289 L468 289 L465 283 L449 283Z', SP * 0.7);
+ P(alley, 'M457 289 L457 306', SP * 0.5);
+ // stepping stones shrinking into the distance
+ [[457, 339, 7, 2.4], [456, 328, 5.6, 1.9], [458, 319, 4.4, 1.5], [457, 312, 3.4, 1.1]].forEach(([x, y, rx, ry]) => S(alley, oval(x, y, rx, ry), SP * 0.5));
+ const alleyLamp = pane(alley, glow, 453.5, 293, 460.5, 301, { thr: 0.05, lateOff: 9 });
+ P(alley, 'M457 293 L457 301 M453.5 297 L460.5 297', SP * 0.4);
+
+ // ================= H1 · sake shop (酒屋) x 18–236
+ const h1 = g(hg);
+ [[26, 206], [220, 206]].forEach(([x, y]) => { S(h1, rect(x, y + 4, x + 8, 262), SP * 0.8); S(h1, `M${x - 3} ${y + 5} L${x + 11} ${y + 5} L${x + 8} ${y} L${x} ${y}Z`, SP * 0.7); });
+ S(h1, rect(32, 214, 222, 262));
+ roof(h1, { x0: 12, x1: 242, eave: 218, ridge: 184, inset: 28 });
+ mushiko(h1, 46, 230, 128, 252);
+ // horizontal signboard under the eave
+ S(h1, rect(140, 228, 212, 250), SP * 1.1);
+ P(h1, rect(142.5, 230.5, 209.5, 247.5), SP * 0.5);
+ text(h1, 176, 239.5, '白梅 酒', 11.5, { weight: 800 });
+ S(h1, rect(20, 270, 234, BASE));
+ roof(h1, { x0: 14, x1: 240, eave: 274, ridge: 262, inset: 6, tile: 5, sori: 1.4, oni: false });
+ windows.push(pane(h1, glow, 28, 284, 88, 336));
+ koshi(h1, 26, 90, 280, 340);
+ // door with noren
+ S(h1, rect(114, 280, 166, BASE), SP * 0.9);
+ windows.push(pane(h1, glow, 117, 283, 163, BASE - 1, { thr: 0.05, lateOff: 0.9 }));
+ P(h1, 'M117 314 L163 314 M140 283 L140 344', SP * 0.45);
+ norens.push(noren(h1, 116, 164, 281, 26, 3, '酒', { open: [0.29, 0.86] }));
+ // sake barrels (komodaru) stacked to the right
+ const barrel = (x, y, w, h) => {
+ S(h1, `M${x} ${y + 2} Q${x + w / 2} ${y - 1} ${x + w} ${y + 2} L${x + w} ${y + h - 2} Q${x + w / 2} ${y + h + 1} ${x} ${y + h - 2}Z`, SP * 0.9);
+ P(h1, `M${x} ${y + 6} Q${x + w / 2} ${y + 3.5} ${x + w} ${y + 6} M${x} ${y + h - 6} Q${x + w / 2} ${y + h - 3.5} ${x + w} ${y + h - 6} M${x + 3} ${y + 1} L${x + 3} ${y + h - 1} M${x + w - 3} ${y + 1} L${x + w - 3} ${y + h - 1}`, SP * 0.5);
+ S(h1, oval(x + w / 2, y + h / 2, w * 0.24, h * 0.24), SP * 0.6);
+ text(h1, x + w / 2, y + h / 2, '酒', w * 0.26, { weight: 800 });
+ };
+ barrel(172, 318, 28, 26); barrel(202, 318, 28, 26); barrel(187, 292, 28, 26);
+ // sugidama (cedar ball) hanging by the door
+ P(h1, 'M102 274 L102 280', SP * 0.6);
+ const sug = [];
+ for (let i = 0; i < 360; i++) { const a = srnd(0, 6.28), d = Math.sqrt(srnd(0, 1)) * 11.2; const x = 102 + Math.cos(a) * d, y = 292 + Math.sin(a) * d; const b = srnd(0, 6.28); sug.push(`M${f(x)} ${f(y)} l${f(Math.cos(b) * 1.6)} ${f(Math.sin(b) * 1.6)}`); }
+ S(h1, oval(102, 292, 12, 12), SP * 0.8);
+ P(h1, sug.join(' '), SP * 0.45);
+ P(h1, 'M97 303 l10 0 M100 303 l-1 5 M105 303 l1 5', SP * 0.5);
+
+ // ================= H2 · house with balcony x 236–432
+ const h2 = g(hg);
+ S(h2, rect(246, 200, 424, 260));
+ roof(h2, { x0: 230, x1: 438, eave: 204, ridge: 168, inset: 26 });
+ // upper shoji windows (left one slides open on click)
+ const shojiWin = pane(h2, glow, 262, 212, 318, 250, { thr: 0.12, lateOff: 1.08 });
+ windows.push(shojiWin);
+ const interior = g(h2); // revealed when the shoji slides
+ const room = el('path', { d: rect(262, 212, 318, 250), fill: '#3a2c22' }, interior);
+ const person = g(interior);
+ S(person, 'M294 250 Q295 236 304 234 Q313 236 314 250Z', SP * 0.8);
+ const face = S(person, oval(304, 227, 5, 6), SP * 0.8);
+ B(person, 'M298.6 226 Q299 219 304 219 Q309.4 219 309.4 226 Q307 222.5 304 223 Q301 222.5 298.6 226Z M302 219.4 a2.6 2.2 0 1 1 4 0Z');
+ const waveArm = limb(person, 3, SP * 0.7);
+ const slide = g(h2); // the sliding panel
+ const shojiGrid = (gg, x0, y0, x1, y1, cols, rows) => {
+ const d = [rect(x0, y0, x1, y1)];
+ for (let i = 1; i < cols; i++) { const x = lerp(x0, x1, i / cols); d.push(`M${f(x)} ${y0} L${f(x)} ${y1}`); }
+ for (let j = 1; j < rows; j++) { const y = lerp(y0, y1, j / rows); d.push(`M${x0} ${f(y)} L${x1} ${f(y)}`); }
+ P(gg, d.join(' '), SP * 0.5);
+ };
+ const slidePane = el('path', { d: rect(290, 212, 318, 250), fill: PAPER }, slide);
+ shojiGrid(slide, 290, 212, 318, 250, 3, 5);
+ shojiGrid(h2, 262, 212, 290, 250, 3, 5);
+ P(h2, rect(262, 212, 318, 250), SP);
+ windows.push(pane(h2, glow, 340, 212, 404, 250, { thr: 0.3 }));
+ shojiGrid(h2, 340, 212, 372, 250, 3, 5); shojiGrid(h2, 372, 212, 404, 250, 3, 5);
+ P(h2, rect(340, 212, 404, 250), SP);
+ // balcony rail
+ const rail = g(h2);
+ S(rail, rect(250, 238, 418, 258), SP * 0.8);
+ const bal = [];
+ for (let x = 254; x < 416; x += 5.2) bal.push(`M${f(x)} 241 L${f(x)} 256`);
+ P(rail, bal.join(' ') + ' M250 241 L418 241', SP * 0.5);
+ S(h2, rect(240, 268, 428, BASE));
+ roof(h2, { x0: 232, x1: 436, eave: 272, ridge: 260, inset: 6, tile: 5, sori: 1.4, oni: false });
+ windows.push(pane(h2, glow, 246, 282, 294, 322));
+ koshi(h2, 244, 296, 278, 324);
+ windows.push(pane(h2, glow, 366, 282, 422, 322, { thr: 0.25 }));
+ koshi(h2, 364, 424, 278, 324);
+ inuyarai(h2, 244, 296, 326); inuyarai(h2, 364, 424, 326);
+ // lattice sliding entrance door
+ S(h2, rect(304, 278, 356, BASE), SP * 0.9);
+ windows.push(pane(h2, glow, 306, 280, 354, BASE - 1, { thr: 0.2 }));
+ const dd = [];
+ for (let x = 308; x < 354; x += 3.4) dd.push(`M${f(x)} 280 L${f(x)} 343`);
+ for (let y = 290; y < 342; y += 12) dd.push(`M306 ${y} L354 ${y}`);
+ P(h2, dd.join(' ') + ' M330 280 L330 344', SP * 0.45);
+ S(h2, rect(316, 270, 344, 276), SP * 0.6);
+ text(h2, 330, 273, '伊 藤', 4.6, { weight: 700 });
+ // potted plants at the door
+ ([[298, 'pine'], [360, 'asagao']] as Array<[number, string]>).forEach(([x, kind]) => {
+ S(h2, `M${x - 5} 336 L${x + 5} 336 L${x + 4} ${BASE} L${x - 4} ${BASE}Z`, SP * 0.7);
+ if (kind === 'pine') {
+ P(h2, `M${x} 336 Q${x - 3} 330 ${x + 1} 325 Q${x + 4} 321 ${x - 1} 316 M${x + 1} 325 Q${x + 5} 324 ${x + 7} 321`, SP * 0.8);
+ [[x - 4, 324, 5.2], [x + 6, 319.5, 4], [x - 1, 314, 4.4]].forEach(([px, py, r]) => {
+ S(h2, `M${px - r} ${py} Q${px - r * 0.8} ${py - 2.6} ${px - r * 0.3} ${py - 2.2} Q${px} ${py - 3.4} ${px + r * 0.4} ${py - 2.4} Q${px + r} ${py - 2.2} ${px + r} ${py} Q${px} ${py + 1} ${px - r} ${py}Z`, SP * 0.6);
+ P(h2, Array.from({ length: 4 }, (_, k) => `M${f(px - r * 0.6 + k * r * 0.4)} ${py - 0.5} l0.6 -1.4`).join(' '), SP * 0.35);
+ });
+ }
+ else { P(h2, `M${x - 2} 336 L${x - 2} 300 M${x + 2} 336 L${x + 2} 300 M${x - 3} 312 L${x + 3} 312 M${x - 3} 324 L${x + 3} 324`, SP * 0.5); P(h2, `M${x} 334 q-4 -8 1 -14 q4 -6 -1 -12 q-3 -4 1 -8`, SP * 0.5); [[x - 3, 316], [x + 3, 306], [x - 2, 326]].forEach(([fx, fy]) => S(h2, oval(fx, fy, 2.2, 1.8), SP * 0.5)); }
+ });
+ // fūrin under the main eave
+ const furinG = g(h2);
+
+ // ================= H3 · tea house (茶屋) x 482–704
+ const h3 = g(hg);
+ S(h3, rect(496, 224, 690, 256));
+ roof(h3, { x0: 476, x1: 710, eave: 228, ridge: 196, inset: 24 });
+ mushiko(h3, 520, 232, 668, 250);
+ S(h3, rect(486, 264, 700, BASE));
+ roof(h3, { x0: 478, x1: 708, eave: 268, ridge: 256, inset: 5, tile: 5, sori: 1.6, oni: false });
+ // open shop front: interior (lights up), counter, menu tags, sudare
+ windows.push(pane(h3, glow, 492, 272, 614, 330, { thr: 0.02, lateOff: 0.94 }));
+ P(h3, 'M496 308 L610 308', SP * 0.55);
+ const tags = ['だんご', '甘酒', '抹茶', 'おしるこ', '草餅'];
+ tags.forEach((s, i) => { const x = 506 + i * 22; P(h3, `M${x} 283 L${x} 285.5`, SP * 0.4); S(h3, rect(x - 5, 285.5, x + 5, 307), SP * 0.6); text(h3, x, 296.2, s, 4.6, { vertical: true, weight: 700 }); });
+ S(h3, rect(490, 318, 616, 324), SP * 0.9); // counter
+ P(h3, 'M494 324 L494 344 M612 324 L612 344', SP * 0.7);
+ // dango on a plate on the counter
+ [528, 574].forEach((x) => { S(h3, `M${x - 9} 318 Q${x} 321 ${x + 9} 318 Z`, SP * 0.6); P(h3, `M${x - 7} 315 L${x + 8} 307`, SP * 0.6); [0, 1, 2].forEach((k) => S(h3, oval(x - 4 + k * 4.4, 313.5 - k * 2.4, 2.3, 2.3), SP * 0.6)); });
+ const sudare = g(h3);
+ S(sudare, rect(490, 270, 616, 282), SP * 0.7);
+ P(sudare, Array.from({ length: 5 }, (_, i) => `M490 ${272 + i * 2} L616 ${272 + i * 2}`).join(' ') + ' M520 268 L520 284 M586 268 L586 284', SP * 0.35);
+ S(sudare, `M488 268.5 a2.5 2.5 0 0 0 0 5 L618 273.5 a2.5 2.5 0 0 0 0 -5Z`, SP * 0.7);
+ // entrance with noren
+ S(h3, rect(620, 270, 694, BASE), SP * 0.9);
+ windows.push(pane(h3, glow, 622, 272, 692, BASE - 1, { thr: 0.02, lateOff: 0.95 }));
+ norens.push(noren(h3, 624, 690, 271, 24, 4, '茶', { open: [0.31, 0.9] }));
+ lanterns.push(chochin(h3, glow, 498, 268, { r: 6.4, h: 15, label: '茶', red: true }));
+ lanterns.push(chochin(h3, glow, 696, 268, { r: 6.4, h: 15, label: '茶', red: true }));
+ // bench (shōgi) and the red parasol (nodategasa) out front
+ const out = g(front);
+ S(out, `M586 351 L586 296 M589 351 L589 296`, SP * 0.6);
+ P(out, 'M587.5 352 L587.5 262', SP * 0.9);
+ let rimD = 'M536 273 Q548 256 587.5 252 Q627 256 639 273';
+ for (let i = 12; i > 0; i--) { const xa = lerp(536, 639, i / 12), xb = lerp(536, 639, (i - 1) / 12); rimD += ` Q${f((xa + xb) / 2)} 276.4 ${f(xb)} 273`; }
+ const parasol = el('path', { d: rimD + 'Z', fill: rgb(RED), stroke: 'currentColor', 'stroke-width': SP * 0.8 }, out);
+ P(out, Array.from({ length: 13 }, (_, i) => `M587.5 252.6 L${f(lerp(538, 637, i / 12))} 272.4`).join(' '), SP * 0.35);
+ S(out, oval(587.5, 252, 3.2, 1.6), SP * 0.6);
+ const benchTop = el('path', { d: rect(516, 330, 600, 336), fill: rgb(RED), stroke: 'currentColor', 'stroke-width': SP * 0.8 }, out);
+ S(out, rect(514, 336, 602, 339), SP * 0.7);
+ P(out, 'M520 339 L520 352 M596 339 L596 352 M522 339 L522 352 M594 339 L594 352 M520 348 L596 348', SP * 0.7);
+ // a teacup and a plate left on the bench
+ S(out, 'M584 330 L585 325 L591 325 L592 330Z', SP * 0.6);
+
+ // ================= H4 · public bath (銭湯) x 704–948
+ const h4 = g(hg);
+ // chimney behind the roof
+ const chim = g(back);
+ S(chim, 'M893 252 L895 72 L907 72 L909 252Z', SP);
+ P(chim, 'M894.3 100 L907.7 100 M894 130 L908 130 M893.7 170 L908.3 170 M893.4 210 L908.6 210', SP * 0.55);
+ S(chim, rect(892, 66, 910, 72), SP * 0.9);
+ text(chim, 901, 150, 'ゆ', 9, { weight: 800 });
+ S(h4, rect(708, 252, 944, BASE));
+ roof(h4, { x0: 700, x1: 952, eave: 256, ridge: 214, inset: 44 });
+ // karahafu: undulating gable over the entrance
+ S(h4, 'M766 262 Q780 262 790 250 Q806 226 826 222 Q846 226 862 250 Q872 262 886 262 L882 268 Q870 268 860 258 Q846 236 826 232 Q806 236 792 258 Q782 268 770 268Z', SP);
+ P(h4, 'M790 252 Q806 230 826 226 Q846 230 862 252', SP * 0.5);
+ S(h4, 'M821 222 Q826 214 831 222Z', SP * 0.7);
+ P(h4, 'M800 262 L800 344 M852 262 L852 344', SP);
+ windows.push(pane(h4, glow, 803, 266, 849, BASE - 1, { thr: 0.0, lateOff: 9 }));
+ norens.push(noren(h4, 804, 848, 266, 30, 2, 'ゆ', { open: [0.6, 1.08], red: false }));
+ // clerestory windows
+ windows.push(pane(h4, glow, 716, 266, 774, 292, { thr: 0.05, lateOff: 9 }));
+ windows.push(pane(h4, glow, 878, 266, 936, 292, { thr: 0.05, lateOff: 9 }));
+ [[716, 774], [878, 936]].forEach(([a, b]) => shojiGrid(h4, a, 266, b, 292, 6, 2));
+ // signboard + wainscot
+ S(h4, rect(714, 300, 734, 344), SP * 0.9);
+ text(h4, 724, 322, '松の湯', 9, { vertical: true, weight: 800 });
+ const ws = [];
+ for (let x = 740; x < 800; x += 4) ws.push(`M${x} 304 L${x} 344`);
+ for (let x = 856; x < 940; x += 4) ws.push(`M${x} 304 L${x} 344`);
+ P(h4, ws.join(' ') + ' M738 304 L800 304 M852 304 L940 304', SP * 0.5);
+ // bucket pyramid (yellow bath pails)
+ const pail = (x, y) => { const n = el('path', { d: `M${x - 6} ${y} L${x + 6} ${y} L${x + 5} ${y + 9} L${x - 5} ${y + 9}Z`, fill: '#e9c45a', stroke: 'currentColor', 'stroke-width': SP * 0.7 }, h4); P(h4, `M${x - 5.6} ${y + 2.4} L${x + 5.6} ${y + 2.4}`, SP * 0.4); return n; };
+ const pails = [pail(902, 335), pail(915, 335), pail(928, 335), pail(908.5, 326), pail(921.5, 326), pail(915, 317)];
+ // lanterns at the bath
+ lanterns.push(chochin(h4, glow, 790, 262, { r: 5.6, h: 13, label: 'ゆ' }));
+ lanterns.push(chochin(h4, glow, 862, 262, { r: 5.6, h: 13, label: 'ゆ' }));
+
+ // ---------- utility pole, wires, street lamp (in front of the alley)
+ const pole = g(front);
+ S(pole, 'M465 352 L466.5 98 L470.5 98 L472 352Z', SP * 0.9);
+ P(pole, 'M466 140 L471 140 M466 200 L471 200 M466 260 L471 260 M466 320 L471 320', SP * 0.5);
+ S(pole, rect(446, 110, 490, 114), SP * 0.8);
+ [450, 458, 478, 486].forEach((x) => S(pole, `M${x - 1.6} 110 L${x + 1.6} 110 L${x + 1.2} 105 L${x - 1.2} 105Z`, SP * 0.5));
+ S(pole, 'M472 140 Q480 140 480 146 L480 170 Q480 176 472 176Z', SP * 0.8); // transformer
+ P(pole, 'M472 150 L479 150 M472 160 L479 160', SP * 0.45);
+ // lamp arm
+ P(pole, 'M466 226 Q452 222 446 230', SP * 0.8);
+ S(pole, 'M439 230 L453 230 L450 236 L442 236Z', SP * 0.8);
+ const streetLamp = el('ellipse', { cx: 446, cy: 237, rx: 3, ry: 1.6, fill: PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.5 }, pole);
+ const lampCone = el('path', { d: 'M441 237 L451 237 L496 352 L396 352Z', fill: 'url(#v-cone)', opacity: 0 }, glow);
+ const cone = el('linearGradient', { id: 'v-cone', x1: 0, y1: 0, x2: 0, y2: 1 }, defs);
+ el('stop', { offset: 0, 'stop-color': '#ffe2a8', 'stop-opacity': 0.5 }, cone);
+ el('stop', { offset: 1, 'stop-color': '#ffe2a8', 'stop-opacity': 0.06 }, cone);
+ const lampGlow = el('circle', { cx: 446, cy: 237, r: 34, fill: 'url(#v-warmglow)', opacity: 0 }, glow);
+ // wires sag to both sides; sparrows sit on the right-hand wire
+ const wireY = (x) => { if (x >= 488) { const u = (x - 488) / (970 - 488); return 112 + (108 - 112) * u + 26 * 4 * u * (1 - u); } const u = (446 - x) / (446 + 10); return 112 + (104 - 112) * u + 22 * 4 * u * (1 - u); };
+ const wires = g(back);
+ const wd = [];
+ for (const [a, b, off] of [[488, 970, 0], [446, -10, 0], [488, 970, 7], [446, -10, 7]]) {
+ const pts = []; for (let k = 0; k <= 30; k++) { const x = lerp(a, b, k / 30); pts.push([x, wireY(x) + off * (1 + 0.3 * Math.sin(k))]); }
+ wd.push('M' + pts.map(pt).join('L'));
+ }
+ P(wires, wd.join(' '), SP * 0.5);
+
+ // ---------- the street itself
+ const street = g(front);
+ P(street, `M0 ${BASE} L960 ${BASE}`, SP);
+ const cracks = [];
+ for (let i = 0; i < 34; i++) { const x = srnd(0, 960), y = srnd(350, 380); cracks.push(`M${f(x)} ${f(y)} l${f(srnd(6, 16))} ${f(srnd(-0.4, 0.4))}`); }
+ P(street, cracks.join(' '), SP * 0.45);
+ // stone gutter slabs along the houses
+ const gut = [];
+ for (let x = 0; x < 960; x += srnd(16, 26)) gut.push(`M${f(x)} ${BASE} L${f(x)} ${BASE + 4}`);
+ P(street, `M0 ${BASE + 4} L960 ${BASE + 4} ` + gut.join(' '), SP * 0.5);
+
+ // ---------- fūrin (wind chime) under H2's eave
+ const furin = (() => {
+ const x = 412, y = 207;
+ const grp = g(furinG);
+ const cord = pen(grp, SP * 0.45), bell = el('path', { fill: '#e8f2f4', stroke: 'currentColor', 'stroke-width': SP * 0.7 }, grp);
+ const clap = pen(grp, SP * 0.45), strip = el('path', { fill: PAPER, stroke: 'currentColor', 'stroke-width': SP * 0.55 }, grp);
+ const rings = pen(grp, SP * 0.5);
+ let a = 0, v = 0, sa = 0, sv = 0, ring = 0;
+ return {
+ x, y,
+ draw(t, dt, wind) {
+ v += (-a * 14 + wind * 0.9 + wobble(t * 0.7) * 0.4 - v * 1.4) * dt; a += v * dt;
+ sv += (-(sa - a * 1.6) * 9 + wind * 2.2 + Math.sin(t * 2.3) * 0.6 - sv * 1.6) * dt; sa += sv * dt;
+ ring = Math.max(0, ring - dt * 0.9);
+ const bx = x + Math.sin(a) * 6, by = y + Math.cos(a) * 6;
+ cord.setAttribute('d', `M${x} ${y - 3} L${f(bx)} ${f(by)}`);
+ bell.setAttribute('d', `M${f(bx - 4)} ${f(by + 5)} Q${f(bx - 4.2)} ${f(by - 0.6)} ${f(bx)} ${f(by - 0.6)} Q${f(bx + 4.2)} ${f(by - 0.6)} ${f(bx + 4)} ${f(by + 5)}Z`);
+ const cx = bx + Math.sin(sa) * 4, cy = by + 5 + Math.cos(sa) * 4;
+ clap.setAttribute('d', `M${f(bx)} ${f(by)} L${f(cx)} ${f(cy)} M${f(cx - 0.8)} ${f(cy)} l1.6 0`);
+ const sx = cx + Math.sin(sa) * 9, sy = cy + Math.cos(sa) * 9;
+ strip.setAttribute('d', `M${f(cx - 1.6)} ${f(cy + 1)} L${f(cx + 1.6)} ${f(cy + 1)} L${f(sx + 1.6)} ${f(sy)} L${f(sx - 1.6)} ${f(sy)}Z`);
+ rings.setAttribute('d', ring > 0.02 ? [7, 11].map((r) => `M${f(bx - r * 0.7)} ${f(by - r * 0.1 - 4)} Q${f(bx)} ${f(by - r - 4)} ${f(bx + r * 0.7)} ${f(by - r * 0.1 - 4)}`).join(' ') : '');
+ rings.setAttribute('opacity', f(ring));
+ },
+ poke() { v += 2.4; sv += 6; ring = 1; },
+ ring() { ring = 1; },
+ get swing() { return sv; },
+ };
+ })();
+
+ // ---------- the shoji someone opens
+ const shoji = (() => {
+ let s = -1;
+ return {
+ hit: rect(260, 210, 320, 252),
+ poke() { if (s < 0) s = 0; },
+ draw(t, dt, P_) {
+ let open = 0;
+ if (s >= 0) { s += dt; open = s < 0.6 ? ease(s / 0.6) : s < 4.4 ? 1 : 1 - ease((s - 4.4) / 0.6); if (s > 5) s = -1; }
+ slide.setAttribute('transform', `translate(${f(-open * 27.5)} 0)`);
+ interior.setAttribute('opacity', f(open > 0.001 ? 1 : 0));
+ const lit = shojiWin.lit;
+ room.setAttribute('fill', rgb(mix(hex('#4a3a2c'), hex('#f0a85a'), lit * 0.85)));
+ // the person leans into view and waves
+ const lean = ease(clamp((s - 0.4) / 0.6, 0, 1)) * (1 - ease(clamp((s - 4.0) / 0.5, 0, 1)));
+ person.setAttribute('transform', `translate(${f((1 - lean) * 22)} 0)`);
+ const wv = Math.sin(Math.max(0, s - 1) * 9) * 0.5 * lean;
+ const sh = [297, 238], el2 = [293, 231], hand = [293 + Math.sin(wv) * 5, 222 - Math.cos(wv) * 2];
+ waveArm.draw([sh, el2, hand], [0.2, 0.2]);
+ slidePane.setAttribute('fill', rgb(mix(P_.paper, WARM, lit * 0.9)));
+ },
+ };
+ })();
+
+ return {
+ windows, lanterns, norens, furin, shoji, blossoms, canopy, pails,
+ parasol, benchTop, alleyLamp,
+ bench: { x0: 518, x1: 598, y: 330 },
+ chimney: [901, 64] as [number, number],
+ wireY,
+ lamp: { node: streetLamp, cone: lampCone, glow: lampGlow, x: 446, y: 237 },
+ applyRed(P_) {
+ const c = rgb(mix(RED, RED_NIGHT, P_.inkT));
+ parasol.setAttribute('fill', c); benchTop.setAttribute('fill', c);
+ pails.forEach((p) => p.setAttribute('fill', rgb(mix(hex('#e9c45a'), hex('#6d6240'), P_.inkT))));
+ },
+ };
+}
diff --git a/examples/village/index.html b/examples/village/index.html
new file mode 100644
index 0000000..f7af018
--- /dev/null
+++ b/examples/village/index.html
@@ -0,0 +1,25 @@
+<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Ink Village</title>
+<meta name="description" content="A Japanese street in hand-inked line, alive from dawn to night.">
+<style>
+ html,body{margin:0;height:100%;overflow:hidden;background:#ebe8e2}
+ body{display:grid;place-items:center}
+ /* the scene is a self-contained card; the page around it never changes */
+ .card{position:relative;width:min(94vw,calc((100vh - 48px) * 2));aspect-ratio:2/1;border-radius:18px;overflow:hidden;
+ box-shadow:0 1px 0 rgba(255,255,255,.7) inset,0 0 0 1px rgba(40,34,26,.10),0 18px 50px -18px rgba(40,34,26,.35),0 4px 14px -6px rgba(40,34,26,.18);
+ --ink:#1c1c1c;touch-action:none;isolation:isolate}
+ #village,#village svg{display:block;width:100%;height:100%;user-select:none;-webkit-user-select:none}
+ #village svg .pp{fill:var(--paper,#fdfdfc)}
+ #village svg.scrubbing,#village svg.scrubbing *{cursor:grabbing!important}
+ .hud{position:absolute;left:2.2%;top:3.4%;font:500 clamp(10px,1.25vw,15px)/1.3 "Iowan Old Style","Hiragino Mincho ProN","Yu Mincho",Georgia,serif;color:var(--ink);letter-spacing:.04em;pointer-events:none;opacity:.85}
+ .hud b{font-weight:600;font-variant-numeric:tabular-nums;letter-spacing:.06em}
+ .hud span{margin-left:6px;font-size:.9em}
+ #hint{position:absolute;left:0;right:0;bottom:3%;margin:0;text-align:center;font:italic clamp(10px,1.2vw,14px)/1.4 "Iowan Old Style",Georgia,serif;color:var(--ink);opacity:.75;pointer-events:none;transition:opacity 1.2s}
+ #hint.gone{opacity:0}
+ .capture #hint{display:none}
+</style></head><body>
+<div class="card" id="card">
+ <div id="village"></div>
+ <div class="hud" id="clock"></div>
+ <p id="hint">drag the sun across the sky · click anyone and anything</p>
+</div>
+<script type="module" src="./main.ts"></script></body></html>
diff --git a/examples/village/kit.ts b/examples/village/kit.ts
new file mode 100644
index 0000000..bf48883
--- /dev/null
+++ b/examples/village/kit.ts
@@ -0,0 +1,45 @@
+// Shared constants and small helpers for the ink village.
+
+// The scene sets many numeric attributes; let setAttribute take numbers (the DOM stringifies them).
+declare global { interface Element { setAttribute(qualifiedName: string, value: string | number): void } }
+export const W = 960, H = 480;
+export const BASE = 344; // house fronts / back edge of the street
+export const LANE = { back: 360, mid: 366, front: 372 }; // feet lines on the street
+export const EDGE = 384; // canal coping top
+export const WATER = 400; // water surface
+export const SP = 0.8; // scene pen
+export const FS = 0.5; // figure scale (figures are drawn ~95 px tall, ground 120)
+
+export const rnd = (a, b) => a + Math.random() * (b - a);
+export const pick = (arr) => arr[(Math.random() * arr.length) | 0];
+export const clamp = (x, a, b) => Math.max(a, Math.min(b, x));
+export const lerp = (a, b, t) => a + (b - a) * t;
+export const smooth = (e0, e1, x) => { const t = clamp((x - e0) / (e1 - e0), 0, 1); return t * t * (3 - 2 * t); };
+export const ease = (t) => smooth(0, 1, t);
+export const easeOut = (t) => 1 - Math.pow(1 - clamp(t, 0, 1), 3);
+export const oval = (cx, cy, rx, ry) => `M${(cx - rx).toFixed(2)} ${cy.toFixed(2)} a${rx} ${ry} 0 1 0 ${2 * rx} 0 a${rx} ${ry} 0 1 0 ${-2 * rx} 0Z`;
+
+// deterministic randomness for the static drawing, so the street is the same every load
+let seed = 11;
+export const srnd = (a, b) => { seed = (seed * 16807) % 2147483647; return a + ((seed - 1) / 2147483646) * (b - a); };
+
+// colours
+export const hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
+export const rgb = (c) => `rgb(${c.map((v) => Math.round(v)).join(',')})`;
+export const mix = (a, b, t) => a.map((v, i) => v + (b[i] - v) * t);
+export const lum = (c) => (0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]) / 255;
+
+/** Sample a cyclic colour ramp [[pos, '#hex'], ...] at u in [0,1). */
+export function ramp(keys, u) {
+ u = ((u % 1) + 1) % 1;
+ const n = keys.length;
+ let i = n - 1;
+ for (let j = 0; j < n; j++) if (keys[j][0] <= u) i = j;
+ const [p0, c0] = keys[i], [p1, c1] = keys[(i + 1) % n];
+ const span = (i + 1 < n ? p1 : p1 + 1) - p0;
+ let x = u - p0; if (x < 0) x += 1;
+ return mix(hex(c0), hex(c1), ease(x / span));
+}
+
+/** Simple layered noise for organic motion (no deps). */
+export const wobble = (t, k = 1) => Math.sin(t * 1.3 * k) * 0.6 + Math.sin(t * 2.7 * k + 1.7) * 0.3 + Math.sin(t * 5.1 * k + 4.1) * 0.1;
diff --git a/examples/village/main.ts b/examples/village/main.ts
new file mode 100644
index 0000000..d957966
--- /dev/null
+++ b/examples/village/main.ts
@@ -0,0 +1,172 @@
+// Ink village — a Japanese street from dawn to night, drawn in pen.
+// Drag the sun or moon to change the time; move the pointer to make wind;
+// click people, windows, lanterns, the fūrin, the cat, the birds, the water.
+import { el, inkDefs, run, f } from '../../lib/ink.ts';
+import { W, H, LANE, WATER, rnd, pick, clamp, lerp, smooth, rgb, hex, mix } from './kit.ts';
+import { createSky, palette } from './sky.ts';
+import { buildStreet } from './houses.ts';
+import { buildCanal } from './canal.ts';
+import { createKimono, createCyclist, createKid, createBoat } from './people.ts';
+import { createCat, createSparrows, createSwallows, createPetals, createSmoke } from './critters.ts';
+
+const q = new URLSearchParams(location.search);
+const svg = el('svg', { viewBox: `0 0 ${W} ${H}`, class: 'village', role: 'img',
+ 'aria-label': 'An ink drawing of a Japanese street with machiya houses, a tea house and a public bath beside a canal, through day and night.' });
+const ink = inkDefs(svg, 'v');
+document.querySelector('#village').appendChild(svg);
+const defs = ink.defs;
+const grad = (id: string, stops: Array<[number, string, number]>, attrs: { radial?: boolean; x1?: number; x2?: number } = {}) => { const g = el(attrs.radial ? 'radialGradient' : 'linearGradient', attrs.radial ? { id } : { id, x1: attrs.x1 ?? 0, y1: 0, x2: attrs.x2 ?? 1, y2: 0 }, defs); stops.forEach(([o, c, a]) => el('stop', { offset: o, 'stop-color': c, 'stop-opacity': a }, g)); };
+grad('v-beamR', [[0, '#fff1c2', 0.55], [1, '#fff1c2', 0]]);
+grad('v-beamL', [[0, '#fff1c2', 0], [1, '#fff1c2', 0.55]]);
+grad('v-cateye', [[0, '#e8ff9a', 1], [1, '#c8ff6a', 0]], { radial: true });
+
+const layer = (parent: Element = svg, attrs: Record<string, string> = {}) => el('g', attrs, parent);
+const skyL = layer();
+const scene = layer(svg, { filter: ink.filter });
+const back = layer(scene), birdsL = layer(scene), ground = layer(scene), houses = layer(scene), front = layer(scene);
+const catL = layer(scene), walkers = layer(scene), canalL = layer(scene), boatL = layer(scene), willowL = layer(scene), petalL = layer(scene, { style: 'pointer-events:none' });
+const glow = layer(svg, { style: 'mix-blend-mode:screen;pointer-events:none' });
+
+// ------------------------------------------------------------------ time
+let tau = q.has('tau') ? +q.get('tau') : q.has('start') ? +q.get('start') : 0.66; // ?tau pins the time, ?start just sets it
+let scrub = null, frozenTau = q.has('tau');
+const DAY_SECONDS = q.has('day') ? +q.get('day') : 180; // ?day=30 → a full cycle in 30 s
+// People always move at a natural pace (a sped-up gait looks fake); when a day is
+// compressed only the arrivals come more often, so the street stays busy. ?life= overrides.
+const LIFE = q.has('life') ? +q.get('life') : 1;
+const TRAFFIC = Math.max(1, Math.sqrt(180 / DAY_SECONDS));
+const card = document.querySelector<HTMLElement>('#card')!;
+if (q.has('capture')) document.body.classList.add('capture');
+
+// ------------------------------------------------------------------ wind from the pointer
+let wind = 0.3, windTarget = 0.3, lastX = null, lastT = 0;
+svg.addEventListener('pointermove', (e) => {
+ const now = performance.now();
+ if (lastX !== null && !svg.classList.contains('scrubbing')) windTarget = clamp(windTarget + ((e.clientX - lastX) / Math.max(8, now - lastT)) * 0.8, -2.4, 2.4);
+ lastX = e.clientX; lastT = now;
+});
+const on = (node, fn) => node.addEventListener('pointerdown', (e) => { e.stopPropagation(); fn(e); hint.done(); });
+const toSvg = (e) => { const p = svg.createSVGPoint(); p.x = e.clientX; p.y = e.clientY; return p.matrixTransform(svg.getScreenCTM().inverse()); };
+
+// ------------------------------------------------------------------ world
+const sky = createSky(svg, skyL, defs, {
+ onScrub: (v) => { scrub = v; if (v !== null) { tau = v; frozenTau = false; hint.done(); } },
+ onShoot: () => palette(tau).night > 0.4,
+});
+const street = buildStreet({ back, houses, front, glow }, defs);
+const canal = buildCanal({ ground, canalL, willowL, glow }, defs);
+const smoke = createSmoke(back, street.chimney);
+const sparrows = createSparrows(birdsL, { wireY: street.wireY });
+const swallows = createSwallows(birdsL);
+const petals = createPetals(petalL, { blossoms: street.blossoms, canal });
+const cat = createCat(catL, glow, { x: 548, y: 330 });
+const boat = createBoat(boatL, glow, { onRipple: (x, y) => canal.ring(x, y, 2) });
+
+// reflections in the water under every light source
+street.windows.forEach((w) => canal.addRefl(() => w.lit, (w.x0 + w.x1) / 2, Math.min(40, (w.x1 - w.x0) * 0.8)));
+street.lanterns.forEach((l) => canal.addRefl(() => smooth(l.thr, l.thr + 0.2, P.lamp), l.x, 8));
+canal.addRefl(() => smooth(0.2, 0.45, P.lamp), 446, 14);
+
+// interactions on the scenery
+street.lanterns.forEach((l) => { l.grp.style.cursor = 'pointer'; on(l.grp, () => l.poke()); });
+street.norens.forEach((n) => { n.grp.style.cursor = 'pointer'; on(n.grp, () => n.poke()); });
+const hits = layer(scene);
+const hitPath = (d, title, fn) => { const n = el('path', { d, fill: 'transparent', style: 'cursor:pointer' }, hits); el('title', {}, n).textContent = title; on(n, fn); return n; };
+hitPath(street.shoji.hit, 'Knock on the window', () => street.shoji.poke());
+hitPath('M402 202 L422 202 L422 236 L402 236Z', 'Ring the wind chime', () => street.furin.poke());
+let shake = 0;
+street.canopy.style.cursor = 'pointer';
+on(street.canopy, () => { shake = 1; petals.burst(46); });
+on(sparrows.hit, () => sparrows.flush());
+on(cat.hit, () => cat.poke());
+on(boat.g, () => boat.poke());
+willowL.style.cursor = 'pointer';
+on(willowL, () => canal.willowPoke());
+const waterHit = el('rect', { x: 0, y: WATER, width: W, height: H - WATER, fill: 'transparent', style: 'cursor:pointer' }, canalL);
+on(waterHit, (e) => { const p = toSvg(e); canal.poke(p.x, p.y); });
+canalL.insertBefore(waterHit, canalL.children[2] || null);
+
+// ------------------------------------------------------------------ villagers
+const people = [];
+const spawn = { kimono: 0, bike: 7, kid: 4 };
+function addPerson(kind: 'kimono' | 'bike' | 'kid', x?: number) {
+ const dir = Math.random() < 0.5 ? 1 : -1;
+ const sx = x ?? (dir > 0 ? -60 : W + 60);
+ let p;
+ if (kind === 'kimono') p = createKimono(walkers, glow, { dir, x: sx, y: LANE.back + rnd(-1, 1), lantern: P.lamp > 0.5 });
+ if (kind === 'bike') p = createCyclist(walkers, glow, { dir, x: sx, y: LANE.front + rnd(-1, 1) });
+ if (kind === 'kid') p = createKid(walkers, glow, { dir, x: sx, y: LANE.mid + rnd(-1, 1) });
+ on(p.g, () => { p.poke(); if (p.kind === 'bike') setTimeout(() => sparrows.flush(), 150); });
+ people.push(p);
+}
+
+// ------------------------------------------------------------------ hud
+const clock = document.querySelector('#clock'), hintN = document.querySelector('#hint');
+const hint = { shown: true, done() { if (this.shown) { this.shown = false; hintN.classList.add('gone'); } } };
+setTimeout(() => hint.done(), 14000);
+const period = (h) => (h < 4 ? '深夜' : h < 6 ? '夜明け' : h < 10 ? '朝' : h < 15 ? '昼' : h < 17.5 ? '午後' : h < 19.5 ? '夕暮れ' : '夜');
+
+// ------------------------------------------------------------------ frame
+let P = palette(tau);
+let started = false;
+run((t, dt) => {
+ dt = dt || 1 / 60;
+ if (scrub === null && !frozenTau) tau = (tau + dt / DAY_SECONDS) % 1;
+ P = palette(tau);
+ svg.style.color = rgb(P.ink);
+ svg.style.setProperty('--paper', rgb(P.paper));
+ card.style.setProperty('--ink', rgb(P.ink));
+
+ windTarget = lerp(windTarget, 0.3 + 0.25 * Math.sin(t * 0.21) + 0.15 * Math.sin(t * 0.67), 0.012);
+ wind = lerp(wind, windTarget, 0.05);
+
+ sky.draw(tau, t, dt, P, wind);
+ street.applyRed(P);
+ const sinceDusk = (tau - 0.75 + 1) % 1;
+ street.windows.forEach((w) => {
+ let lit = smooth(w.thr, w.thr + 0.25, P.lamp);
+ if (w.lateOff < 9 && sinceDusk > w.lateOff - 0.75 && sinceDusk < 0.5) lit = 0;
+ w.lit = lerp(w.lit, lit, 0.08);
+ w.n.style.fill = rgb(mix(P.paper, mix(hex('#ffd58a'), hex('#f0a24e'), w.warmth), w.lit * 0.92));
+ w.glow.setAttribute('opacity', f(w.lit * 0.8));
+ });
+ const L = street.lamp, lampOn = smooth(0.2, 0.45, P.lamp);
+ L.node.style.fill = rgb(mix(P.paper, hex('#fff1c9'), lampOn));
+ L.cone.setAttribute('opacity', f(lampOn * 0.75));
+ L.glow.setAttribute('opacity', f(lampOn));
+
+ street.norens.forEach((n) => n.draw(t, dt, wind, tau, P));
+ street.lanterns.forEach((l) => l.draw(t, dt, wind, P));
+ street.furin.draw(t, dt, wind);
+ street.shoji.draw(t, dt, P);
+ shake = Math.max(0, shake - dt * 1.5);
+ street.canopy.setAttribute('transform', `translate(${f(Math.sin(t * 40) * shake * 2.4 + wind * 0.9)} ${f(Math.cos(t * 31) * shake * 1.2)})`);
+
+ smoke.draw(t, dt, P, wind, tau);
+ sparrows.draw(t, dt, P);
+ swallows.draw(t, dt, P);
+ petals.draw(t, dt, P, wind);
+ cat.draw(t, dt, P);
+ canal.draw(t, dt, P, wind, null, tau, lampOn);
+ boat.draw(t, dt * LIFE, P, wind);
+
+ // villagers: spawn on their own schedules, draw back-to-front
+ if (!started) { started = true; addPerson('kimono', 300); addPerson('kimono', 760); addPerson('bike', 560); }
+ const dayish = tau > 0.28 && tau < 0.72, lateNight = tau > 0.96 || tau < 0.22;
+ for (const k in spawn) {
+ spawn[k] -= dt * TRAFFIC;
+ if (spawn[k] < 0) {
+ if (k === 'kimono') { spawn[k] = rnd(10, 18); if (!lateNight || Math.random() < 0.3) addPerson('kimono'); }
+ if (k === 'bike') { spawn[k] = rnd(9, 16); if (!lateNight) addPerson('bike'); }
+ if (k === 'kid') { spawn[k] = rnd(14, 24); if (dayish) addPerson('kid'); }
+ }
+ }
+ for (let i = people.length - 1; i >= 0; i--) { const p = people[i]; p.draw(t, dt * LIFE, P, wind); if (p.done) { p.remove(); people.splice(i, 1); } else if (p.ringing && Math.random() < dt * 4) sparrows.flush(); }
+ people.slice().sort((a, b) => a.y - b.y).forEach((p) => walkers.appendChild(p.g));
+
+ // clock
+ const hrs = tau * 24, h = Math.floor(hrs), m = Math.floor((hrs - h) * 60);
+ clock.innerHTML = `<b>${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}</b> <span>${period(hrs)}</span>`;
+});
+
+(window as unknown as { __village: unknown }).__village = { addPerson, setTau: (v) => { tau = v; frozenTau = true; }, get tau() { return tau; }, people, sparrows, cat, boat, canal, street, petals };
diff --git a/examples/village/people.ts b/examples/village/people.ts
new file mode 100644
index 0000000..0513c9f
--- /dev/null
+++ b/examples/village/people.ts
@@ -0,0 +1,428 @@
+// Villagers. Each is drawn in its own space (~95 px tall, ground y 120, facing +x,
+// feet centred on x 40) and placed with translate/scale, so line weight matches.
+import { el, pen, shape, blot, f, pt, limb, joint, curve, PEN, PAPER } from '../../lib/ink.ts';
+import { FS, WATER, rnd, pick, clamp, lerp, smooth, ease, oval, rgb, hex, mix } from './kit.ts';
+
+const RAD = Math.PI / 180;
+const place = (g, X, Y, dir, s = FS) => g.setAttribute('transform', `translate(${f(X)} ${f(Y)}) scale(${f(dir * s)} ${f(s)}) translate(-40 -120)`);
+const world = (X, Y, dir, lx, ly, s = FS) => [X + dir * s * (lx - 40), Y + s * (ly - 120)];
+const fillOf = (c, P, k = 0.55) => rgb(mix(hex(c), mix(hex(c), [12, 16, 30], 0.6), P.inkT * k));
+const solid = (lb, c = 'currentColor') => { const n = lb.g.querySelector('path'); n.classList.remove('pp'); n.setAttribute('fill', c); return lb; };
+const paintPath = (g, c, w = PEN) => el('path', { fill: c, stroke: 'currentColor', 'stroke-width': w, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' }, g);
+
+// ===================================================================== woman in kimono
+// A real gait under the kimono: two hidden legs (thigh 23, shin 23) walk at a
+// natural 2 steps/s. The planted foot slides back at exactly the travel speed;
+// the swinging foot follows a minimum-jerk path with a low geta lift; the heel
+// peels off the front tooth before each swing. Hip height is whatever both
+// planted legs can reach, so the body rises over each step and dips at double
+// support. The kimono is then drawn around the forward knee and both ankles,
+// so the cloth opens and closes with the stride; sleeves swing on springs.
+export function createKimono(parent, glow, { dir = 1, x, y, lantern = false }) {
+ const g = el('g', { style: 'cursor:pointer' }, parent);
+ const T = 1.0, DUTY = 0.62, S = 24, LEG = 45.2;
+ const speed = (S / (DUTY * T)) * FS; // scene px/s; matches the planted foot
+ const colours = pick([['#34507a', '#d3a24c'], ['#7a4766', '#cfd3c2'], ['#4f6b55', '#c58a4a'], ['#8a5a3c', '#2f3f5f']]);
+ const [kimonoC, obiC] = colours;
+ const parasolC = pick(['#2f4d5c', '#7b2f2f', '#2f3d2f']);
+
+ const feet = [0, 1].map(() => ({ tabi: shape(g, PEN * 0.75), geta: blot(g) }));
+ const farSleeve = paintPath(g, kimonoC);
+ const lower = paintPath(g, kimonoC);
+ const okumi = pen(g, PEN * 0.6), crease = pen(g, PEN * 0.45);
+ const patternLow = el('path', { fill: 'none', stroke: '#f2ead8', 'stroke-width': PEN * 0.5 }, g);
+ const upperG = el('g', {}, g);
+ const upper = paintPath(upperG, kimonoC);
+ const pattern = el('path', { fill: 'none', stroke: '#f2ead8', 'stroke-width': PEN * 0.5 }, upperG);
+ const obi = paintPath(upperG, obiC), taiko = paintPath(upperG, obiC), cord = el('path', { stroke: '#b3412d', 'stroke-width': 1.1, fill: 'none' }, upperG);
+ const collar = shape(upperG, PEN * 0.8);
+ const neck = limb(upperG, 3.2);
+ const head = el('ellipse', { cx: 41, cy: 32, rx: 4.2, ry: 5.1, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN }, upperG);
+ const hair = blot(upperG);
+ const pin = pen(upperG, PEN * 0.7), pinBall = el('circle', { r: 1.1, fill: '#c9a24a', stroke: 'currentColor', 'stroke-width': 0.5 }, upperG);
+ const sleeve = paintPath(upperG, kimonoC);
+ const hand = el('ellipse', { rx: 1.8, ry: 1.5, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN * 0.7 }, upperG);
+ const prop = el('g', {}, upperG);
+ const pole = pen(prop, PEN * 0.9);
+ const canopyG = el('g', {}, prop);
+ const canopy = paintPath(canopyG, parasolC, PEN * 0.9), ring_ = el('path', { fill: 'none', stroke: '#f1e7d0', 'stroke-width': 2.4 }, canopyG), ribs = pen(canopyG, PEN * 0.4), cap = blot(canopyG);
+ const lanternG = el('g', {}, prop);
+ const lBody = el('path', { stroke: 'currentColor', 'stroke-width': PEN * 0.8 }, lanternG), lCaps = blot(lanternG), lRibs = pen(lanternG, PEN * 0.4);
+ const lGlow = el('circle', { r: 22, fill: 'url(#v-warmglow)', opacity: 0 }, glow);
+
+ const mj = (s) => s * s * s * (10 - 15 * s + 6 * s * s); // minimum-jerk
+ // foot pose over the cycle: ankle position + geta pitch (deg, toe down) + pivot
+ const foot = (u) => {
+ u = ((u % 1) + 1) % 1;
+ if (u < DUTY) {
+ const x = 40 + S / 2 - (S * u) / DUTY;
+ const heel = smooth(DUTY - 0.14, DUTY, u); // heel peels off the front tooth
+ const th = 15 * heel * RAD, px = x + 4.2, py = 120;
+ const ox = -4.2, oy = -4; // ankle relative to the toe pivot
+ return { a: [px + ox * Math.cos(th) - oy * Math.sin(th), py + ox * Math.sin(th) + oy * Math.cos(th)], pitch: 15 * heel, stance: true };
+ }
+ const s = (u - DUTY) / (1 - DUTY);
+ return { a: [40 - S / 2 + S * mj(s), 116 - 3.4 * Math.pow(Math.sin(Math.PI * s), 1.2)], pitch: 15 * Math.pow(1 - smooth(0, 0.55, s), 1.4), stance: false };
+ };
+ const getaPath = (ank, pitch) => {
+ const r = pitch * RAD, c = Math.cos(r), s = Math.sin(r);
+ const R = (px, py) => pt([ank[0] + px * c - py * s, ank[1] + px * s + py * c]);
+ return {
+ geta: `M${R(-4.4, 0.2)} L${R(5.2, 0.2)} L${R(5.2, 1.5)} L${R(3.8, 1.5)} L${R(3.8, 4)} L${R(2.4, 4)} L${R(2.4, 1.5)} L${R(-1.4, 1.5)} L${R(-1.4, 4)} L${R(-2.8, 4)} L${R(-2.8, 1.5)} L${R(-4.4, 1.5)}Z`,
+ tabi: `M${R(-3.4, 0.2)} Q${R(-3.7, -5)} ${R(-0.7, -5.6)} L${R(1.6, -5)} Q${R(4.7, -3.4)} ${R(4.8, 0.2)}Z`,
+ };
+ };
+ let ph = rnd(0, 1), hipS = 70.8, slv = 0, slvV = 0, tiltS = 0, tiltV = 0, lanA = 0, lanV = 0, bowT = -1, stop = 0;
+ return {
+ g, x, y, dir, speed, done: false,
+ poke() { if (bowT < 0) bowT = 0; },
+ draw(t, dt, P) {
+ // a polite bow: ease to a stop, bend from the waist, rise, walk on
+ let bow = 0;
+ if (bowT >= 0) { bowT += dt; bow = bowT < 0.7 ? 0 : bowT < 1.15 ? ease((bowT - 0.7) / 0.45) : bowT < 1.9 ? 1 : 1 - ease((bowT - 1.9) / 0.5); if (bowT > 2.6) bowT = -1; }
+ stop = clamp(stop + (bowT >= 0 && bowT < 2.4 ? dt : -dt) * 2.4, 0, 1);
+ const go = 1 - ease(stop);
+ ph += (dt / T) * go; this.x += dir * speed * dt * go;
+ if (this.x < -80 || this.x > 1040) this.done = true;
+ place(g, this.x, this.y, dir);
+
+ // legs (hidden) → hip height, knees, ankles
+ const F = [foot(ph), foot(ph + 0.5)];
+ if (go < 1) F.forEach((fo, i) => { const rest = 40 + (i ? -2 : 2); fo.a = [lerp(rest, fo.a[0], go), lerp(116, fo.a[1], go)]; fo.pitch *= go; });
+ let hipY = 70.8;
+ F.forEach((fo) => { if (fo.stance || go < 1) { const dx = fo.a[0] - 40; hipY = Math.max(hipY, fo.a[1] - Math.sqrt(Math.max(1, LEG * LEG - dx * dx))); } });
+ hipS = lerp(hipS, hipY, Math.min(1, dt * 18));
+ const hip = [40, hipS], b = hipS - 70.8;
+ const K = F.map((fo) => joint(hip, fo.a, 23, 23, 1));
+ F.forEach((fo, i) => { const p = getaPath(fo.a, fo.pitch); feet[i].geta.setAttribute('d', p.geta); feet[i].tabi.setAttribute('d', p.tabi); });
+ const iF = F[0].a[0] >= F[1].a[0] ? 0 : 1, iR = 1 - iF;
+ const aF = F[iF].a, aR = F[iR].a;
+ const kF = K[0][0] >= K[1][0] ? K[0] : K[1], kR = K[0][0] >= K[1][0] ? K[1] : K[0];
+ // swinging foot passes in front of the planted one
+ g.insertBefore(feet[iF].geta, farSleeve); g.insertBefore(feet[iF].tabi, feet[iF].geta);
+
+ // kimono below the obi, shaped by the knees and ankles
+ const wB = [31.8, 69 + b], wF = [47.8, 69.4 + b];
+ const hemF = [Math.max(46.6, aF[0] + 4.2), 112.6], hemR = [Math.min(31.4, aR[0] - 2.4), 113];
+ const kx = Math.max(kF[0] + 2.6, 47.4);
+ lower.setAttribute('d', `M${pt(wB)} L${pt(wF)} C${f(48.6)} ${f(80 + b)} ${f(kx)} ${f(kF[1] - 9)} ${f(kx)} ${f(kF[1])} Q${f(kx - 0.2)} ${f((kF[1] + hemF[1]) / 2 + 2)} ${pt(hemF)} Q${f((hemF[0] + hemR[0]) / 2)} ${f(113.6)} ${pt(hemR)} Q${f(Math.min(30.8, hemR[0] + 1.6))} ${f(92 + b * 0.5)} ${pt(wB)}Z`);
+ okumi.setAttribute('d', `M${f(44.4)} ${f(72 + b)} Q${f(kF[0] - 0.6)} ${f(kF[1] + 3)} ${f(Math.max(42, aF[0] + 0.8))} ${f(112.6)}`);
+ crease.setAttribute('d', `M${f(kR[0] + 1.6)} ${f(kR[1] - 4)} Q${f(kR[0] + 0.4)} ${f(kR[1] + 6)} ${f(Math.max(hemR[0] + 3, aR[0] + 1.4))} ${f(112.4)}`);
+ patternLow.setAttribute('d', [[36.4, 84], [41.6, 96], [36, 104], [42, 79]].map(([px, py]) => `M${px} ${f(py + b * 0.6)} a1.1 1.1 0 1 0 0.1 0`).join(' '));
+
+ // sleeves swing on springs, trailing a little while walking
+ const stepPh = 4 * Math.PI * ph;
+ slvV += (40 * ((-1.4 + Math.sin(stepPh - 1.1) * 0.9) * go - slv) - 6 * slvV) * dt; slv += slvV * dt;
+ tiltV += (30 * (Math.sin(stepPh - 0.8) * 1.6 * go - tiltS) - 5 * tiltV) * dt; tiltS += tiltV * dt;
+ farSleeve.setAttribute('d', `M${f(34)} ${f(47 + b)} Q${f(30 + slv * 0.5)} ${f(56 + b)} ${f(28.8 + slv)} ${f(74 + b)} Q${f(31 + slv)} ${f(77.6 + b)} ${f(34)} ${f(76 + b)}Z`);
+
+ // upper body rides on the hip, with a slight lean into the walk; bows from the waist
+ upperG.setAttribute('transform', `translate(0 ${f(b)}) rotate(${f(bow * 34 + 1.4 * go)} 40 68)`);
+ upper.setAttribute('d', 'M36 43 Q32 45.5 32.2 52 Q31.6 60 32 69 L47.6 69 Q48.4 56 46.6 48 Q45.4 44 43.4 43Z');
+ pattern.setAttribute('d', [[36, 55], [42, 50]].map(([px, py]) => `M${px} ${py} a1.1 1.1 0 1 0 0.1 0`).join(' '));
+ obi.setAttribute('d', 'M31.8 59 L47.8 59.5 L47.9 69.4 L31.7 69Z');
+ cord.setAttribute('d', 'M31.8 64.4 L47.9 64.6');
+ taiko.setAttribute('d', 'M32 57.5 L25.4 58.6 Q24.4 66 25.6 75 L32 74Z');
+ collar.setAttribute('d', 'M37.4 43.4 L41.6 53.4 L44.8 43.6 L43 43 L41.4 49 L39.2 43.2Z');
+ neck.draw([[40.6, 44], [40.8, 37]], [0.2, 0.2]);
+ hair.setAttribute('d', `M36.6 31 Q35.4 23.6 41 22.6 Q46.4 22.4 46 28.6 Q43.2 25.6 39.8 27 Q37.8 28.4 36.6 31Z ${oval(35.4, 31.4, 3, 3.8)} ${oval(40.2, 20.6, 3.8, 2.3)}`);
+ pin.setAttribute('d', 'M42.6 21.2 L47.4 17.6');
+ pinBall.setAttribute('cx', 47.6); pinBall.setAttribute('cy', 17.4);
+ sleeve.setAttribute('d', `M43.6 46 Q49.6 49 50.4 55 L${f(50.6 + slv * 0.5)} 72 Q${f(46 + slv)} 75.6 ${f(41.6 + slv)} 72.4 L41.6 54Z`);
+ if (!lantern && P.lamp > 0.62) lantern = true; // dusk caught her out: parasol down, lantern lit
+ const night = lantern;
+ const hx = 50.4, hy = night ? 57.4 : 54.6;
+ hand.setAttribute('cx', hx); hand.setAttribute('cy', hy);
+ canopyG.style.display = night ? 'none' : '';
+ lanternG.style.display = night ? '' : 'none';
+ if (!night) {
+ const tilt = -14 + tiltS - bow * 10;
+ const apex = [hx - 15, hy - 50];
+ pole.setAttribute('d', `M${hx + 1} ${hy + 3} L${f(apex[0])} ${f(apex[1])}`);
+ canopyG.setAttribute('transform', `translate(${f(apex[0])} ${f(apex[1])}) rotate(${f(tilt)})`);
+ canopy.setAttribute('d', 'M-27 10 Q-25 -1.6 0 -4 Q25 -1.6 27 10 Q22 8 18 9.6 Q13 7.6 9 9 Q4.6 7.4 0 8.8 Q-4.6 7.4 -9 9 Q-13 7.6 -18 9.6 Q-22 8 -27 10Z');
+ ring_.setAttribute('d', 'M-18.6 2.8 Q0 -3 18.6 2.8');
+ ribs.setAttribute('d', Array.from({ length: 9 }, (_, k) => { const xx = lerp(-24, 24, k / 8); return `M0 -3.6 L${f(xx)} ${f(8.8 - Math.abs(xx) * 0.02)}`; }).join(' '));
+ cap.setAttribute('d', oval(0, -4.2, 2.6, 1.4));
+ lGlow.setAttribute('opacity', 0);
+ } else {
+ const tip = [hx + 15, hy - 9];
+ pole.setAttribute('d', `M${hx - 1} ${hy + 1} Q${hx + 8} ${hy - 6} ${tip[0]} ${tip[1]}`);
+ lanV += (-lanA * 22 - Math.sin(stepPh) * 2.2 * go - lanV * 2.2) * dt; lanA += lanV * dt;
+ lanternG.setAttribute('transform', `translate(${tip[0]} ${tip[1]}) rotate(${f(lanA * 57.3)})`);
+ lBody.setAttribute('d', 'M-3.6 5 Q-5.4 10.5 -3.6 16 L3.6 16 Q5.4 10.5 3.6 5Z M0 0 L0 3');
+ lBody.setAttribute('fill', rgb(mix(P.paper, hex('#ffd38a'), 1)));
+ lCaps.setAttribute('d', 'M-2.6 3 L2.6 3 L2.6 5 L-2.6 5Z M-2.6 15.6 L2.6 15.6 L2.6 17.4 L-2.6 17.4Z');
+ lRibs.setAttribute('d', 'M-4.4 8 Q0 9 4.4 8 M-4.8 11 Q0 12 4.8 11 M-4.4 14 Q0 15 4.4 14');
+ const [wx, wy] = world(this.x, this.y, dir, tip[0] - Math.sin(lanA) * 10, tip[1] + b + 10.5);
+ lGlow.setAttribute('cx', f(wx)); lGlow.setAttribute('cy', f(wy)); lGlow.setAttribute('opacity', f(0.9 + 0.1 * Math.sin(t * 9)));
+ }
+ [lower, upper, sleeve].forEach((n) => n.setAttribute('fill', fillOf(kimonoC, P)));
+ farSleeve.setAttribute('fill', rgb(mix(hex(kimonoC), [10, 12, 20], 0.18 + P.inkT * 0.4)));
+ [obi, taiko].forEach((n) => n.setAttribute('fill', fillOf(obiC, P)));
+ canopy.setAttribute('fill', fillOf(parasolC, P));
+ },
+ remove() { g.remove(); lGlow.remove(); },
+ };
+}
+
+// ===================================================================== schoolboy on a mama-chari
+export function createCyclist(parent, glow, { dir = -1, x, y }) {
+ const g = el('g', { style: 'cursor:pointer' }, parent);
+ const speed = 66; // scene px/s
+ const R = 13.5, REAR = [18, 106.5], FRONT = [71, 106.5], BB = [41, 108];
+ const wheels = [REAR, FRONT].map((c) => ({ c, tyre: el('circle', { cx: c[0], cy: c[1], r: R, fill: 'none', stroke: 'currentColor', 'stroke-width': PEN * 1.1 }, g), rim: el('circle', { cx: c[0], cy: c[1], r: R - 1.6, fill: 'none', stroke: 'currentColor', 'stroke-width': PEN * 0.45 }, g), spokes: pen(g, PEN * 0.32), hub: el('circle', { cx: c[0], cy: c[1], r: 1.4, fill: 'currentColor' }, g) }));
+ const farLeg = solid(limb(g, 4.2));
+ const farShoe = blot(g);
+ const frame = pen(g, PEN * 1.05);
+ pen(g, PEN * 0.6).setAttribute('d', `M${REAR[0] - 15} ${REAR[1] - 2} Q${REAR[0]} ${REAR[1] - 18} ${REAR[0] + 14} ${REAR[1] - 5} M${FRONT[0] - 13} ${FRONT[1] - 5} Q${FRONT[0]} ${FRONT[1] - 18} ${FRONT[0] + 14} ${FRONT[1] - 3}`);
+ frame.setAttribute('d', `M64 79 Q52 103 ${BB[0]} ${BB[1]} L${REAR[0]} ${REAR[1]} L31 80 L${BB[0]} ${BB[1]} M31 80 L30 74 M64 79 L66.6 89 Q68.4 97 ${FRONT[0]} ${FRONT[1]} M64 79 L62.4 70 Q58 68 54.4 69.6`);
+ const guard = shape(g, PEN * 0.6); guard.setAttribute('d', `M${BB[0] + 3} ${BB[1] - 3.6} L${REAR[0] + 1} ${REAR[1] - 3} Q${REAR[0] - 2} ${REAR[1]} ${REAR[0] + 1} ${REAR[1] + 3} L${BB[0] + 3} ${BB[1] + 3.6} Q${BB[0] + 6.4} ${BB[1]} ${BB[0] + 3} ${BB[1] - 3.6}Z`);
+ const saddle = blot(g); saddle.setAttribute('d', 'M25 73 Q30 70.6 35.6 72.4 L34.6 75 L26 75Z');
+ const basket = shape(g, PEN * 0.7); basket.setAttribute('d', 'M66 71 L82 71 L80.6 84 L67.4 84Z');
+ pen(g, PEN * 0.35).setAttribute('d', 'M66.5 75 L81.6 75 M66.9 79.4 L81 79.4 M70 71 L70.6 84 M74 71 L74 84 M78 71 L77.4 84');
+ const bag = el('path', { d: 'M68 71 Q68.5 64 74 64 Q80 64 80 71Z', fill: '#4a3a2c', stroke: 'currentColor', 'stroke-width': PEN * 0.6 }, g);
+ const lamp = el('path', { d: 'M81.6 84 L85.4 84 L85.4 88 L81.6 88Z', fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN * 0.6 }, g);
+ const bell = el('path', { d: 'M56 66.6 a1.8 1.8 0 0 1 3.6 0Z', fill: '#d8d2c0', stroke: 'currentColor', 'stroke-width': 0.5 }, g);
+ const crank = pen(g, PEN * 0.9);
+ const torso = blot(g);
+ const collarB = pen(g, PEN * 0.6);
+ const head = el('ellipse', { rx: 4.3, ry: 5, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN }, g);
+ const capC = blot(g);
+ const nearLeg = solid(limb(g, 4.4));
+ const nearShoe = blot(g);
+ const arm = solid(limb(g, 3.6));
+ const handC = el('ellipse', { rx: 1.7, ry: 1.4, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN * 0.7 }, g);
+ const rings = pen(g, PEN * 0.6);
+ const beam = el('path', { fill: dir > 0 ? 'url(#v-beamR)' : 'url(#v-beamL)', opacity: 0 }, glow);
+ const beamGlow = el('circle', { r: 10, fill: 'url(#v-warmglow)', opacity: 0 }, glow);
+ let dist = 0, ringT = -1;
+ return {
+ g, x, y, dir, done: false, kind: 'bike',
+ poke() { ringT = 0; },
+ get ringing() { return ringT >= 0 && ringT < 0.8; },
+ draw(t, dt, P) {
+ this.x += dir * speed * dt; dist += speed * dt / FS;
+ if (this.x < -80 || this.x > 1040) this.done = true;
+ place(g, this.x, this.y, dir);
+ const wa = dist / R;
+ wheels.forEach((w) => {
+ const d = [];
+ for (let k = 0; k < 8; k++) { const a = wa + (k * Math.PI) / 8; d.push(`M${f(w.c[0] + Math.cos(a) * (R - 1.6))} ${f(w.c[1] + Math.sin(a) * (R - 1.6))} L${f(w.c[0] - Math.cos(a) * (R - 1.6))} ${f(w.c[1] - Math.sin(a) * (R - 1.6))}`); }
+ w.spokes.setAttribute('d', d.join(' '));
+ });
+ const ca = wa * 0.42, CR = 6.2;
+ const pN = [BB[0] + Math.cos(ca) * CR, BB[1] + Math.sin(ca) * CR], pF = [BB[0] - Math.cos(ca) * CR, BB[1] - Math.sin(ca) * CR];
+ crank.setAttribute('d', `M${pt(pF)} L${pt(pN)} M${f(pN[0] - 2)} ${f(pN[1])} l4 0 M${f(pF[0] - 2)} ${f(pF[1])} l4 0`);
+ const bob = Math.sin(ca * 2) * 0.35;
+ const hip = [31, 70.6 + bob];
+ [[farLeg, farShoe, pF], [nearLeg, nearShoe, pN]].forEach(([L, S, p]) => {
+ const ank = [p[0] - 0.6, p[1] - 2.2];
+ L.draw([hip, joint(hip, ank, 21, 21, 1), ank], [0.2, 0.4]);
+ S.setAttribute('d', `M${f(ank[0] - 2.6)} ${f(ank[1] + 0.6)} L${f(ank[0] + 4.4)} ${f(ank[1] + 0.6)} Q${f(ank[0] + 5.4)} ${f(ank[1] + 2.6)} ${f(ank[0] + 3)} ${f(ank[1] + 2.8)} L${f(ank[0] - 2.4)} ${f(ank[1] + 2.8)}Z`);
+ });
+ const sh = [44.6, 43 + bob];
+ torso.setAttribute('d', `M${f(hip[0] - 3.6)} ${f(hip[1] + 2)} Q${f(hip[0] - 4.4)} ${f(hip[1] - 14)} ${f(sh[0] - 6)} ${f(sh[1] + 1)} Q${f(sh[0] - 1)} ${f(sh[1] - 3.4)} ${f(sh[0] + 3.4)} ${f(sh[1] + 1.6)} Q${f(sh[0] - 2)} ${f(hip[1] - 12)} ${f(hip[0] + 6)} ${f(hip[1] + 2)}Z`);
+ collarB.setAttribute('d', `M${f(sh[0] - 2)} ${f(sh[1] - 1)} l3 1.6`);
+ collarB.setAttribute('stroke', rgb(P.paper));
+ const hc = [sh[0] + 4.2, sh[1] - 9.4];
+ head.setAttribute('cx', f(hc[0])); head.setAttribute('cy', f(hc[1]));
+ capC.setAttribute('d', `M${f(hc[0] - 4.6)} ${f(hc[1] - 1.6)} Q${f(hc[0] - 4.4)} ${f(hc[1] - 7)} ${f(hc[0] + 0.4)} ${f(hc[1] - 6.8)} Q${f(hc[0] + 4.8)} ${f(hc[1] - 6.4)} ${f(hc[0] + 4.6)} ${f(hc[1] - 2)} L${f(hc[0] + 8)} ${f(hc[1] - 1.2)} L${f(hc[0] + 4.4)} ${f(hc[1] - 0.6)}Z`);
+ const grip = [55.4, 69.6];
+ arm.draw([[sh[0], sh[1] + 2], joint([sh[0], sh[1] + 2], grip, 11.5, 11.5, -1), grip], [0.2, 0.4]);
+ handC.setAttribute('cx', grip[0]); handC.setAttribute('cy', grip[1]);
+ bag.setAttribute('fill', fillOf('#4a3a2c', P));
+ // bell rings
+ if (ringT >= 0) { ringT += dt; if (ringT > 0.9) ringT = -1; }
+ const rr = ringT >= 0 ? ringT : 0;
+ rings.setAttribute('d', ringT >= 0 ? [5, 9].map((r) => `M${57.8 - r * 0.6} ${f(64 - r * 0.5)} Q57.8 ${f(64 - r * 1.1)} ${57.8 + r * 0.6} ${f(64 - r * 0.5)}`).join(' ') : '');
+ rings.setAttribute('opacity', f(1 - rr));
+ bell.setAttribute('transform', ringT >= 0 ? `rotate(${f(Math.sin(rr * 60) * 14 * (1 - rr))} 57.8 66.6)` : '');
+ // headlamp after dark
+ const on = smooth(0.35, 0.6, P.lamp);
+ lamp.style.fill = rgb(mix(P.paper, hex('#fff1c2'), on));
+ const [lx, ly] = world(this.x, this.y, dir, 85, 86);
+ beamGlow.setAttribute('cx', f(lx)); beamGlow.setAttribute('cy', f(ly)); beamGlow.setAttribute('opacity', f(on));
+ beam.setAttribute('d', `M${f(lx)} ${f(ly - 1)} L${f(lx + dir * 70)} ${f(this.y - 5)} L${f(lx + dir * 70)} ${f(this.y + 6)} L${f(lx)} ${f(ly + 1)}Z`);
+ beam.setAttribute('opacity', f(on * 0.7));
+ },
+ remove() { g.remove(); beam.remove(); beamGlow.remove(); },
+ };
+}
+
+// ===================================================================== child with a pinwheel
+export function createKid(parent, glow, { dir = 1, x, y }) {
+ const g = el('g', { style: 'cursor:pointer' }, parent);
+ const T = 0.5, STRIDE = 8, DUTY = 0.36;
+ const speed = (2 * STRIDE) / (DUTY * T) * FS;
+ const legs = [0, 1].map(() => ({ L: limb(g, 3.6), S: blot(g) }));
+ const farArm = limb(g, 3);
+ const shorts = el('path', { fill: '#33465e', stroke: 'currentColor', 'stroke-width': PEN }, g);
+ const shirt = el('path', { fill: 'url(#v-stripes)', stroke: 'currentColor', 'stroke-width': PEN }, g);
+ const head = el('ellipse', { rx: 6.4, ry: 6.9, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN }, g);
+ const hair = blot(g);
+ const hat = el('path', { fill: '#e6cf8e', stroke: 'currentColor', 'stroke-width': PEN * 0.8 }, g);
+ const band = el('path', { fill: '#b3412d' }, g);
+ const arm = limb(g, 3);
+ const stick = pen(g, PEN * 0.7);
+ const wheel = el('g', {}, g);
+ const blades = ['#d4552f', '#3f6ea8', '#e3b33d', '#4e8a5a'].map((c, k) => el('path', { d: 'M0 0 L0 -7.6 Q4.8 -6.2 4.8 -3.2Z', transform: `rotate(${k * 90})`, fill: c, stroke: 'currentColor', 'stroke-width': PEN * 0.5, 'stroke-linejoin': 'round' }, wheel));
+ const pinDot = el('circle', { r: 1, fill: 'currentColor' }, wheel);
+ const footKey = (u) => {
+ u = ((u % 1) + 1) % 1;
+ if (u < DUTY) return { x: STRIDE - (2 * STRIDE * u) / DUTY, y: 0 };
+ const s = (u - DUTY) / (1 - DUTY);
+ // heel kicks up behind first, then the knee drives the foot forward and down
+ const xs = s * s * s * (10 - 15 * s + 6 * s * s);
+ return { x: -STRIDE + 2 * STRIDE * xs - 3.5 * Math.sin(Math.PI * Math.min(1, s * 1.6)), y: -12 * Math.pow(Math.sin(Math.PI * Math.pow(s, 0.7)), 1.1) };
+ };
+ let ph = rnd(0, 1), spin = 0, hopT = -1;
+ return {
+ g, x, y, dir, done: false,
+ poke() { if (hopT < 0) hopT = 0; },
+ draw(t, dt, P, wind) {
+ ph += dt / T; this.x += dir * speed * dt;
+ if (this.x < -60 || this.x > 1020) this.done = true;
+ let hop = 0;
+ if (hopT >= 0) { hopT += dt; hop = Math.sin(Math.PI * Math.min(1, hopT / 0.55)) * 14; if (hopT > 0.55) hopT = -1; }
+ place(g, this.x, this.y - hop * FS, dir);
+ const bounce = -3 * Math.pow(Math.abs(Math.sin(2 * Math.PI * ph + 0.6)), 1.4) + 0.8; // up in flight, down at contact
+ const hip = [40, 94 + bounce];
+ [footKey(ph), footKey(ph + 0.5)].forEach((k, i) => {
+ const a = [40 + k.x, 118 + k.y];
+ legs[i].L.draw([hip, joint(hip, a, 13, 13, 1), a], [0.2, 0.4]);
+ legs[i].S.setAttribute('d', `M${f(a[0] - 2)} ${f(a[1])} L${f(a[0] + 4)} ${f(a[1])} Q${f(a[0] + 5)} ${f(a[1] + 2)} ${f(a[0] + 3)} ${f(a[1] + 2)} L${f(a[0] - 2)} ${f(a[1] + 2)}Z`);
+ });
+ g.appendChild(legs[footKey(ph).x > footKey(ph + 0.5).x ? 0 : 1].L.g);
+ g.insertBefore(farArm.g, shorts);
+ const sh = [47, 72.6 + bounce]; // leaning into the run
+ shorts.setAttribute('d', `M34.6 ${f(hip[1] - 4)} L46 ${f(hip[1] - 4)} L47 ${f(hip[1] + 4)} L41 ${f(hip[1] + 4.6)} L40 ${f(hip[1] + 1)} L37.6 ${f(hip[1] + 4.6)} L33.8 ${f(hip[1] + 3.6)}Z`);
+ shirt.setAttribute('d', `M35 ${f(hip[1] - 3.6)} Q34.2 ${f(sh[1] + 6)} ${f(sh[0] - 6)} ${f(sh[1])} Q${f(sh[0])} ${f(sh[1] - 2.6)} ${f(sh[0] + 3)} ${f(sh[1] + 1)} Q47.4 ${f(sh[1] + 10)} 46.4 ${f(hip[1] - 3.6)}Z`);
+ const hc = [sh[0] + 2.4, sh[1] - 11];
+ head.setAttribute('cx', f(hc[0])); head.setAttribute('cy', f(hc[1]));
+ hair.setAttribute('d', `M${f(hc[0] - 6.2)} ${f(hc[1] + 1)} Q${f(hc[0] - 6.6)} ${f(hc[1] - 6)} ${f(hc[0])} ${f(hc[1] - 6.6)} Q${f(hc[0] - 3)} ${f(hc[1] - 2)} ${f(hc[0] - 6.2)} ${f(hc[1] + 1)}Z`);
+ hat.setAttribute('d', `M${f(hc[0] - 12)} ${f(hc[1] - 4)} Q${f(hc[0])} ${f(hc[1] - 8)} ${f(hc[0] + 12)} ${f(hc[1] - 4)} Q${f(hc[0])} ${f(hc[1] - 1)} ${f(hc[0] - 12)} ${f(hc[1] - 4)}Z M${f(hc[0] - 5.6)} ${f(hc[1] - 5.4)} Q${f(hc[0] - 5)} ${f(hc[1] - 12)} ${f(hc[0])} ${f(hc[1] - 12)} Q${f(hc[0] + 5)} ${f(hc[1] - 12)} ${f(hc[0] + 5.6)} ${f(hc[1] - 5.6)}Z`);
+ band.setAttribute('d', `M${f(hc[0] - 5.5)} ${f(hc[1] - 7.6)} L${f(hc[0] + 5.5)} ${f(hc[1] - 7.6)} L${f(hc[0] + 5.6)} ${f(hc[1] - 5.8)} L${f(hc[0] - 5.6)} ${f(hc[1] - 5.8)}Z`);
+ const swing = Math.sin(2 * Math.PI * ph) * 52;
+ const fsh = [sh[0] - 2.5, sh[1] + 1.5];
+ const fe = [fsh[0] + Math.sin(swing * RAD) * 8, fsh[1] + Math.cos(swing * RAD) * 8];
+ farArm.draw([fsh, fe, [fe[0] + Math.sin((swing - 50) * RAD) * 8, fe[1] + Math.cos((swing - 50) * RAD) * 8]], [0.2, 0.4]);
+ const hand = [56, sh[1] - 5];
+ arm.draw([[sh[0], sh[1] + 1.5], [sh[0] + 4.6, sh[1] + 5], hand], [0.2, 0.4]);
+ const top = [hand[0] + 3, hand[1] - 22];
+ stick.setAttribute('d', `M${hand[0] - 0.6} ${f(hand[1] + 2)} L${f(top[0])} ${f(top[1])}`);
+ spin += (8 + speed * 0.12 + Math.abs(wind) * 6 + (hopT >= 0 ? 30 : 0)) * dt;
+ wheel.setAttribute('transform', `translate(${f(top[0])} ${f(top[1])}) rotate(${f(spin * 57.3)})`);
+ blades.forEach((b, k) => b.setAttribute('fill', fillOf(['#d4552f', '#3f6ea8', '#e3b33d', '#4e8a5a'][k], P)));
+ shorts.setAttribute('fill', fillOf('#33465e', P));
+ hat.setAttribute('fill', fillOf('#e6cf8e', P));
+ },
+ remove() { g.remove(); },
+ };
+}
+
+// ===================================================================== boatman poling a flat boat
+export function createBoat(parent, glow, { onRipple }) {
+ const g = el('g', { style: 'cursor:pointer' }, parent);
+ const Y = WATER + 30; // waterline in scene
+ const hull = el('path', { fill: '#8b6a48', stroke: 'currentColor', 'stroke-width': PEN }, g);
+ const planks = pen(g, PEN * 0.45);
+ const cargo = el('g', {}, g);
+ const bales = [[120, 106], [146, 106], [172, 106], [133, 94], [159, 94]].map(([bx, by]) => {
+ const n = el('path', { d: `M${bx - 12} ${by} Q${bx - 12} ${by - 6} ${bx} ${by - 6.5} Q${bx + 12} ${by - 6} ${bx + 12} ${by} Q${bx + 12} ${by + 6} ${bx} ${by + 6.5} Q${bx - 12} ${by + 6} ${bx - 12} ${by}Z`, fill: '#e2cf95', stroke: 'currentColor', 'stroke-width': PEN * 0.8 }, cargo);
+ pen(cargo, PEN * 0.45).setAttribute('d', `M${bx - 6} ${by - 6} Q${bx - 7.4} ${by} ${bx - 6} ${by + 6} M${bx + 6} ${by - 6} Q${bx + 7.4} ${by} ${bx + 6} ${by + 6} M${bx - 12} ${by} L${bx + 12} ${by}`);
+ return n;
+ });
+ const post = pen(g, PEN * 0.9);
+ const lan = el('path', { stroke: 'currentColor', 'stroke-width': PEN * 0.7 }, g);
+ const lanGlow = el('circle', { r: 26, fill: 'url(#v-warmglow)', opacity: 0 }, glow);
+ const man = el('g', {}, g);
+ const legs = [limb(man, 4.2), limb(man, 4.2)];
+ legs.forEach((l) => solid(l, '#2b3446'));
+ const coat = el('path', { fill: '#34507a', stroke: 'currentColor', 'stroke-width': PEN }, man);
+ const coatMark = pen(man, PEN * 0.5);
+ const head = el('ellipse', { rx: 4, ry: 4.8, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN }, man);
+ const kasa = el('path', { fill: '#cdb57a', stroke: 'currentColor', 'stroke-width': PEN * 0.8 }, man);
+ const kasaL = pen(man, PEN * 0.4);
+ const arms = [limb(man, 3.4), limb(man, 3.4)];
+ const pole = pen(g, PEN * 1.4);
+ const poleWet = el('path', { stroke: 'currentColor', 'stroke-width': PEN * 0.9, 'stroke-dasharray': '2 2.4', fill: 'none', opacity: 0.6 }, g);
+ const notes = el('g', {}, g);
+ let X = 140, anchor = null, ph = 0, songT = -1, lastTip = [40, 160];
+ const noteN = [];
+ const T = 3.6;
+ const lean = curve([[0, -4], [0.45, 26], [0.62, 14], [0.8, 2]], 1);
+ return {
+ g,
+ get x() { return X; },
+ poke() { if (songT < 0) { songT = 0; for (let i = 0; i < 4; i++) noteN.push({ t: -i * 0.35, x0: rnd(-4, 4), n: el('text', { 'font-size': 11, fill: 'currentColor', 'font-family': 'serif' }, notes) }); noteN.slice(-4).forEach((n, i) => (n.n.textContent = i % 2 ? '♪' : '♫')); } },
+ draw(t, dt, P, wind) {
+ ph = (ph + dt / T) % 1;
+ const push = ph > 0.1 && ph < 0.62 ? Math.sin(Math.PI * (ph - 0.1) / 0.52) : 0;
+ const v = 7 + 15 * push;
+ X += v * dt; if (X > 1120) { X = -170; anchor = null; }
+ g.setAttribute('transform', `translate(${f(X)} ${f(Y - 120 * FS + Math.sin(t * 1.4) * 0.6)}) scale(${FS}) translate(-40 0)`);
+ // hull with an upturned bow, cargo of rice bales
+ hull.setAttribute('d', 'M14 112 L232 112 Q250 110 258 96 Q252 116 236 124 L30 124 Q18 122 14 112Z');
+ hull.setAttribute('fill', fillOf('#8b6a48', P));
+ planks.setAttribute('d', 'M18 116 L240 116 M24 120 L236 120 M60 112 L60 124 M110 112 L110 124 M200 112 L200 124');
+ bales.forEach((b) => b.setAttribute('fill', fillOf('#e2cf95', P)));
+ // bow lantern
+ post.setAttribute('d', 'M244 112 L244 86 Q244 82 248 82');
+ const on = smooth(0.3, 0.55, P.lamp);
+ lan.setAttribute('d', 'M245 84 L251 84 Q253 89 251 94 L245 94 Q243 89 245 84Z');
+ lan.setAttribute('fill', rgb(mix(P.paper, hex('#ffd38a'), on)));
+ const lw = [X + (248 - 40) * FS, Y - 120 * FS + 89 * FS];
+ lanGlow.setAttribute('cx', f(lw[0])); lanGlow.setAttribute('cy', f(lw[1])); lanGlow.setAttribute('opacity', f(on));
+ // boatman at the stern
+ const ln = lean(ph) * RAD;
+ const hip = [40, 86];
+ legs[0].draw([hip, [44 + Math.sin(ln) * 6, 99], [46, 111]], [0.2, 0.4]);
+ legs[1].draw([hip, [36, 99], [32, 111]], [0.2, 0.4]);
+ const sh = [hip[0] + Math.sin(ln) * 22, hip[1] - Math.cos(ln) * 22];
+ coat.setAttribute('d', `M${f(hip[0] - 5)} ${f(hip[1] + 4)} L${f(sh[0] - 5)} ${f(sh[1] + 1)} Q${f(sh[0])} ${f(sh[1] - 2.6)} ${f(sh[0] + 5)} ${f(sh[1] + 1)} L${f(hip[0] + 6)} ${f(hip[1] + 4)}Z`);
+ coat.setAttribute('fill', fillOf('#34507a', P));
+ coatMark.setAttribute('d', `M${f((hip[0] + sh[0]) / 2 - 3)} ${f((hip[1] + sh[1]) / 2)} l6 0`);
+ coatMark.setAttribute('stroke', rgb(P.paper));
+ const hc = [sh[0] + Math.sin(ln) * 9 + 1, sh[1] - Math.cos(ln) * 9];
+ head.setAttribute('cx', f(hc[0])); head.setAttribute('cy', f(hc[1]));
+ kasa.setAttribute('d', `M${f(hc[0] - 15)} ${f(hc[1] - 1)} L${f(hc[0] + 0.5)} ${f(hc[1] - 12)} L${f(hc[0] + 16)} ${f(hc[1] - 1)} Q${f(hc[0])} ${f(hc[1] - 3.6)} ${f(hc[0] - 15)} ${f(hc[1] - 1)}Z`);
+ kasa.setAttribute('fill', fillOf('#cdb57a', P));
+ kasaL.setAttribute('d', [-10, -5, 0, 5, 10].map((k) => `M${f(hc[0] + 0.5)} ${f(hc[1] - 11)} L${f(hc[0] + k)} ${f(hc[1] - 2.6)}`).join(' '));
+ // the pole: planted in the bed while he pushes, then lifted and swung forward
+ const toLocal = (wx) => (wx - X) / FS + 40;
+ const bed = (Y - 120 * FS + 160 * FS);
+ let tip;
+ if (ph < 0.62) {
+ if (!anchor) { anchor = X + (100 - 40) * FS; onRipple(anchor, WATER + 30); }
+ tip = [toLocal(anchor), 160];
+ lastTip = tip;
+ } else {
+ anchor = null;
+ const u = (ph - 0.62) / 0.38;
+ tip = [lerp(lastTip[0], 100, ease(u)), 160 - 58 * Math.sin(Math.PI * u)];
+ }
+ const hiHand = [sh[0] + 9, sh[1] + 4 + lean(ph) * 0.2];
+ const dirx = hiHand[0] - tip[0], diry = hiHand[1] - tip[1], dl = Math.hypot(dirx, diry);
+ const top = [hiHand[0] + (dirx / dl) * 46, hiHand[1] + (diry / dl) * 46];
+ const loHand = [hiHand[0] - (dirx / dl) * 13, hiHand[1] - (diry / dl) * 13];
+ arms[0].draw([[sh[0] + 1, sh[1] + 2], joint([sh[0] + 1, sh[1] + 2], hiHand, 10, 10, 1), hiHand], [0.2, 0.3]);
+ arms[1].draw([[sh[0] - 1, sh[1] + 2], joint([sh[0] - 1, sh[1] + 2], loHand, 10, 11, 1), loHand], [0.2, 0.3]);
+ // split at the water surface (local y where world y == WATER)
+ const wl = (WATER - (Y - 120 * FS)) / FS;
+ const k = (wl - top[1]) / (tip[1] - top[1]);
+ const surf = k > 0 && k < 1 ? [lerp(top[0], tip[0], k), wl] : tip;
+ pole.setAttribute('d', `M${pt(top)} L${pt(surf)}`);
+ poleWet.setAttribute('d', k > 0 && k < 1 ? `M${pt(surf)} L${pt(tip)}` : '');
+ // song
+ if (songT >= 0) songT += dt; if (songT > 3.4) songT = -1;
+ for (let i = noteN.length - 1; i >= 0; i--) {
+ const n = noteN[i]; n.t += dt;
+ if (n.t < 0) { n.n.setAttribute('opacity', 0); continue; }
+ n.n.setAttribute('x', f(hc[0] + 6 + n.x0 + n.t * 10)); n.n.setAttribute('y', f(hc[1] - 10 - n.t * 18 + Math.sin(n.t * 6) * 2));
+ n.n.setAttribute('opacity', f(Math.max(0, 1 - n.t / 1.8)));
+ if (n.t > 1.8) { n.n.remove(); noteN.splice(i, 1); }
+ }
+ },
+ };
+}
diff --git a/examples/village/sky.ts b/examples/village/sky.ts
new file mode 100644
index 0000000..c99b761
--- /dev/null
+++ b/examples/village/sky.ts
@@ -0,0 +1,172 @@
+// Sky, sun, moon, stars and the day/night palette.
+// Time of day τ ∈ [0,1): 0 midnight, 0.25 dawn, 0.5 noon, 0.75 dusk.
+import { el, pen, shape, blot, f, pt, PAPER } from '../../lib/ink.ts';
+import { W, SP, rnd, srnd, clamp, lerp, smooth, ramp, rgb, hex, mix, lum, oval } from './kit.ts';
+
+const SKY_TOP = [[0, '#0d1222'], [0.19, '#131a30'], [0.235, '#3d4066'], [0.27, '#cfd8e2'], [0.33, '#f3f2ee'], [0.5, '#f6f5f1'], [0.68, '#f3eee4'], [0.735, '#e3c6a6'], [0.762, '#5a5279'], [0.80, '#1b2140'], [0.86, '#0d1222']];
+const SKY_BOT = [[0, '#1a2240'], [0.19, '#283050'], [0.235, '#d49884'], [0.27, '#f3d0b3'], [0.33, '#faf6ee'], [0.5, '#fcfbf7'], [0.68, '#f9efdc'], [0.735, '#f0a379'], [0.762, '#d47f68'], [0.80, '#383a60'], [0.86, '#1a2240']];
+const PAPERS = [[0, '#1a2036'], [0.19, '#1f263e'], [0.235, '#4a4561'], [0.27, '#ede4d8'], [0.33, '#fbf8f1'], [0.5, '#fdfcf8'], [0.68, '#faf4e8'], [0.735, '#f0dbc4'], [0.756, '#5d5571'], [0.80, '#262c48'], [0.86, '#1a2036']];
+const INK_DARK = hex('#1c1c1c'), INK_LIGHT = hex('#efe6cf');
+
+export function palette(tau) {
+ const top = ramp(SKY_TOP, tau), bot = ramp(SKY_BOT, tau), paper = ramp(PAPERS, tau);
+ const L = lum(paper);
+ const inkT = smooth(0.56, 0.36, L);
+ return {
+ top, bot, paper,
+ ink: mix(INK_DARK, INK_LIGHT, inkT),
+ inkT,
+ lamp: smooth(0.78, 0.4, L), // how dark it is for lamps (windows add their own threshold)
+ night: smooth(0.42, 0.1, lum(top)), // stars, moon glow, fireflies
+ sunset: Math.max(smooth(0.67, 0.735, tau) * smooth(0.79, 0.745, tau), smooth(0.215, 0.245, tau) * smooth(0.3, 0.26, tau)),
+ };
+}
+
+const sunArc = (u) => [40 + 880 * u, 300 - 236 * Math.sin(Math.PI * u)];
+const moonArc = (u) => [60 + 840 * u, 290 - 205 * Math.sin(Math.PI * u)];
+const SUN_SPAN = [0.225, 0.55], MOON_SPAN = [0.775, 0.45];
+
+export function createSky(svg, root, defs, { onScrub, onShoot }) {
+ // gradient sky
+ const grad = el('linearGradient', { id: 'v-sky', x1: 0, y1: 0, x2: 0, y2: 1 }, defs);
+ const s0 = el('stop', { offset: 0 }, grad), s1 = el('stop', { offset: 1 }, grad);
+ const glowSun = el('radialGradient', { id: 'v-sunglow' }, defs);
+ el('stop', { offset: 0, 'stop-color': '#ffd9a0', 'stop-opacity': 0.55 }, glowSun);
+ el('stop', { offset: 1, 'stop-color': '#ffd9a0', 'stop-opacity': 0 }, glowSun);
+ const glowMoon = el('radialGradient', { id: 'v-moonglow' }, defs);
+ el('stop', { offset: 0, 'stop-color': '#e9e4ff', 'stop-opacity': 0.35 }, glowMoon);
+ el('stop', { offset: 1, 'stop-color': '#e9e4ff', 'stop-opacity': 0 }, glowMoon);
+
+ const g = el('g', {}, root);
+ el('rect', { x: -20, y: -20, width: W + 40, height: 520, fill: 'url(#v-sky)' }, g);
+
+ // stars
+ const starG = el('g', {}, g);
+ const stars = Array.from({ length: 90 }, () => {
+ const x = srnd(0, W), y = srnd(6, 250), r = srnd(0.35, 1.05);
+ return { n: el('circle', { cx: f(x), cy: f(y), r: f(r), fill: '#f5efda' }, starG), ph: srnd(0, 6), sp: srnd(0.6, 2.4), big: r > 0.9, spark: null as SVGPathElement | null };
+ });
+ stars.filter((s) => s.big).forEach((s) => {
+ const x = +s.n.getAttribute('cx'), y = +s.n.getAttribute('cy');
+ s.spark = el('path', { d: `M${x - 2.6} ${y} L${x + 2.6} ${y} M${x} ${y - 2.6} L${x} ${y + 2.6}`, stroke: '#f5efda', 'stroke-width': 0.35, opacity: 0.6 }, starG);
+ });
+ const shoots = [];
+
+ // sun & moon (draggable)
+ const sunG = el('g', { class: 'drag', style: 'cursor:grab' }, g);
+ const sunGlow = el('circle', { r: 70, fill: 'url(#v-sunglow)' }, sunG);
+ const sunDisk = el('circle', { r: 21, stroke: 'currentColor', 'stroke-width': SP }, sunG);
+ el('title', {}, sunG).textContent = 'Drag the sun to change the time';
+ const moonG = el('g', { class: 'drag', style: 'cursor:grab' }, g);
+ el('circle', { r: 60, fill: 'url(#v-moonglow)' }, moonG);
+ const moonDisk = el('path', { fill: '#f3ecd6', stroke: '#f3ecd6', 'stroke-width': 0.6 }, moonG);
+ const moonShade = el('path', { fill: 'none', stroke: '#cfc6ad', 'stroke-width': 0.5, opacity: 0.7 }, moonG);
+ el('title', {}, moonG).textContent = 'Drag the moon to change the time';
+
+ // mist bands (suyari-gasumi) drifting in the day sky
+ const mist = el('g', {}, g);
+ const bands = [[120, 92, 150], [520, 64, 190], [760, 120, 130], [330, 140, 100]].map(([x, y, w]) => ({ x, y, w, v: rnd(1.2, 2.6), n: pen(mist, SP * 0.75) }));
+ // Japanese cloud strokes: long horizontal lines that curl into small spirals at the ends
+ const cloudD = (x, y, w) => {
+ const curlR = (cx, cy, s) => `M${f(cx)} ${f(cy)} q${5 * s} 0 ${5 * s} -4 q0 -3.2 ${-3.2 * s} -3.2 q-2.2 0 -2.2 2.2 q0 1.4 1.4 1.4`;
+ return `M${f(x)} ${f(y)} L${f(x + w)} ${f(y)} ${curlR(x + w, y, 1)} ${curlR(x, y, -1)} `
+ + `M${f(x + w * 0.18)} ${f(y - 7)} L${f(x + w * 0.66)} ${f(y - 7)} ${curlR(x + w * 0.66, y - 7, 1)} `
+ + `M${f(x + w * 0.42)} ${f(y + 6.5)} L${f(x + w * 0.92)} ${f(y + 6.5)} ${curlR(x + w * 0.42, y + 6.5, -1)}`;
+ };
+
+ // far hills and a pagoda, in diluted ink
+ const far = el('g', { opacity: 0.42 }, g);
+ pen(far, SP * 0.8).setAttribute('d', 'M0 262 Q80 238 170 222 Q240 206 300 214 Q360 222 420 208 Q470 196 520 188 Q600 176 660 198 Q720 218 790 206 Q860 192 960 214');
+ pen(far, SP * 0.55).setAttribute('d', 'M140 228 q20 -6 40 -4 M300 216 q16 -2 30 2 M560 186 q26 -4 44 4 M820 202 q18 -4 32 0');
+ drawPagoda(far, 640, 236);
+
+ // dragging: pointer x along the arc → time
+ let drag = null;
+ const toSvg = (e) => { const p = svg.createSVGPoint(); p.x = e.clientX; p.y = e.clientY; return p.matrixTransform(svg.getScreenCTM().inverse()); };
+ const start = (kind) => (e) => { e.preventDefault(); e.stopPropagation(); drag = kind; svg.setPointerCapture?.(e.pointerId); svg.classList.add('scrubbing'); };
+ sunG.addEventListener('pointerdown', start('sun'));
+ moonG.addEventListener('pointerdown', start('moon'));
+ svg.addEventListener('pointermove', (e) => {
+ if (!drag) return;
+ const p = toSvg(e);
+ if (drag === 'sun') onScrub(SUN_SPAN[0] + SUN_SPAN[1] * clamp((p.x - 40) / 880, 0, 1));
+ else onScrub((MOON_SPAN[0] + MOON_SPAN[1] * clamp((p.x - 60) / 840, 0, 1)) % 1);
+ });
+ const end = () => { if (drag) { drag = null; svg.classList.remove('scrubbing'); onScrub(null); } };
+ svg.addEventListener('pointerup', end);
+ svg.addEventListener('pointercancel', end);
+
+ // night sky click → shooting star
+ const skyHit = el('rect', { x: 0, y: 0, width: W, height: 160, fill: 'transparent' }, g);
+ skyHit.addEventListener('pointerdown', (e) => { if (onShoot()) { const p = toSvg(e); shoot(p.x, p.y); } });
+ g.insertBefore(skyHit, sunG);
+ function shoot(x, y) {
+ shoots.push({ x: x - 30, y: y - 18, t: 0, dir: Math.random() < 0.5 ? -1 : 1, n: el('path', { stroke: '#fff6dc', 'stroke-width': 0.9, 'stroke-linecap': 'round', fill: 'none' }, starG) });
+ }
+
+ return {
+ shoot,
+ draw(tau, t, dt, P, wind) {
+ s0.setAttribute('stop-color', rgb(P.top));
+ s1.setAttribute('stop-color', rgb(P.bot));
+ starG.setAttribute('opacity', f(P.night));
+ if (P.night > 0.01) stars.forEach((s) => {
+ const tw = 0.55 + 0.45 * Math.sin(t * s.sp + s.ph);
+ s.n.setAttribute('opacity', f(tw));
+ if (s.spark) s.spark.setAttribute('opacity', f(tw * 0.7));
+ });
+ if (P.night > 0.6 && Math.random() < dt * 0.04) shoot(rnd(100, 860), rnd(30, 110));
+ for (let i = shoots.length - 1; i >= 0; i--) {
+ const s = shoots[i]; s.t += dt;
+ const u = s.t / 0.9, x = s.x + s.dir * 120 * u, y = s.y + 60 * u;
+ s.n.setAttribute('d', `M${f(x)} ${f(y)} L${f(x - s.dir * 34 * (1 - u))} ${f(y - 17 * (1 - u))}`);
+ s.n.setAttribute('opacity', f(Math.sin(Math.PI * Math.min(1, u))));
+ if (u >= 1) { s.n.remove(); shoots.splice(i, 1); }
+ }
+
+ // sun
+ const su = (tau - SUN_SPAN[0]) / SUN_SPAN[1];
+ if (su > -0.05 && su < 1.05) {
+ const [x, y] = sunArc(clamp(su, 0, 1));
+ sunG.setAttribute('transform', `translate(${f(x)} ${f(y + (su < 0 || su > 1 ? 30 : 0))})`);
+ sunG.style.display = '';
+ sunDisk.setAttribute('fill', rgb(mix(hex('#fbf3df'), hex('#df5a3a'), P.sunset)));
+ sunGlow.setAttribute('opacity', f(0.35 + 0.65 * P.sunset));
+ } else sunG.style.display = 'none';
+
+ // moon (waxing crescent drawn with two arcs)
+ const mu = (((tau - MOON_SPAN[0]) % 1) + 1) % 1 / MOON_SPAN[1];
+ if (mu <= 1.02) {
+ const [x, y] = moonArc(clamp(mu, 0, 1));
+ moonG.setAttribute('transform', `translate(${f(x)} ${f(y)}) rotate(-24)`);
+ moonG.style.display = '';
+ moonG.setAttribute('opacity', f(smooth(0, 0.08, mu) * smooth(1.02, 0.94, mu)));
+ const r = 15;
+ moonDisk.setAttribute('d', `M0 ${-r} A${r} ${r} 0 1 1 0 ${r} A${r * 0.62} ${r} 0 1 0 0 ${-r}Z`);
+ moonShade.setAttribute('d', `M3 -6 a2.4 1.8 0 1 0 0.1 0 M8 4 a1.6 1.3 0 1 0 0.1 0`);
+ } else moonG.style.display = 'none';
+
+ // mist bands — strongest in the morning
+ mist.setAttribute('opacity', f(0.75 - 0.45 * P.night));
+ bands.forEach((b) => {
+ b.x += (b.v + wind * 3) * dt; if (b.x > W + 40) b.x = -b.w - 40; if (b.x < -b.w - 60) b.x = W + 30;
+ b.n.setAttribute('d', cloudD(b.x, b.y, b.w));
+ });
+ },
+ };
+}
+
+function drawPagoda(g, cx, baseY) {
+ // five tiers, each a sweeping roof with a small body under it, then the sōrin spire
+ let y = baseY;
+ for (let i = 0; i < 5; i++) {
+ const w = 36 - i * 4.2, bodyH = 9 - i * 0.6;
+ shape(g, SP * 0.75).setAttribute('d', `M${cx - w * 0.42} ${y} L${cx + w * 0.42} ${y} L${cx + w * 0.42} ${y - bodyH} L${cx - w * 0.42} ${y - bodyH}Z`);
+ pen(g, SP * 0.5).setAttribute('d', `M${cx - w * 0.18} ${y} L${cx - w * 0.18} ${y - bodyH} M${cx + w * 0.18} ${y} L${cx + w * 0.18} ${y - bodyH}`);
+ y -= bodyH;
+ shape(g, SP * 0.75).setAttribute('d', `M${cx - w} ${y + 1} Q${cx - w * 0.6} ${y - 1} ${cx - w * 0.35} ${y - 5} L${cx + w * 0.35} ${y - 5} Q${cx + w * 0.6} ${y - 1} ${cx + w} ${y + 1} Q${cx} ${y - 2} ${cx - w} ${y + 1}Z`);
+ y -= 5;
+ }
+ pen(g, SP * 0.8).setAttribute('d', `M${cx} ${y} L${cx} ${y - 26}`);
+ pen(g, SP * 0.5).setAttribute('d', Array.from({ length: 6 }, (_, k) => `M${cx - 2.6} ${y - 4 - k * 3} L${cx + 2.6} ${y - 4 - k * 3}`).join(' '));
+}
diff --git a/examples/village/tsconfig.json b/examples/village/tsconfig.json
new file mode 100644
index 0000000..93cf8ea
--- /dev/null
+++ b/examples/village/tsconfig.json
@@ -0,0 +1,5 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": { "strict": false, "noImplicitAny": false },
+ "include": ["./*.ts", "../../lib"]
+}
diff --git a/examples/walker/index.html b/examples/walker/index.html
new file mode 100644
index 0000000..02f1a38
--- /dev/null
+++ b/examples/walker/index.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Walker · line-art-animation</title>
+<style>
+ html, body { margin: 0; height: 100%; background: #ebe8e2; }
+ body { display: grid; place-items: center; }
+ .card { width: min(92vw, calc((100vh - 48px) * 2)); aspect-ratio: 2 / 1; border-radius: 16px; overflow: hidden; background: #fdfcf8;
+ box-shadow: 0 0 0 1px rgba(40, 34, 26, .10), 0 18px 50px -18px rgba(40, 34, 26, .35); }
+ #stage, #stage svg { display: block; width: 100%; height: 100%; }
+ #stage svg .pp { fill: var(--paper, #fdfdfc); }
+</style>
+</head>
+<body>
+ <div class="card"><div id="stage"></div></div>
+ <script type="module" src="./walker.ts"></script>
+</body>
+</html>
diff --git a/examples/walker/walker.ts b/examples/walker/walker.ts
new file mode 100644
index 0000000..8c8175a
--- /dev/null
+++ b/examples/walker/walker.ts
@@ -0,0 +1,109 @@
+// A man with a briefcase walks across the card. Click him to tip his hat;
+// move the pointer to blow his scarf. ~150 lines: the smallest complete example
+// of the library — gait, open-stroke limbs, clothing drawn around the legs,
+// springs for things that swing, a reaction to a click.
+import { el, pen, shape, blot, paint, limb, shoe, place, inkDefs, run, f, pt, PEN, PAPER, type Vec } from '../../lib/ink.ts';
+import { gait } from '../../lib/gait.ts';
+import { spring, pendulum, pointerWind, ease, clamp } from '../../lib/motion.ts';
+
+const W = 480, H = 240, GROUND = 196, SCALE = 1.25;
+const svg = el('svg', { viewBox: `0 0 ${W} ${H}`, role: 'img', 'aria-label': 'Line drawing of a man walking with a briefcase' });
+const { filter } = inkDefs(svg, 'w');
+document.querySelector('#stage')!.appendChild(svg);
+const scene = el('g', { filter }, svg);
+
+// --- a little street: kerb, paving, a lamp post
+pen(scene, 0.9).setAttribute('d', `M0 ${GROUND} L${W} ${GROUND} M0 ${GROUND + 9} L${W} ${GROUND + 9}`);
+pen(scene, 0.55).setAttribute('d', Array.from({ length: 16 }, (_, i) => `M${i * 32 + 10} ${GROUND} l0 9`).join(' '));
+shape(scene, 0.9).setAttribute('d', `M383 ${GROUND} L385 70 L389 70 L391 ${GROUND}Z`);
+shape(scene, 0.9).setAttribute('d', 'M377 70 L397 70 L394 58 L380 58Z');
+pen(scene, 0.6).setAttribute('d', 'M381 64 L393 64 M387 58 L387 52');
+
+// --- the figure, back to front. Everything is in figure space (feet on y 120).
+const fig = el('g', { style: 'cursor:pointer' }, scene);
+const farArm = limb(fig, 3.6);
+const legs = [limb(fig, 4.2), limb(fig, 4.2)];
+const shoes = [blot(fig), blot(fig)];
+const coat = shape(fig);
+const coatSeam = pen(fig, PEN * 0.6);
+const scarfTail = paint(fig, '#b3412d', PEN * 0.8);
+const head = el('ellipse', { rx: 3.6, ry: 4.6, fill: PAPER, stroke: 'currentColor', 'stroke-width': PEN }, fig);
+const hat = blot(fig);
+const scarf = paint(fig, '#b3412d', PEN * 0.8);
+const nearArm = limb(fig, 3.6);
+const caseG = el('g', {}, fig);
+const briefcase = paint(caseG, '#6b4a32', PEN * 0.8);
+const handle = pen(caseG, PEN * 0.7);
+
+const walk = gait({ kind: 'walk' });
+const wind = pointerWind(svg, 0.2);
+const armSwing = [spring(60, 9), spring(60, 9)];
+const caseSwing = pendulum(14, 1.8);
+const tail = spring(30, 4);
+let phase = 0, x = 120, tipT = -1;
+
+fig.addEventListener('pointerdown', () => { if (tipT < 0) tipT = 0; });
+
+run((t, dt) => {
+ wind.step(t);
+ // tipping the hat: slow to a stop, raise the hand, lift the hat, walk on
+ let tip = 0;
+ if (tipT >= 0) { tipT += dt; tip = tipT < 0.35 ? ease(tipT / 0.35) : tipT < 1.2 ? 1 : 1 - ease((tipT - 1.2) / 0.4); if (tipT > 1.6) tipT = -1; }
+ const go = 1 - tip * 0.85;
+ phase += (dt / walk.period) * go;
+ x += walk.speed * SCALE * dt * go;
+ if (x > W + 50) x = -50;
+ place(fig, x, GROUND, 1, SCALE);
+
+ const p = walk.pose(phase, go);
+ const b = p.bob;
+ // legs; the leading leg is drawn on top
+ p.feet.forEach((fo, i) => { legs[i].draw([p.hip, fo.knee, fo.ankle], [0.3, 0.8]); shoe(shoes[i], fo.ankle, fo.pitch); });
+ fig.insertBefore(legs[p.front].g, coat); fig.insertBefore(shoes[p.front], coat);
+
+ // coat: drawn around the forward knee, so the hem opens and closes with the stride
+ const kF = p.feet[p.front].knee, aF = p.feet[p.front].ankle;
+ const sh: Vec = [41, 41 + b], hemY = 92;
+ const fx = Math.max(kF[0] + 2.4, 46.4);
+ coat.setAttribute('d', `M${f(sh[0] - 6)} ${f(sh[1] + 1)} Q${f(sh[0] - 1)} ${f(sh[1] - 2.4)} ${f(sh[0] + 5)} ${f(sh[1] + 1)} L${f(fx - 0.6)} ${f(70 + b)} Q${f(fx)} ${f(82 + b * 0.5)} ${f(Math.max(fx, aF[0] - 4))} ${hemY} L${f(30.6)} ${hemY + 1} L${f(33.2)} ${f(70 + b)}Z`);
+ coatSeam.setAttribute('d', `M${f(sh[0] + 2.6)} ${f(sh[1] + 4)} L${f(sh[0] + 3.8)} ${f(66 + b)}`);
+
+ // head, hat (lifts when tipped), scarf tail streaming in the wind
+ const hc: Vec = [42.6, 31.6 + b];
+ head.setAttribute('cx', f(hc[0])); head.setAttribute('cy', f(hc[1]));
+ const lift = tip * 5;
+ hat.setAttribute('d', `M${f(hc[0] - 6.4)} ${f(hc[1] - 3.6 - lift)} L${f(hc[0] + 6.6)} ${f(hc[1] - 3.6 - lift)} Q${f(hc[0] + 4.4)} ${f(hc[1] - 5 - lift)} ${f(hc[0] + 4)} ${f(hc[1] - 8 - lift)} Q${f(hc[0])} ${f(hc[1] - 11 - lift)} ${f(hc[0] - 3.8)} ${f(hc[1] - 8 - lift)} Q${f(hc[0] - 4.2)} ${f(hc[1] - 5 - lift)} ${f(hc[0] - 6.4)} ${f(hc[1] - 3.6 - lift)}Z`);
+ scarf.setAttribute('d', `M${f(hc[0] - 4.6)} ${f(hc[1] + 4.6)} Q${f(hc[0])} ${f(hc[1] + 8.4)} ${f(hc[0] + 4)} ${f(hc[1] + 4.8)} L${f(hc[0] + 4.4)} ${f(hc[1] + 7.6)} Q${f(hc[0])} ${f(hc[1] + 11)} ${f(hc[0] - 4.8)} ${f(hc[1] + 7.4)}Z`);
+ const flow = tail.step(-6 - walk.speed * 0.08 * go - wind.value * 5 + Math.sin(t * 9) * 0.8, dt);
+ scarfTail.setAttribute('d', `M${f(hc[0] - 3.6)} ${f(hc[1] + 6)} Q${f(hc[0] - 6 + flow * 0.4)} ${f(hc[1] + 9)} ${f(hc[0] - 4 + flow)} ${f(hc[1] + 16 + flow * 0.2)} L${f(hc[0] - 1 + flow * 0.9)} ${f(hc[1] + 16.6 + flow * 0.2)} Q${f(hc[0] - 3 + flow * 0.3)} ${f(hc[1] + 10)} ${f(hc[0] - 0.8)} ${f(hc[1] + 7.4)}Z`);
+
+ // arms swing opposite the legs, through springs so they lag and settle
+ const legSwing = (p.feet[0].ankle[0] - 40) / (walk.stride / 2); // -1..1, near leg
+ const farA = armSwing[0].step(-legSwing * 16 * go, dt) * Math.PI / 180;
+ const nearA = armSwing[1].step(legSwing * 14 * go, dt) * Math.PI / 180;
+ const shF: Vec = [sh[0] - 1, sh[1] + 2], shN: Vec = [sh[0] + 1.6, sh[1] + 2.4];
+ const elbF: Vec = [shF[0] + 17 * Math.sin(farA), shF[1] + 17 * Math.cos(farA)];
+ farArm.draw([shF, elbF, [elbF[0] + 16 * Math.sin(farA + 0.25), elbF[1] + 16 * Math.cos(farA + 0.25)]], [0.2, 0.5]);
+ let hand: Vec;
+ if (tip > 0.01) {
+ // near arm goes to the hat brim
+ const target: Vec = [hc[0] + 4, hc[1] - 4 - lift];
+ const mid = lerpP(shN, target, 0.5);
+ const elb: Vec = [mid[0] + 7 * tip, mid[1] + 3];
+ hand = lerpP([shN[0] + 17 * Math.sin(nearA) + 16 * Math.sin(nearA + 0.1), shN[1] + 33], target, tip);
+ nearArm.draw([shN, lerpP([shN[0] + 17 * Math.sin(nearA), shN[1] + 17], elb, tip), hand], [0.2, 0.4]);
+ } else {
+ const elb: Vec = [shN[0] + 17 * Math.sin(nearA), shN[1] + 17 * Math.cos(nearA)];
+ hand = [elb[0] + 16 * Math.sin(nearA + 0.1), elb[1] + 16 * Math.cos(nearA + 0.1)];
+ nearArm.draw([shN, elb, hand], [0.2, 0.4]);
+ }
+ // briefcase hangs from the near hand (or rests on the ground-side when tipping)
+ const accel = Math.cos(2 * Math.PI * phase * 2) * 1.6 * go;
+ const ca = caseSwing.step(-accel - wind.value * 0.3, dt);
+ const ch: Vec = tip > 0.01 ? [shN[0] + 6, shN[1] + 34] : hand;
+ caseG.setAttribute('transform', `rotate(${f(ca * 57.3)} ${pt(ch)})`);
+ handle.setAttribute('d', `M${f(ch[0] - 2.4)} ${f(ch[1] + 2.4)} Q${pt(ch)} ${f(ch[0] + 2.4)} ${f(ch[1] + 2.4)}`);
+ briefcase.setAttribute('d', `M${f(ch[0] - 8)} ${f(ch[1] + 2.4)} L${f(ch[0] + 8)} ${f(ch[1] + 2.4)} L${f(ch[0] + 8)} ${f(ch[1] + 13)} L${f(ch[0] - 8)} ${f(ch[1] + 13)}Z`);
+});
+
+function lerpP(a: Vec, b: Vec, t: number): Vec { t = clamp(t, 0, 1); return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]; }
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..ca39af2
--- /dev/null
+++ b/index.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>line-art-animation</title>
+<style>
+ body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #ebe8e2; color: #1c1c1c;
+ font: 15px/1.6 ui-serif, "Iowan Old Style", Georgia, serif; }
+ main { width: min(560px, 90vw); }
+ h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
+ p { margin: 0 0 20px; color: #5a554d; }
+ a { display: block; padding: 14px 0; border-top: 1px solid rgba(28, 28, 28, .12); color: inherit; text-decoration: none; }
+ a:hover span { text-decoration: underline; }
+ small { display: block; color: #7a746a; font-size: 13px; }
+</style>
+</head>
+<body>
+<main>
+ <h1>line-art-animation</h1>
+ <p>Examples built with the library in <code>lib/</code>.</p>
+ <a href="examples/walker/"><span>Walker</span><small>One figure: gait, open-stroke limbs, springs, a click reaction. About 150 lines.</small></a>
+ <a href="examples/village/"><span>Village</span><small>A full scene: day/night cycle, lit windows, villagers, wind, a dozen interactions.</small></a>
+</main>
+</body>
+</html>
diff --git a/lib/daynight.ts b/lib/daynight.ts
new file mode 100644
index 0000000..bbe9980
--- /dev/null
+++ b/lib/daynight.ts
@@ -0,0 +1,67 @@
+// daynight.ts — time-of-day palette for line-art scenes.
+// τ ∈ [0,1): 0 midnight · 0.25 dawn · 0.5 noon · 0.75 dusk.
+//
+// Day is dark ink on warm paper. Night inverts it: pale ink on indigo paper, with
+// warm light from windows and lanterns. The ink flips while the paper is mid-dark,
+// so the low-contrast moment lasts about a second of a three-minute day.
+
+export type RGB = [number, number, number];
+type Ramp = Array<[pos: number, hex: string]>;
+
+export const toRGB = (h: string): RGB => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)) as RGB;
+export const rgb = (c: RGB): string => `rgb(${c.map((v) => Math.round(v)).join(',')})`;
+export const mix = (a: RGB, b: RGB, t: number): RGB => a.map((v, i) => v + (b[i] - v) * t) as RGB;
+const lum = (c: RGB) => (0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]) / 255;
+const smooth = (e0: number, e1: number, x: number) => { const t = Math.max(0, Math.min(1, (x - e0) / (e1 - e0))); return t * t * (3 - 2 * t); };
+
+/** Sample a cyclic colour ramp at u ∈ [0,1). */
+export function ramp(keys: Ramp, u: number): RGB {
+ u = ((u % 1) + 1) % 1;
+ const n = keys.length;
+ let i = n - 1;
+ for (let j = 0; j < n; j++) if (keys[j][0] <= u) i = j;
+ const [p0, c0] = keys[i], [p1, c1] = keys[(i + 1) % n];
+ const span = (i + 1 < n ? p1 : p1 + 1) - p0;
+ let x = u - p0; if (x < 0) x += 1;
+ return mix(toRGB(c0), toRGB(c1), smooth(0, 1, x / span));
+}
+
+export const SKY_TOP: Ramp = [[0, '#0d1222'], [0.19, '#131a30'], [0.235, '#3d4066'], [0.27, '#cfd8e2'], [0.33, '#f3f2ee'], [0.5, '#f6f5f1'], [0.68, '#f3eee4'], [0.735, '#e3c6a6'], [0.762, '#5a5279'], [0.8, '#1b2140'], [0.86, '#0d1222']];
+export const SKY_BOTTOM: Ramp = [[0, '#1a2240'], [0.19, '#283050'], [0.235, '#d49884'], [0.27, '#f3d0b3'], [0.33, '#faf6ee'], [0.5, '#fcfbf7'], [0.68, '#f9efdc'], [0.735, '#f0a379'], [0.762, '#d47f68'], [0.8, '#383a60'], [0.86, '#1a2240']];
+export const PAPERS: Ramp = [[0, '#1a2036'], [0.19, '#1f263e'], [0.235, '#4a4561'], [0.27, '#ede4d8'], [0.33, '#fbf8f1'], [0.5, '#fdfcf8'], [0.68, '#faf4e8'], [0.735, '#f0dbc4'], [0.756, '#5d5571'], [0.8, '#262c48'], [0.86, '#1a2036']];
+const INK_DARK = toRGB('#1c1c1c'), INK_LIGHT = toRGB('#efe6cf');
+
+export interface Palette {
+ top: RGB; bottom: RGB; paper: RGB; ink: RGB;
+ /** 0 day ink … 1 night ink — use to darken flat colours at night. */
+ inkT: number;
+ /** 0 bright day … 1 dark. Give each light its own threshold so they come on one by one. */
+ lamp: number;
+ /** Stars, moon glow, fireflies. */
+ night: number;
+ /** Warm horizon light around dawn and dusk. */
+ sunset: number;
+}
+
+export function palette(tau: number): Palette {
+ const top = ramp(SKY_TOP, tau), bottom = ramp(SKY_BOTTOM, tau), paper = ramp(PAPERS, tau);
+ const L = lum(paper);
+ const inkT = smooth(0.56, 0.36, L);
+ return {
+ top, bottom, paper, inkT,
+ ink: mix(INK_DARK, INK_LIGHT, inkT),
+ lamp: smooth(0.78, 0.4, L),
+ night: smooth(0.42, 0.1, lum(top)),
+ sunset: Math.max(smooth(0.67, 0.735, tau) * smooth(0.79, 0.745, tau), smooth(0.215, 0.245, tau) * smooth(0.3, 0.26, tau)),
+ };
+}
+
+/** Apply a palette to an <svg> drawn with ink.ts (needs `.pp { fill: var(--paper) }` in CSS). */
+export function applyPalette(svg: SVGSVGElement, P: Palette): void {
+ svg.style.color = rgb(P.ink);
+ svg.style.setProperty('--paper', rgb(P.paper));
+}
+
+/** Darken a flat colour (clothes, props) toward night so it sits in the inverted palette. */
+export const nightTint = (colour: string, P: Palette, amount = 0.55): string =>
+ rgb(mix(toRGB(colour), mix(toRGB(colour), [12, 16, 30], 0.6), P.inkT * amount));
diff --git a/lib/gait.ts b/lib/gait.ts
new file mode 100644
index 0000000..96cdccc
--- /dev/null
+++ b/lib/gait.ts
@@ -0,0 +1,128 @@
+// gait.ts — walk and run solvers for a figure drawn in ink.ts figure space
+// (feet on y = 120, facing +x, hip above x = 40).
+//
+// A believable gait comes from four rules, all built in here:
+// 1. The planted foot slides back at exactly the travel speed (`speed`), so it
+// stays still on the ground while the figure moves by `speed`.
+// 2. The swinging foot follows a minimum-jerk path: low for walking, with a heel
+// kick for running.
+// 3. The heel peels off before the swing: the foot pivots on its toe.
+// 4. Hip height comes from what the planted legs can reach, so a walker rises over
+// each step and dips when both feet are down. A runner compresses over the
+// planted foot and is highest in flight. No sine bobbing.
+//
+// const walk = gait({ kind: 'walk' });
+// phase += dt / walk.period; x += dir * walk.speed * scale * dt;
+// const p = walk.pose(phase); // hip, feet[0..1] { ankle, knee, pitch, stance }, front, bob
+
+import type { Vec } from './ink.ts';
+
+export type GaitKind = 'walk' | 'shuffle' | 'run';
+
+export interface GaitOptions {
+ kind?: GaitKind;
+ /** Seconds for one full left+right cycle. */
+ period?: number;
+ /** Fraction of the cycle each foot is planted (walk ≈ 0.6, run ≈ 0.35). */
+ duty?: number;
+ /** Distance a planted foot travels under the body, figure units. */
+ stride?: number;
+ /** Peak foot lift during the swing. */
+ lift?: number;
+ /** Degrees the foot pitches toe-down as the heel peels off. */
+ heelOff?: number;
+ /** Runners: how far the heel kicks back before the foot comes through. 0 for walks. */
+ heelKick?: number;
+ thigh?: number;
+ shin?: number;
+ /** Ankle height when the foot is flat: ground − 1.6 for shoes, ground − 4 for geta or clogs. */
+ ankleY?: number;
+ ground?: number;
+ /** Ankle-to-toe distance; the foot pivots on the toe at heel-off. */
+ toe?: number;
+}
+
+export interface Foot { ankle: Vec; knee: Vec; pitch: number; stance: boolean }
+export interface Pose { hip: Vec; feet: [Foot, Foot]; front: 0 | 1; bob: number }
+export interface Gait extends Required<GaitOptions> {
+ /** Figure units per second. Multiply by the figure's scale for scene speed. */
+ speed: number;
+ /** phase in cycles; go ∈ [0,1] blends both feet to a standstill (for stopping to bow, wave …). */
+ pose(phase: number, go?: number): Pose;
+}
+
+const clamp = (x: number, a: number, b: number) => Math.max(a, Math.min(b, x));
+const smooth = (e0: number, e1: number, x: number) => { const t = clamp((x - e0) / (e1 - e0), 0, 1); return t * t * (3 - 2 * t); };
+const minJerk = (s: number) => s * s * s * (10 - 15 * s + 6 * s * s);
+
+function knee(hip: Vec, ankle: Vec, l1: number, l2: number): Vec {
+ const dx = ankle[0] - hip[0], dy = ankle[1] - hip[1];
+ const d = Math.min(Math.hypot(dx, dy), l1 + l2 - 0.01);
+ const th = Math.atan2(dy, dx);
+ const al = Math.acos(clamp((l1 * l1 + d * d - l2 * l2) / (2 * l1 * d), -1, 1));
+ const c1: Vec = [hip[0] + l1 * Math.cos(th - al), hip[1] + l1 * Math.sin(th - al)];
+ const c2: Vec = [hip[0] + l1 * Math.cos(th + al), hip[1] + l1 * Math.sin(th + al)];
+ return c1[0] > c2[0] ? c1 : c2; // knees bend forward
+}
+
+export const GAIT_PRESETS: Record<GaitKind, Required<Omit<GaitOptions, 'kind'>>> = {
+ // natural adult walk, ~2 steps/s
+ walk: { period: 1.0, duty: 0.62, stride: 24, lift: 3.4, heelOff: 15, heelKick: 0, thigh: 23, shin: 23, ankleY: 118.4, ground: 120, toe: 4.2 },
+ // kimono, tight skirt, geta: shorter stride, very low lift
+ shuffle: { period: 0.9, duty: 0.64, stride: 18, lift: 2.4, heelOff: 12, heelKick: 0, thigh: 23, shin: 23, ankleY: 116, ground: 120, toe: 4.2 },
+ // child's or adult's run: short ground contact, flight phase, heel kick
+ run: { period: 0.5, duty: 0.36, stride: 16, lift: 12, heelOff: 10, heelKick: 3.5, thigh: 13, shin: 13, ankleY: 118, ground: 120, toe: 3 },
+};
+
+export function gait(opts: GaitOptions = {}): Gait {
+ const kind = opts.kind ?? 'walk';
+ const o = { ...GAIT_PRESETS[kind], ...opts, kind };
+ const { period, duty, stride: S, lift, heelOff, heelKick, thigh, shin, ankleY, ground, toe } = o;
+ const reach = (thigh + shin) * 0.983; // a planted leg is nearly, not perfectly, straight
+ const restHip = ankleY - reach;
+ const speed = S / (duty * period);
+
+ const foot = (u: number): Omit<Foot, 'knee'> => {
+ u = ((u % 1) + 1) % 1;
+ if (u < duty) {
+ const x = 40 + S / 2 - (S * u) / duty;
+ const peel = smooth(duty - 0.14, duty, u);
+ const th = (heelOff * peel * Math.PI) / 180;
+ const px = x + toe, py = ground, ox = -toe, oy = ankleY - ground; // pivot on the toe, on the ground
+ return { ankle: [px + ox * Math.cos(th) - oy * Math.sin(th), py + ox * Math.sin(th) + oy * Math.cos(th)], pitch: heelOff * peel, stance: true };
+ }
+ const s = (u - duty) / (1 - duty);
+ const x = 40 - S / 2 + S * minJerk(s) - heelKick * Math.sin(Math.PI * Math.min(1, s * 1.6));
+ const y = ankleY - lift * Math.pow(Math.sin(Math.PI * Math.pow(s, heelKick ? 0.7 : 1)), 1.2);
+ return { ankle: [x, y], pitch: heelOff * Math.pow(1 - smooth(0, 0.55, s), 1.4), stance: false };
+ };
+
+ return {
+ ...o,
+ speed,
+ pose(phase, go = 1) {
+ const raw = [foot(phase), foot(phase + 0.5)];
+ if (go < 1) raw.forEach((fo, i) => {
+ const rest = 40 + (i ? -2 : 2);
+ fo.ankle = [rest + (fo.ankle[0] - rest) * go, ankleY + (fo.ankle[1] - ankleY) * go];
+ fo.pitch *= go; fo.stance = true;
+ });
+ let hipY = restHip;
+ const half = (((phase % 0.5) + 0.5) % 0.5);
+ if (heelKick && go >= 1) {
+ // run: compress over the planted foot, highest mid-flight
+ hipY = half < duty ? restHip + 1.4 * Math.sin((Math.PI * half) / duty) : restHip - 2.6 * Math.sin((Math.PI * (half - duty)) / (0.5 - duty));
+ } else {
+ // walk: lowest at double support, highest as the legs pass
+ for (const fo of raw) if (fo.stance) {
+ const dx = fo.ankle[0] - 40;
+ hipY = Math.max(hipY, fo.ankle[1] - Math.sqrt(Math.max(1, reach * reach - dx * dx)));
+ }
+ }
+ const hip: Vec = [40, hipY];
+ const feet = raw.map((fo) => ({ ...fo, knee: knee(hip, fo.ankle, thigh, shin) })) as [Foot, Foot];
+ const front: 0 | 1 = feet[0].ankle[0] >= feet[1].ankle[0] ? 0 : 1;
+ return { hip, feet, front, bob: hipY - restHip };
+ },
+ };
+}
diff --git a/lib/ink.ts b/lib/ink.ts
new file mode 100644
index 0000000..071a021
--- /dev/null
+++ b/lib/ink.ts
@@ -0,0 +1,189 @@
+// ink.ts — pen, paper and the drawing primitives every line-art figure shares.
+//
+// Conventions
+// - Draw each figure in its own space: ~95 units tall, feet on y = 120, facing +x,
+// standing on x = 40. Place it in a scene with `place()`.
+// - Ink is `currentColor`; paper fills get class "pp". Set `color` and `--paper`
+// on the <svg> (with `.pp { fill: var(--paper) }` in CSS) to retint everything,
+// e.g. pale ink on indigo paper at night.
+// - Create nodes once, then update `d`/attributes each frame. Nothing here allocates DOM per frame.
+
+/** A point produced by the library. */
+export type Vec = [number, number];
+/** Any point you pass in: a tuple or a plain [x, y] array. */
+export type Pt = readonly number[];
+export type Attrs = Record<string, string | number>;
+
+export const NS = 'http://www.w3.org/2000/svg';
+export const INK = 'currentColor';
+export const PAPER = '#fdfdfc';
+export const INK_DAY = '#1c1c1c';
+/** Pen width in figure units: ≈1.4 % of a 95-unit figure. */
+export const PEN = 1.35;
+
+export function el<K extends keyof SVGElementTagNameMap>(tag: K, attrs: Attrs = {}, parent?: Element | null): SVGElementTagNameMap[K] {
+ const n = document.createElementNS(NS, tag);
+ for (const k in attrs) n.setAttribute(k, String(attrs[k]));
+ if (attrs.fill === PAPER) n.classList.add('pp');
+ if (parent) parent.appendChild(n);
+ return n;
+}
+export const f = (n: number): string => n.toFixed(2);
+export const pt = (p: readonly number[]): string => `${f(p[0])} ${f(p[1])}`;
+
+/** Open pen stroke. */
+export const pen = (parent: Element, w = PEN): SVGPathElement =>
+ el('path', { fill: 'none', stroke: INK, 'stroke-width': w, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }, parent);
+
+/** Closed outline filled with paper — hides what is behind it (coats, heads, walls, roofs). */
+export const shape = (parent: Element, w = PEN): SVGPathElement =>
+ el('path', { fill: PAPER, stroke: INK, 'stroke-width': w, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' }, parent);
+
+/** Solid ink: shoes, hair, feet, small dark details. */
+export const blot = (parent: Element): SVGPathElement => el('path', { fill: INK }, parent);
+
+/** Closed outline with a flat colour fill (clothes, props). Re-set `fill` per frame if it should darken at night. */
+export const paint = (parent: Element, colour: string, w = PEN): SVGPathElement =>
+ el('path', { fill: colour, stroke: INK, 'stroke-width': w, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' }, parent);
+
+export interface Limb {
+ g: SVGGElement;
+ /** joints: [start, end] or [start, bend, end]. endGap: how far each pen line stops short at the far end. */
+ draw(joints: readonly Pt[], endGap?: readonly [number, number]): void;
+}
+
+/**
+ * A limb drawn as two separate pen lines either side of a soft curve through the
+ * joints, open at the ends, paper between them. This open double stroke is the
+ * single most recognisable trait of the style — never draw limbs as closed tubes.
+ */
+export function limb(parent: Element, width: number, w = PEN): Limb {
+ const g = el('g', {}, parent);
+ const fill = el('path', { fill: PAPER }, g);
+ const a = pen(g, w), b = pen(g, w);
+ const half = (width - w) / 2;
+ return {
+ g,
+ draw(joints, endGap = [0.4, 0.9]) {
+ const s = joints[0], e = joints[joints.length - 1];
+ let c: Vec = [(s[0] + e[0]) / 2, (s[1] + e[1]) / 2];
+ if (joints.length === 3) { const m = joints[1]; c = [m[0] + 0.55 * (m[0] - c[0]), m[1] + 0.55 * (m[1] - c[1])]; }
+ const P: Vec[] = [];
+ for (let i = 0; i <= 16; i++) {
+ const t = i / 16, u = 1 - t;
+ P.push([u * u * s[0] + 2 * u * t * c[0] + t * t * e[0], u * u * s[1] + 2 * u * t * c[1] + t * t * e[1]]);
+ }
+ const side = (sgn: number): Vec[] => P.map((p, i) => {
+ const q = P[Math.min(P.length - 1, i + 1)], o = P[Math.max(0, i - 1)];
+ const dx = q[0] - o[0], dy = q[1] - o[1], l = Math.hypot(dx, dy) || 1;
+ return [p[0] - (dy / l) * half * sgn, p[1] + (dx / l) * half * sgn];
+ });
+ const L = side(1), R = side(-1);
+ fill.setAttribute('d', 'M' + L.map(pt).join('L') + 'L' + R.slice().reverse().map(pt).join('L') + 'Z');
+ const cut = (arr: Vec[], gap: number) => arr.slice(0, arr.length - Math.round(gap * 2));
+ a.setAttribute('d', 'M' + cut(L, endGap[0]).map(pt).join('L'));
+ b.setAttribute('d', 'M' + cut(R, endGap[1]).map(pt).join('L'));
+ },
+ };
+}
+
+/** Give a limb a solid fill (black trousers, sleeves). Drops the paper class so CSS can't override it. */
+export function solid(l: Limb, colour = INK): Limb {
+ const n = l.g.querySelector('path');
+ if (n) { n.classList.remove('pp'); n.setAttribute('fill', colour); }
+ return l;
+}
+
+/** Two-bone IK. bend = +1 puts the middle joint toward +x (knees), -1 toward -x. */
+export function joint(a: Pt, b: Pt, l1: number, l2: number, bend: 1 | -1 = 1): Vec {
+ const dx = b[0] - a[0], dy = b[1] - a[1];
+ const d = Math.min(Math.hypot(dx, dy), l1 + l2 - 0.01);
+ const th = Math.atan2(dy, dx);
+ const al = Math.acos(Math.max(-1, Math.min(1, (l1 * l1 + d * d - l2 * l2) / (2 * l1 * d))));
+ const c1: Vec = [a[0] + l1 * Math.cos(th - al), a[1] + l1 * Math.sin(th - al)];
+ const c2: Vec = [a[0] + l1 * Math.cos(th + al), a[1] + l1 * Math.sin(th + al)];
+ return (c1[0] - c2[0]) * bend > 0 ? c1 : c2;
+}
+
+/** Point `len` away at `deg` from straight down (forward = positive). */
+export const hang = (from: Pt, len: number, deg: number): Vec => {
+ const r = (deg * Math.PI) / 180;
+ return [from[0] + len * Math.sin(r), from[1] + len * Math.cos(r)];
+};
+
+/** Periodic Catmull-Rom through [time, value] keys — the place for keyed or measured poses. */
+export function curve(keys: readonly Pt[], period: number): (x: number) => number {
+ return (x) => {
+ x = ((x % period) + period) % period;
+ const n = keys.length;
+ let i = n - 1;
+ for (let j = 0; j < n; j++) if (keys[j][0] <= x) i = j;
+ const k = (j: number): Vec => { const w = Math.floor(j / n); const e = keys[((j % n) + n) % n]; return [e[0] + w * period, e[1]]; };
+ const p0 = k(i - 1), p1 = k(i), p2 = k(i + 1), p3 = k(i + 2);
+ const span = p2[0] - p1[0];
+ const u = (x - p1[0]) / span;
+ const m1 = ((p2[1] - p0[1]) / (p2[0] - p0[0])) * span;
+ const m2 = ((p3[1] - p1[1]) / (p3[0] - p1[0])) * span;
+ const u2 = u * u, u3 = u2 * u;
+ return (2 * u3 - 3 * u2 + 1) * p1[1] + (u3 - 2 * u2 + u) * m1 + (-2 * u3 + 3 * u2) * p2[1] + (u3 - u2) * m2;
+ };
+}
+
+/** Shoe: a fat ink wedge at the ankle, pitched by `toe` degrees (toe down positive). */
+export function shoe(node: SVGPathElement, ankle: Pt, toe = 0): void {
+ const r = (toe * Math.PI) / 180, c = Math.cos(r), s = Math.sin(r);
+ const S = (x: number, y: number): Vec => [ankle[0] + x * c - y * s, ankle[1] + x * s + y * c];
+ node.setAttribute('d', `M${pt(S(-1.6, -0.6))} L${pt(S(4.6, -0.2))} Q${pt(S(6.6, 0.4))} ${pt(S(5.6, 1.6))} L${pt(S(-1.4, 1.5))} Q${pt(S(-2.2, 0.5))} ${pt(S(-1.6, -0.6))}Z`);
+}
+
+/** Place a figure group: its local (40, 120) lands on scene (x, y); dir ±1 mirrors it; s scales it. */
+export const place = (g: SVGGElement, x: number, y: number, dir: 1 | -1 = 1, s = 0.5): void =>
+ g.setAttribute('transform', `translate(${f(x)} ${f(y)}) scale(${f(dir * s)} ${f(s)}) translate(-40 -120)`);
+
+/** Scene coordinates of a figure-local point (for glows or effects drawn outside the figure). */
+export const toScene = (x: number, y: number, dir: 1 | -1, lx: number, ly: number, s = 0.5): Vec => [x + dir * s * (lx - 40), y + s * (ly - 120)];
+
+export interface InkDefs { defs: SVGDefsElement; filter: string; stripes: string }
+
+/** Wobble filter (so lines read as ink, not vector) and a stripe hatch for striped clothes. */
+export function inkDefs(svg: SVGSVGElement, id = 'ink'): InkDefs {
+ if (!svg.style.color) svg.style.color = INK_DAY;
+ const defs = el('defs', {}, svg);
+ const flt = el('filter', { id: `${id}-edge`, x: '-2%', y: '-2%', width: '104%', height: '104%' }, defs);
+ el('feTurbulence', { type: 'fractalNoise', baseFrequency: '0.6', numOctaves: 1, seed: 7, result: 'n' }, flt);
+ el('feDisplacementMap', { in: 'SourceGraphic', in2: 'n', scale: 0.45, xChannelSelector: 'R', yChannelSelector: 'G', result: 'd' }, flt);
+ el('feGaussianBlur', { in: 'd', stdDeviation: 0.12 }, flt);
+ const stripes = el('pattern', { id: `${id}-stripes`, width: 4, height: 2.2, patternUnits: 'userSpaceOnUse', patternTransform: 'rotate(-12)' }, defs);
+ el('rect', { width: 4, height: 2.2, fill: PAPER }, stripes);
+ el('rect', { width: 4, height: 1.0, fill: INK }, stripes);
+ return { defs, filter: `url(#${id}-edge)`, stripes: `url(#${id}-stripes)` };
+}
+
+declare global { interface Window { __step?: (seconds?: number) => number } }
+
+/**
+ * Animation loop calling draw(t, dt) with t and dt in seconds.
+ * ?t=1.25 freeze at a time (check a pose)
+ * ?debug no rAF; exposes window.__step(seconds) to advance in exact 1/60 s steps —
+ * for headless checks and frame capture (background tabs throttle rAF)
+ */
+export function run(draw: (t: number, dt: number) => void): () => void {
+ const q = new URLSearchParams(location.search);
+ if (q.has('debug')) {
+ let t = 0;
+ draw(t, 1 / 60);
+ window.__step = (s = 1) => { for (let i = 0, n = Math.round(s * 60); i < n; i++) draw((t += 1 / 60), 1 / 60); return t; };
+ return () => {};
+ }
+ const frozen = q.has('t') ? Number(q.get('t')) : null;
+ const still = frozen !== null || matchMedia('(prefers-reduced-motion: reduce)').matches;
+ const t0 = performance.now();
+ let id = 0, prev = 0;
+ const tick = (now: number) => {
+ const t = frozen ?? (now - t0) / 1000;
+ draw(t, Math.min(0.05, t - prev)); prev = t;
+ if (!still) id = requestAnimationFrame(tick);
+ };
+ id = requestAnimationFrame(tick);
+ return () => cancelAnimationFrame(id);
+}
diff --git a/lib/motion.ts b/lib/motion.ts
new file mode 100644
index 0000000..079f862
--- /dev/null
+++ b/lib/motion.ts
@@ -0,0 +1,80 @@
+// motion.ts — the small physics that make things feel alive without looking procedural.
+
+export const clamp = (x: number, a: number, b: number): number => Math.max(a, Math.min(b, x));
+export const lerp = (a: number, b: number, t: number): number => a + (b - a) * t;
+export const smooth = (e0: number, e1: number, x: number): number => { const t = clamp((x - e0) / (e1 - e0), 0, 1); return t * t * (3 - 2 * t); };
+export const ease = (t: number): number => smooth(0, 1, t);
+export const minJerk = (s: number): number => s * s * s * (10 - 15 * s + 6 * s * s);
+export const rnd = (a: number, b: number): number => a + Math.random() * (b - a);
+
+/** Seeded random for static drawing, so a scene looks the same on every load. */
+export function seeded(seed = 11): (a?: number, b?: number) => number {
+ let s = seed;
+ return (a = 0, b = 1) => { s = (s * 16807) % 2147483647; return a + ((s - 1) / 2147483646) * (b - a); };
+}
+
+/** Layered sines: organic drift for idle motion that doesn't read as a loop. */
+export const wobble = (t: number, k = 1): number => Math.sin(t * 1.3 * k) * 0.6 + Math.sin(t * 2.7 * k + 1.7) * 0.3 + Math.sin(t * 5.1 * k + 4.1) * 0.1;
+
+export interface Spring { x: number; v: number; step(target: number, dt: number): number; kick(v: number): void }
+
+/**
+ * Damped spring toward a moving target. Use for anything attached to a moving body:
+ * sleeves, bags, ears, a parasol's tilt, arms swinging opposite the legs.
+ */
+export function spring(stiffness = 40, damping = 6, x = 0): Spring {
+ return {
+ x, v: 0,
+ step(target, dt) { this.v += (stiffness * (target - this.x) - damping * this.v) * dt; this.x += this.v * dt; return this.x; },
+ kick(v) { this.v += v; },
+ };
+}
+
+export interface Pendulum { a: number; v: number; step(force: number, dt: number): number; kick(v: number): void }
+
+/**
+ * Pendulum (angle in radians) for hanging things: lanterns, curtains, chimes, signs, a briefcase.
+ * `force` is this frame's push — wind, the carrier's acceleration, a click.
+ */
+export function pendulum(stiffness = 10, damping = 1.1, a = 0): Pendulum {
+ return {
+ a, v: 0,
+ step(force, dt) { this.v += (-this.a * stiffness + force - this.v * damping) * dt; this.a += this.v * dt; return this.a; },
+ kick(v) { this.v += v; },
+ };
+}
+
+export interface Wind { value: number; step(t: number): number }
+
+/** Wind from pointer movement plus a slow breeze; `value` ≈ -2.4…2.4. A quick sideways swipe gusts it. */
+export function pointerWind(target: EventTarget, base = 0.3): Wind {
+ let aim = base, lastX: number | null = null, lastT = 0;
+ const w: Wind = {
+ value: base,
+ step(t) {
+ aim = lerp(aim, base + 0.25 * Math.sin(t * 0.21) + 0.15 * Math.sin(t * 0.67), 0.012);
+ w.value = lerp(w.value, aim, 0.05);
+ return w.value;
+ },
+ };
+ target.addEventListener('pointermove', (e) => {
+ const { clientX } = e as PointerEvent;
+ const now = performance.now();
+ if (lastX !== null) aim = clamp(aim + ((clientX - lastX) / Math.max(8, now - lastT)) * 0.8, -2.4, 2.4);
+ lastX = clientX; lastT = now;
+ });
+ return w;
+}
+
+export interface SequenceStep { from: string; to: string; u: number }
+
+/** A timed sequence of named poses for an interaction (sleep → sit → stretch …). Returns null when finished. */
+export function sequence(steps: Array<[name: string, seconds: number]>): (t: number) => SequenceStep | null {
+ const total = steps.reduce((a, s) => a + s[1], 0);
+ return (t) => {
+ if (t < 0 || t >= total) return null;
+ let acc = 0, prev = steps[0][0];
+ for (const [name, d] of steps) { if (t < acc + d) return { from: prev, to: name, u: (t - acc) / d }; acc += d; prev = name; }
+ return null;
+ };
+}
diff --git a/media/day.png b/media/day.png
new file mode 100644
index 0000000..b306582
Binary files /dev/null and b/media/day.png differ
diff --git a/media/night.png b/media/night.png
new file mode 100644
index 0000000..0587a07
Binary files /dev/null and b/media/night.png differ
diff --git a/media/village.gif b/media/village.gif
new file mode 100644
index 0000000..005e672
Binary files /dev/null and b/media/village.gif differ
diff --git a/media/walker.gif b/media/walker.gif
new file mode 100644
index 0000000..d24bba2
Binary files /dev/null and b/media/walker.gif differ
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..786e60a
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,1153 @@
+{
+ "name": "line-art-animation",
+ "version": "0.1.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "line-art-animation",
+ "version": "0.1.0",
+ "license": "MIT",
+ "devDependencies": {
+ "@types/node": "^22.18.0",
+ "typescript": "^5.9.3",
+ "vite": "^7.1.9"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz",
+ "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz",
+ "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz",
+ "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz",
+ "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz",
+ "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz",
+ "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz",
+ "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz",
+ "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz",
+ "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz",
+ "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz",
+ "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz",
+ "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz",
+ "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==",
+ "cpu": [
+ "mips64el"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz",
+ "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz",
+ "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz",
+ "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz",
+ "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz",
+ "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz",
+ "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz",
+ "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz",
+ "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz",
+ "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz",
+ "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz",
+ "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz",
+ "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz",
+ "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@rollup/rollup-android-arm-eabi": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.68.2.tgz",
+ "integrity": "sha512-ItKrNMkEL3hy85kLBXwB0+M6CWWVI8vr7RV+Eb7oDlQIMXLaiEhGfdaj5jAUadYn2v3nwzAhIRl/nLyjAqV9vQ==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ]
+ },
+ "node_modules/@rollup/rollup-android-arm64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.68.2.tgz",
+ "integrity": "sha512-dCkT8BMPLo6X6GCFVtuzrnr981PpJSeK4ZO/d/mZdJ/ao61Qa1Usd/OHIQ69MQgw4qQclR/X6uRRUONiWwD8cw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ]
+ },
+ "node_modules/@rollup/rollup-android-x64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-x64/-/rollup-android-x64-4.68.2.tgz",
+ "integrity": "sha512-p2jkKiscqQOGmyL6qu+KvJctvBc3SQTd+Xi2lQYn5QvFLEWz+QI8Z9iI+xcIjez6vKRsSnWP56Y3Ep7g3Stiug==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ]
+ },
+ "node_modules/@rollup/rollup-darwin-arm64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.68.2.tgz",
+ "integrity": "sha512-aVIfOteo5zoX8aL742H/S3QsyN6aokNYjdzrLnQBKxgRVoh4cibTErpi61RzSmrv2hBzDB1i751hwwdc8QK0vQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@rollup/rollup-darwin-x64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.68.2.tgz",
+ "integrity": "sha512-+Wuf4TFTHiE/WnjKgH1SkNf/9D5ddoed1UR0p3jxjNAGemdeeQRL+r1bJ1LlZyha0VKDBYLB2U/a9a9KlSw4Kw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ]
+ },
+ "node_modules/@rollup/rollup-freebsd-arm64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.68.2.tgz",
+ "integrity": "sha512-feKK2dc13j/6D9mAp7XKhBM/VUqn0N/xRgP6rT7/mdRVVJUaeZ4lsJ9hN90aTi0k3OD+mkjlcN01vQ96Ac9VzQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ]
+ },
+ "node_modules/@rollup/rollup-freebsd-x64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.68.2.tgz",
+ "integrity": "sha512-s1oGXPGX1PNqdi9TLWD+RwtPEYf/BOTbCcq4anJBqNbzyjucti86ldYH37eKvsyTP7Bl5/Hf8XmbIxCz/iafTA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm-gnueabihf": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.68.2.tgz",
+ "integrity": "sha512-ksR3ZmzHrm6HOUP8UlDBy5hNTcG9cEIa3EyGnxn5BjorLRjBh4ucxhwjwwVEm0dqcIN4Egc/XjDUiPQwN1ic9A==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm-musleabihf": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.68.2.tgz",
+ "integrity": "sha512-STZVVBM35wULVsQah0xKfCBQMPpHliOfjnRaUNT35jrbpfapUrD8ix6Yhl7tLHW0xQSWotXSSghjUi/DclwRSw==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.68.2.tgz",
+ "integrity": "sha512-Fm/GPC2R0zlJYQIp9aY9L1lO2z+P+UrcvXG6fhubfo/BbMOLZlLXshnbECOTqr3pxfZFb6nNn0QgDETDtrX7TQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-arm64-musl": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.68.2.tgz",
+ "integrity": "sha512-VoqlckWcwNF3WqsUkLZg91zYFgBvrC37Lc5e8AU+BKdCUFDMPoN0Rsin/LvF+rBVF527gWo5KT0oHkaAZaL1GA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-loong64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.68.2.tgz",
+ "integrity": "sha512-Zr8X/SUf7Jjwxt99BqPDF/Wq+sz4oUBIP6HBaFQWwb8wO1nV6LBIpD6jB9cMybLho93Z+B8rrN0uXEL6oNOUJQ==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-loong64-musl": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.68.2.tgz",
+ "integrity": "sha512-2EhrYEJNXIyhSZESwm/kCke1tiH7QAPOU3v3MsLM9J+Nfn2QCDe/pGROUAvYFK0BL2MEbzNgfrqrbnE5CFXkLw==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-ppc64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.68.2.tgz",
+ "integrity": "sha512-IC0dYuEQknw0m2FYBNBKlbrgBJBH5OMRiaRfCc4CFSpYnmDnqTpNSv+TgX+loezGTdRjBNZuYZi3t+Oc5NxNYg==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-ppc64-musl": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.68.2.tgz",
+ "integrity": "sha512-Zlzm6fGuDvtAqMEl071/g17vxq6u2Y2v/rON/gDY4NvzWLJ41BGAlwhF3QuAzwq05zIPo4LYzdqwhx3oisYCUw==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-riscv64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.68.2.tgz",
+ "integrity": "sha512-KhEpYRtHZ3Kj4shavjXeH+K1bQlA6UbP6MJ45rMPF/11JlZb1SRNLeuWCdigUEoMMaFO4+LwwcS+ew1SoLJu/g==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-riscv64-musl": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.68.2.tgz",
+ "integrity": "sha512-LPn9qvPsM/Ofd6Ekq3im6nB8Tk1ruJhTd3x/2bJkTR8m/XTsfxA+EU0RJ23WJqgJg123kitHAqbEK7B4cL1uPg==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-s390x-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.68.2.tgz",
+ "integrity": "sha512-Q1+E+pzSP+FiXuIZtxKR+pK7l2KQ9gsM+VaFPv1LR277kp7l61crG46WGLKLLay3Js5cvyU9Keqdzxa1EcFO+g==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-x64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.68.2.tgz",
+ "integrity": "sha512-3Btp4Lca/WzsmbaKu9Lh9d/XwyRDIegd/5khRBusHGw/Ll6SoF5Shn63OrjPdkLcpNi2PGDApXzNmxriRxGYjA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-linux-x64-musl": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.68.2.tgz",
+ "integrity": "sha512-5SKVaUiVs18+DGBnpg0mORGxgq/0udczngGxV/vf2nvK1djqpOKIxY/+8rBWxAbWGRE4RnnwxWabDwJN3pCwIQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ]
+ },
+ "node_modules/@rollup/rollup-openbsd-x64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.68.2.tgz",
+ "integrity": "sha512-KBpm48/lESsHgWd+dRlcy18APBYhXU4Jb6VlJoqbpWNwfpztFXwP22qVv9aHd3k1quSrmLeJwYLc7rpQ+BFZrw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ]
+ },
+ "node_modules/@rollup/rollup-openharmony-arm64": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.68.2.tgz",
+ "integrity": "sha512-o0D0bfRW8QGA1Ph6OzqVHMq5LRu1xkr1iM7qQIXUSFuR60ddXeDhN9UR4bUBPLYsrT46sZwwgQa51TWtBV3r5g==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-arm64-msvc": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.68.2.tgz",
+ "integrity": "sha512-r17kcu5kmd6WQwokYmfBnfwM/icureCWCPjpJVALcrSv5Lfy6Ggk9azxXor6hILhCHbc/4IfEiv+L5RXaOHinA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-ia32-msvc": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.68.2.tgz",
+ "integrity": "sha512-yUtOqq7ZrQoZ3WiHSR6QGTdOl4YgMHqXIYSBYU6siIcC0YF0pEwx7aGsPTm2mRwrmW6SMJkxzEdFm6wqXpmbNw==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-x64-gnu": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.68.2.tgz",
+ "integrity": "sha512-5IYoWxQGo5WECbJbImIf2w33uCHJNLv4o/FQtSyeYDed7AC6zx84NsEcGYccoI2geDEYkrxUXcsYK/6EhwVSIg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@rollup/rollup-win32-x64-msvc": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.68.2.tgz",
+ "integrity": "sha512-ee+c14ggUiM7lg4PtCjSBYU9O9dHp4FFespRnd5yj7SilUBJCL3x3aHlB+sIqbGjcPo3pEyODASnfKJuZ26YBw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ]
+ },
+ "node_modules/@types/estree": {
+ "version": "1.0.10",
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz",
+ "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@types/node": {
+ "version": "22.20.5",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz",
+ "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.28.2",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",
+ "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.28.2",
+ "@esbuild/android-arm": "0.28.2",
+ "@esbuild/android-arm64": "0.28.2",
+ "@esbuild/android-x64": "0.28.2",
+ "@esbuild/darwin-arm64": "0.28.2",
+ "@esbuild/darwin-x64": "0.28.2",
+ "@esbuild/freebsd-arm64": "0.28.2",
+ "@esbuild/freebsd-x64": "0.28.2",
+ "@esbuild/linux-arm": "0.28.2",
+ "@esbuild/linux-arm64": "0.28.2",
+ "@esbuild/linux-ia32": "0.28.2",
+ "@esbuild/linux-loong64": "0.28.2",
+ "@esbuild/linux-mips64el": "0.28.2",
+ "@esbuild/linux-ppc64": "0.28.2",
+ "@esbuild/linux-riscv64": "0.28.2",
+ "@esbuild/linux-s390x": "0.28.2",
+ "@esbuild/linux-x64": "0.28.2",
+ "@esbuild/netbsd-arm64": "0.28.2",
+ "@esbuild/netbsd-x64": "0.28.2",
+ "@esbuild/openbsd-arm64": "0.28.2",
+ "@esbuild/openbsd-x64": "0.28.2",
+ "@esbuild/openharmony-arm64": "0.28.2",
+ "@esbuild/sunos-x64": "0.28.2",
+ "@esbuild/win32-arm64": "0.28.2",
+ "@esbuild/win32-ia32": "0.28.2",
+ "@esbuild/win32-x64": "0.28.2"
+ }
+ },
+ "node_modules/fdir": {
+ "version": "6.5.0",
+ "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
+ "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "peerDependencies": {
+ "picomatch": "^3 || ^4"
+ },
+ "peerDependenciesMeta": {
+ "picomatch": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/nanoid": {
+ "version": "3.3.20",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz",
+ "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "bin": {
+ "nanoid": "bin/nanoid.cjs"
+ },
+ "engines": {
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
+ }
+ },
+ "node_modules/picocolors": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
+ "dev": true,
+ "license": "ISC"
+ },
+ "node_modules/picomatch": {
+ "version": "4.0.7",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
+ "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
+ "node_modules/postcss": {
+ "version": "8.5.32",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz",
+ "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/postcss/"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/funding/github/npm/postcss"
+ },
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "nanoid": "^3.3.20",
+ "picocolors": "^1.1.1",
+ "source-map-js": "^1.2.2"
+ },
+ "engines": {
+ "node": "^10 || ^12 || >=14"
+ }
+ },
+ "node_modules/rollup": {
+ "version": "4.68.2",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.68.2.tgz",
+ "integrity": "sha512-xzt45rKOxzEuqjTdkGTIEaePcq9xRELlFI1uoazlKap8T6bENJkONSCfhK51P6XFTixa4rosPcDHihSdduXndQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/estree": "^1.0.10"
+ },
+ "bin": {
+ "rollup": "dist/bin/rollup"
+ },
+ "engines": {
+ "node": ">=18.0.0",
+ "npm": ">=8.0.0"
+ },
+ "optionalDependencies": {
+ "@rollup/rollup-android-arm-eabi": "4.68.2",
+ "@rollup/rollup-android-arm64": "4.68.2",
+ "@rollup/rollup-android-x64": "4.68.2",
+ "@rollup/rollup-darwin-arm64": "4.68.2",
+ "@rollup/rollup-darwin-x64": "4.68.2",
+ "@rollup/rollup-freebsd-arm64": "4.68.2",
+ "@rollup/rollup-freebsd-x64": "4.68.2",
+ "@rollup/rollup-linux-arm-gnueabihf": "4.68.2",
+ "@rollup/rollup-linux-arm-musleabihf": "4.68.2",
+ "@rollup/rollup-linux-arm64-gnu": "4.68.2",
+ "@rollup/rollup-linux-arm64-musl": "4.68.2",
+ "@rollup/rollup-linux-loong64-gnu": "4.68.2",
+ "@rollup/rollup-linux-loong64-musl": "4.68.2",
+ "@rollup/rollup-linux-ppc64-gnu": "4.68.2",
+ "@rollup/rollup-linux-ppc64-musl": "4.68.2",
+ "@rollup/rollup-linux-riscv64-gnu": "4.68.2",
+ "@rollup/rollup-linux-riscv64-musl": "4.68.2",
+ "@rollup/rollup-linux-s390x-gnu": "4.68.2",
+ "@rollup/rollup-linux-x64-gnu": "4.68.2",
+ "@rollup/rollup-linux-x64-musl": "4.68.2",
+ "@rollup/rollup-openbsd-x64": "4.68.2",
+ "@rollup/rollup-openharmony-arm64": "4.68.2",
+ "@rollup/rollup-win32-arm64-msvc": "4.68.2",
+ "@rollup/rollup-win32-ia32-msvc": "4.68.2",
+ "@rollup/rollup-win32-x64-gnu": "4.68.2",
+ "@rollup/rollup-win32-x64-msvc": "4.68.2",
+ "fsevents": "~2.3.2"
+ }
+ },
+ "node_modules/source-map-js": {
+ "version": "1.2.2",
+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz",
+ "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==",
+ "dev": true,
+ "license": "BSD-3-Clause",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/tinyglobby": {
+ "version": "0.2.17",
+ "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
+ "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "fdir": "^6.5.0",
+ "picomatch": "^4.0.4"
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/SuperchupuDev"
+ }
+ },
+ "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": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/vite": {
+ "version": "7.3.8",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.8.tgz",
+ "integrity": "sha512-3tTi78MAKhVk9h+YZVXMQ8POmneJuE97QUPAWtJghHzhH7BAyiqQOC2KZh1DWOsu/USB2cRXhznPByaabvYXfw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "esbuild": "^0.27.0 || ^0.28.0",
+ "fdir": "^6.5.0",
+ "picomatch": "^4.0.3",
+ "postcss": "^8.5.6",
+ "rollup": "^4.43.0",
+ "tinyglobby": "^0.2.15"
+ },
+ "bin": {
+ "vite": "bin/vite.js"
+ },
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ },
+ "funding": {
+ "url": "https://github.com/vitejs/vite?sponsor=1"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ },
+ "peerDependencies": {
+ "@types/node": "^20.19.0 || >=22.12.0",
+ "jiti": ">=1.21.0",
+ "less": "^4.0.0",
+ "lightningcss": "^1.21.0",
+ "sass": "^1.70.0",
+ "sass-embedded": "^1.70.0",
+ "stylus": ">=0.54.8",
+ "sugarss": "^5.0.0",
+ "terser": "^5.16.0",
+ "tsx": "^4.8.1",
+ "yaml": "^2.4.2"
+ },
+ "peerDependenciesMeta": {
+ "@types/node": {
+ "optional": true
+ },
+ "jiti": {
+ "optional": true
+ },
+ "less": {
+ "optional": true
+ },
+ "lightningcss": {
+ "optional": true
+ },
+ "sass": {
+ "optional": true
+ },
+ "sass-embedded": {
+ "optional": true
+ },
+ "stylus": {
+ "optional": true
+ },
+ "sugarss": {
+ "optional": true
+ },
+ "terser": {
+ "optional": true
+ },
+ "tsx": {
+ "optional": true
+ },
+ "yaml": {
+ "optional": true
+ }
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..cac3eaa
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "line-art-animation",
+ "version": "0.1.0",
+ "private": true,
+ "type": "module",
+ "description": "A Claude skill and small TypeScript library for animated line-art SVG components.",
+ "license": "MIT",
+ "scripts": {
+ "dev": "vite",
+ "build": "vite build",
+ "typecheck": "tsc -p tsconfig.json && tsc -p examples/village/tsconfig.json",
+ "capture": "node scripts/capture.ts"
+ },
+ "devDependencies": {
+ "@types/node": "^22.18.0",
+ "typescript": "^5.9.3",
+ "vite": "^7.1.9"
+ }
+}
diff --git a/references/matching.md b/references/matching.md
new file mode 100644
index 0000000..5264fb7
--- /dev/null
+++ b/references/matching.md
@@ -0,0 +1,63 @@
+# Matching a reference clip
+
+When someone shares an animation and wants it "exactly like this", measure it. Guessed
+timing and poses were rejected every time; measured ones landed.
+
+## 0. Get the clip and fix the clock
+
+For an X post, `https://cdn.syndication.twimg.com/tweet-result?id=<id>&token=4` lists
+`mediaDetails[].video_info.variants`; take the highest-bitrate mp4.
+
+```sh
+ffprobe -v error -select_streams v -show_entries stream=r_frame_rate,avg_frame_rate,nb_frames clip.mp4
+```
+
+If `nb_frames / duration` isn't `r_frame_rate`, the clip is variable-frame-rate (most
+social clips are). Resample by time (`-vf fps=30`) everywhere and index by time.
+ffmpeg's `trim=start_frame` and `select='…n…'` count decoded frames, and `-f rawvideo`
+pads to the nominal rate — mixing those once doubled a walk's speed.
+
+## 1. Loop lengths
+
+```sh
+node scripts/clip.ts period clip.mp4 X Y W H --fps 60
+```
+
+Measure parts separately when they might loop independently: a dog's legs (0.52 s) and
+its body sway (1.3 s) had different periods. Identical-looking legs also match at half
+the cycle; use arms or props to tell which lag is the real one.
+
+## 2. Read poses off a grid
+
+```sh
+scripts/frames.sh clip.mp4 X Y W H out/ 6 40
+```
+
+Every 3 frames (30 fps) over one step, read hip, knees (only when bent), ankles and
+toe angle in source pixels (`px / scale`). Note the head height for body bob. Rigid
+parts (coat, head, an arm holding something) are measured once and ride on the hip.
+Put the numbers into `curve()` keys, or into `gait()` overrides (`stride`, `period`,
+`duty`, `lift`).
+
+## 3. Track what you can automatically
+
+```sh
+node scripts/clip.ts blobs clip.mp4 X Y W H BAND_Y0 BAND_Y1 --fps 30
+```
+
+prints dark-run centres per frame, e.g. ink-dot feet in the ground band. Fit centres,
+amplitudes and the period over the whole clip so nothing drifts by the end.
+
+## 4. Overlay check
+
+Add an `?overlay&t=` mode to the page: a `<video>` of the clip positioned so the crop
+lines up (`width: W_clip / W_crop × 100%`, `left: −X / W_crop × 100%`,
+`top: −Y / H_crop × 100%`), `currentTime = t` on `loadeddata`, and CSS that turns your
+ink red at 65 % opacity with paper fills set to `none`. Freeze your drawing at the same
+`t`. Check 0–0.6 s in 0.1 s steps and a few points late in the clip.
+
+## Copying vs. making new
+
+Measuring a clip's motion to match its feel is fine. Shipping its characters as your
+own is not: if the brief is "like this but new", reuse the medium and timing and draw
+new characters doing new things.
diff --git a/references/motion.md b/references/motion.md
new file mode 100644
index 0000000..bbccc82
--- /dev/null
+++ b/references/motion.md
@@ -0,0 +1,84 @@
+# Motion
+
+Animation here is mechanics first: solve where the body has to be, then draw around
+it. Free-running sines look procedural immediately; every rejected version of a walk
+had one.
+
+## Walking and running — `gait()`
+
+```ts
+import { gait } from '../lib/gait.ts';
+const walk = gait({ kind: 'walk' }); // or 'shuffle' (kimono, geta), 'run'
+let phase = 0;
+// per frame:
+phase += (dt / walk.period) * go; // go ∈ [0,1] slows to a stop
+x += dir * walk.speed * SCALE * dt * go; // exactly this speed, or feet slide
+const p = walk.pose(phase, go); // hip, feet[0..1] {ankle, knee, pitch, stance}, front, bob
+```
+
+What it does, so you can extend it rather than replace it:
+
+- **Planted foot** slides back under the hip at `stride / (duty × period)` — the travel
+ speed. Move by anything else and feet skate.
+- **Swing** follows a minimum-jerk curve with a low lift (walk 3.4, geta 2.4); runs add
+ a heel kick and a high, early lift.
+- **Heel-off**: in the last 14 % of stance the foot pivots on its toe (`pitch`).
+- **Hip height** is solved, not animated: for a walk, the lowest the planted legs can
+ reach (high at passing, dipped at double support); for a run, compressed over the
+ planted foot and highest in flight.
+
+Natural numbers to sanity-check against: adults ≈ 2 steps/s; kimono or geta steps
+are shorter and lower; children run at ≈ 4 steps/s with a forward lean.
+
+Draw from the pose: legs with `limb().draw([hip, knee, ankle])`, the leading leg on
+top (`p.front`), shoes at `ankle` with `pitch`. Hidden legs (under a kimono or coat)
+are still solved; the garment is drawn from `p.feet[p.front].knee` and both ankles:
+
+- front edge: from the waist, out over the forward knee, down to just past the front ankle
+- hem: from the front ankle to the rear ankle, so it opens into an A when the legs part
+- back edge: pushed back only when the rear leg extends behind
+- a fold line from the rear knee, an overlap line toward the front foot
+
+The upper body rides on `p.bob` (with a degree or two of lean), arms swing opposite
+the legs through springs, sleeves and bags hang on springs/pendulums.
+
+## Things that roll or push
+
+- **Wheels** roll without slipping: angle = distance / radius. Cranks turn at a
+ gear ratio of the wheel angle; feet sit on the pedals; legs are IK to the pedals.
+- **Poling a boat**: plant the pole tip at a fixed world point, let the boat surge
+ while the tip stays put (the pole leans back), lift it out, swing it forward. The
+ boat's speed follows the push, not a constant.
+
+## Things that hang or trail — springs and pendulums
+
+```ts
+const sleeve = spring(40, 6); // stiffness, damping
+sleeve.step(-1.4 + Math.sin(stepPhase) * 0.9, dt); // target moves, the sleeve lags
+const lantern = pendulum(10, 1.1);
+lantern.step(wind.value * 0.5 + carrierAccel, dt); // force this frame
+```
+
+Use them for sleeves, scarves, bags, parasol tilt, lanterns on hooks or sticks,
+curtains (one pendulum per panel), wind chimes (bell + clapper + paper strip, three
+coupled pendulums), willow strands, laundry. Drive them with wind, the carrier's
+acceleration, and clicks (`kick()`).
+
+## Idle life
+
+Things should never be perfectly still: breathing (±0.35 units), a tail-tip flick
+every few seconds, an ear twitch, birds that hop, turn, preen at random intervals
+(1–4 s), smoke puffs, water strokes drifting, stars twinkling. Randomise intervals,
+not shapes.
+
+## Gestures and reactions — keyed poses
+
+For interactions, key a few poses and blend between them over time
+(`sequence([['sit', 0.7], ['yawn', 0.9], ['stretch', 1.5], …])`, `curve()` for single
+channels). Ease each transition. Stop walking before gesturing (blend `go` to 0 over
+~0.4 s), then resume. Typical durations: bow 2.6 s, hat tip 1.6 s, cat wake-up 8 s.
+
+## Time compression
+
+If a scene runs a day in 30 s, people still walk at natural speed. Compress what can
+be compressed without looking fake — how often people arrive, the sky, the lights.
diff --git a/references/scenes.md b/references/scenes.md
new file mode 100644
index 0000000..2e7711b
--- /dev/null
+++ b/references/scenes.md
@@ -0,0 +1,76 @@
+# Scenes
+
+`examples/village` is the reference implementation of everything here.
+
+## The component
+
+- A card (rounded corners, soft shadow, `overflow: hidden`) on a fixed neutral page
+ background (`#ebe8e2`). The page never changes with the scene's time of day.
+- Any readout (a clock) or hint lives inside the card, coloured with the scene ink.
+- 2:1 is a good default aspect; size with `width: min(94vw, calc((100vh - 48px) * 2))`.
+- `touch-action: none` on the card if you use drag interactions.
+
+## Coordinates and layers
+
+Pick a scene viewBox (the village uses 960 × 480) and a figure scale (0.5 → figures
+≈ 48 tall; a doorway ≈ 60–66; a two-storey house ≈ 140–180). Set the scene pen to
+pen × figure scale so everything shares one line weight.
+
+Layer order, back to front:
+
+1. sky (gradient rect, stars, sun/moon, clouds, far hills in diluted ink at ~40 % opacity)
+2. behind-buildings (trees whose canopies rise above roofs, chimneys, wires, birds on wires)
+3. buildings
+4. street (paper fill), street furniture, a cat on a bench
+5. walkers — re-sorted every frame by their ground y
+6. foreground (water, a boat, a willow on the near bank)
+7. airborne particles (petals) with `pointer-events: none`
+8. glow layer: `mix-blend-mode: screen; pointer-events: none` — all light lives here
+9. hit areas for small targets
+
+Put `inkDefs().filter` on the scene group, not the sky or glow.
+
+## Day and night
+
+`palette(τ)` from `lib/daynight.ts`; call `applyPalette(svg, P)` each frame and keep
+`.pp { fill: var(--paper) }` in CSS. Things that follow time:
+
+- **Windows**: a pane drawn before its lattice, filled `mix(paper, warm, lit)`, plus a
+ radial glow. Give each its own on-threshold on `P.lamp` and some an off-time late at
+ night, so lights come on and go out one by one.
+- **Lanterns, street lamp, bike lamp, boat lantern**: same, with a light cone or flicker.
+- **Reflections**: horizontal warm strokes in the water under each lit source, jittered.
+- **Shops** take in their curtains after hours; laundry or stalls follow the day.
+- **Creatures**: birds roost at dusk, fireflies and moths at night, a cat's eyes glow.
+- Flat colours go through `nightTint(colour, P)`.
+
+Start the live component in the afternoon (τ ≈ 0.66) so a visitor sees dusk within a
+minute. Let the user drag the sun or moon along its arc to scrub time.
+
+## People and traffic
+
+Spawn walkers on per-type timers that depend on the hour (children by day, a lantern
+instead of a parasol after dark, fewer people deep at night). Start with two or three
+already on screen so the scene is never empty. Remove them when off-screen.
+
+## Wind
+
+`pointerWind(svg)` gives a smoothed value from pointer speed plus a slow breeze. Feed
+it to everything that hangs or floats — curtains, lanterns, chimes, petals, smoke,
+willow strands, water strokes, clouds.
+
+## Interactions
+
+Every clickable thing reacts in character, takes 1–8 s, and returns to idle by itself:
+a person bows or tips a hat; a cyclist rings the bell (and the birds scatter); a kid
+hops; a boatman sings; a cat wakes, yawns, stretches, grooms, curls up; birds flush and
+resettle; a lantern swings; a chime rings; a window slides open and someone waves;
+a tree drops petals; the water ripples and a fish jumps; the night sky gets a shooting
+star. Give small targets a transparent hit path with a `<title>`. Moving characters
+take `pointerdown` on their own group.
+
+## Performance
+
+Create every node once and only update attributes. Keep per-frame work to path strings
+(`f()` rounds to 2 dp). The village runs ~40 animated objects at 60 fps with the ink
+filter on.
diff --git a/references/style.md b/references/style.md
new file mode 100644
index 0000000..877d8f7
--- /dev/null
+++ b/references/style.md
@@ -0,0 +1,69 @@
+# Style
+
+The look in one sentence: one thin, slightly wobbly ink line on warm paper; open,
+economical figures without faces; flat muted colour used sparingly; buildings drawn
+straight-on like an elevation. Most of the effort goes into the line, not the colour.
+
+## Pen and paper
+
+| | value | why |
+|---|---|---|
+| pen | `1.35` figure units (≈1.4 % of a 95-unit figure) | thinner reads as vector, thicker as cartoon |
+| scene pen | pen × figure scale (0.5 scale → ~0.7–0.8) | architecture and figures must share one pen |
+| detail pen | 0.4–0.6 × pen | tile lines, slats, hatching, ribs |
+| ink (day) | `#1c1c1c` | not pure black |
+| paper (day) | `#fdfcf8` / `#fdfdfc` | warm, never pure white |
+| caps/joins | round | |
+| wobble | `inkDefs()` filter: turbulence 0.6, displacement 0.45, blur 0.12 | ink, not vector — keep it subtle |
+
+Fills are paper (`shape`) so things occlude each other like a drawing, solid ink
+(`blot`) for small dark parts, or one flat colour (`paint`) for clothes and props.
+No gradients on objects; gradients only for sky and light.
+
+## Figures
+
+Work in figure space: ~95 units tall, feet on y = 120, facing +x, standing at x = 40.
+
+- **Head**: small oval, about 7 × 9 units, faceless. Character comes from hair and
+ hats (bun, cap, bowler, straw hat, kasa), not faces.
+- **Neck**: short open double stroke.
+- **Body**: a simple garment silhouette — boxy coat with a straight front, kimono
+ column, striped shirt (`inkDefs().stripes`), solid trousers via `solid()`.
+- **Limbs**: `limb()` — two open strokes, rounded joints. Legs ~4.2 wide, arms ~3.6.
+ Arm length ≈ 0.44 × height: a hand holding a bag hangs at the thigh, not the waist.
+- **Feet**: `shoe()` wedges, or drawn geta/tabi; they peel off at the heel.
+- **Proportions**: head ≈ 1/9.5 of height for adults; children have bigger heads
+ (≈1/6), shorter limbs, and a straw hat or cap helps read age instantly.
+
+## Animals
+
+Open strokes only: a back line and a separate belly line, single-stroke legs ending
+in fat ink-dot feet, a small head with an ear. A cat sitting is a closed paper shape
+with a few patches; birds are a body oval, a cap blot, a tail line.
+
+## Architecture
+
+Draw buildings as street elevations (no perspective), with enough detail that the eye
+can wander — this is where richness comes from:
+
+- tiled roofs: tile channels converging to the ridge, round tile ends along the eave,
+ rafter ends under the fascia, a stacked ridge with end tiles, a slight upward sweep
+- façades: lattice slats with a rhythm (every fourth slat full height), plaster
+ windows with fat bars, shoji grids, low curved fences, blinds, signboards with real
+ lettering in the right script
+- props that tell you who lives there: barrels, pots, a bench, buckets, a bicycle
+
+Keep large areas of plain paper. Density belongs on the buildings, not the sky.
+
+## Colour
+
+Pick one or two accents and use them in small areas (a red parasol and lanterns, an
+indigo kimono, yellow pails). At night every flat colour is pushed toward the night
+palette with `nightTint()`, and ink becomes pale — see `scenes.md`.
+
+## Day and night
+
+Day: dark ink on warm paper, soft gradient sky. Night: the drawing inverts — pale ink
+on indigo paper — and light comes from the windows, lanterns, a street lamp, a bike
+lamp, fireflies, each with a warm radial glow on a `mix-blend-mode: screen` layer. The
+moon is a pale crescent, stars twinkle. This inversion is why ink is `currentColor`.
diff --git a/references/verify.md b/references/verify.md
new file mode 100644
index 0000000..bd2c91a
--- /dev/null
+++ b/references/verify.md
@@ -0,0 +1,68 @@
+# Verifying
+
+Check what the person will check — motion frame by frame and detail at zoom — before
+showing them anything.
+
+## 1. Types and build
+
+```sh
+npm run typecheck # tsc, strict for lib/ and small examples
+npm run build # vite build
+```
+
+## 2. Step time exactly
+
+Load the page with `?debug`. `run()` then skips rAF and exposes `window.__step(s)`,
+which advances in exact 1/60 s steps. Background tabs, embedded preview panes and
+headless browsers throttle rAF to a frame or two per second, which makes everything
+crawl and can make a working scene look broken — always check in debug mode.
+
+`?t=1.25` freezes a normal page at one moment.
+
+## 3. Look at frames, not screenshots of the whole card
+
+Pane screenshots are too downscaled to judge a 1-unit pen. Either temporarily widen
+the SVG container 4–11× and pan it over the area, or capture headless and crop:
+
+```sh
+node scripts/capture.ts "http://localhost:5173/examples/walker/?debug" /tmp/w 8 8 1920 1080
+ffmpeg -i /tmp/w/f%04d.png -vf "crop=560:500:330:330,scale=280:-1,tile=8x1" -frames:v 1 -update 1 strip.png
+```
+
+To follow a moving figure, pass setup and per-frame JS to `capture.ts` that pick the
+figure and re-centre a zoomed container on it, so one stride reads in place:
+
+```sh
+SETUP='window.K = __village.people[0]; true'
+FRAME='(() => { const v = document.querySelector("#village"), z = 11;
+ v.style.cssText = `width:${960*z}px;height:${480*z}px;position:fixed;left:${-(K.x-22)*z}px;top:${-(K.y-58)*z}px`;
+ return true })()'
+node scripts/capture.ts "http://localhost:5173/examples/village/?debug&tau=0.5" /tmp/g 9 8 480 640 "$SETUP" "$FRAME"
+```
+
+Expose whatever handles you need on `window` in the example (the village exposes
+`__village` with its people, cat, boat and spawn function).
+
+What to look for in a strip:
+
+- feet stay still while planted; no skating, no popping between frames
+- the body rises over the planted foot and dips at double support (walk)
+- clothing opens and closes with the stride; sleeves and bags lag, then settle
+- the leading leg is drawn on top
+- nothing is ruler-straight; limbs are open at the ends
+- props sit where hands are; a held bag hangs at the thigh
+
+## 4. Trigger every interaction
+
+Dispatch `pointerdown` on each hit area (`<title>` names them) and step through the
+reaction, taking frames at the start, middle and end. Check it returns to idle.
+
+## 5. Sweep the day
+
+Render at τ = 0.3, 0.5, 0.72, 0.75, 0.8, 0.95, 0.24: day, golden hour, sunset, the ink
+flip, night, late night (lights going out), dawn. Contrast must hold everywhere except
+the brief flip.
+
+## 6. Real frame rate
+
+In a foreground tab, count rAF callbacks for 3 s; expect ~60.
diff --git a/references/video.md b/references/video.md
new file mode 100644
index 0000000..79cf556
--- /dev/null
+++ b/references/video.md
@@ -0,0 +1,26 @@
+# Rendering to video
+
+Capture is deterministic: the page runs in `?debug` mode and `scripts/capture.ts`
+advances it by exactly 1/fps between screenshots, so motion is right regardless of
+machine speed.
+
+```sh
+npm run dev # or any server for the built files
+node scripts/capture.ts "http://localhost:5173/examples/village/?debug&capture&day=30&start=0.3" \
+ captures/village 900 30 1920 1080
+ffmpeg -framerate 30 -i captures/village/f%04d.png \
+ -c:v libx264 -preset slow -crf 15 -pix_fmt yuv420p -movflags +faststart -tune animation village.mp4
+```
+
+- 1080p at 30 fps for 30 s is 900 frames, about 90 s to capture.
+- Use page flags rather than code edits: the village supports `capture` (hides the
+ hint), `day=<seconds>` (length of a full day), `start=<τ>` (starting time, keeps
+ running) and `tau=<τ>` (pins the time).
+- A full day in 30 s from τ = 0.3 shows morning → noon → sunset → night → dawn.
+- Render the component in its card on the page background, so the video shows it as
+ a component.
+- Check a contact sheet before sending: `ffmpeg -i out.mp4 -vf "fps=1/3.75,scale=480:-1,tile=4x2" -frames:v 1 sheet.png`.
+- For a README or post, a short GIF: `ffmpeg -i out.mp4 -vf "fps=15,scale=800:-1:flags=lanczos,split[a][b];[a]palettegen[p];[b][p]paletteuse" out.gif`.
+
+`capture.ts` uses `$CHROME`, a Playwright Chromium in the user cache, or a system
+Chrome/Chromium; it exits non-zero and prints page errors if the page threw.
diff --git a/scripts/capture.ts b/scripts/capture.ts
new file mode 100644
index 0000000..4b1a776
--- /dev/null
+++ b/scripts/capture.ts
@@ -0,0 +1,79 @@
+// Deterministic frame capture of a page that uses ink.js `run()` with ?debug.
+// Drives headless Chrome over the DevTools protocol (Node ≥ 22, no npm deps),
+// advances the scene by exactly 1/fps between screenshots, writes PNGs.
+//
+// node scripts/capture.ts <url> <outDir> <frames> <fps> [width] [height] [setupJs] [perFrameJs]
+// (Node ≥ 22.18 runs .ts directly by stripping types.)
+//
+// The url must include ?debug (so the page exposes window.__step). Encode with:
+// ffmpeg -framerate 30 -i out/f%04d.png -c:v libx264 -preset slow -crf 15 -pix_fmt yuv420p -tune animation out.mp4
+// Set CHROME=/path/to/chrome to choose the browser.
+import { spawn } from 'node:child_process';
+import { mkdirSync, writeFileSync, existsSync, readdirSync } from 'node:fs';
+import { join } from 'node:path';
+
+const [url, outDir, framesArg, fpsArg, wArg, hArg, setupJs = '', frameJs = ''] = process.argv.slice(2);
+if (!url || !outDir || !framesArg) { console.error('usage: capture.ts <url> <outDir> <frames> <fps> [w] [h] [setupJs] [perFrameJs]'); process.exit(1); }
+const FRAMES = +framesArg, FPS = +(fpsArg || 30), W = +(wArg || 1920), H = +(hArg || 1080);
+
+function findChrome(): string | undefined {
+ if (process.env.CHROME) return process.env.CHROME;
+ const home = process.env.HOME || '';
+ const fromCache = (dir: string, test: (d: string) => string): string | null => {
+ if (!existsSync(dir)) return null;
+ for (const d of readdirSync(dir).sort().reverse()) { const p = test(join(dir, d)); if (p && existsSync(p)) return p; }
+ return null;
+ };
+ return fromCache(join(home, 'Library/Caches/ms-playwright'), (d) => join(d, 'chrome-headless-shell-mac-arm64/chrome-headless-shell'))
+ || fromCache(join(home, 'Library/Caches/ms-playwright'), (d) => join(d, 'chrome-headless-shell-mac-x64/chrome-headless-shell'))
+ || fromCache(join(home, '.cache/ms-playwright'), (d) => join(d, 'chrome-headless-shell-linux64/chrome-headless-shell'))
+ || ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium', '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser'].find(existsSync);
+}
+const CHROME = findChrome();
+if (!CHROME) { console.error('No Chrome found. Set CHROME=/path/to/chrome (or `npx playwright install chromium-headless-shell`).'); process.exit(1); }
+
+mkdirSync(outDir, { recursive: true });
+const port = 9400 + Math.floor(Math.random() * 400);
+const proc = spawn(CHROME, [`--remote-debugging-port=${port}`, '--headless', `--window-size=${W},${H}`, '--hide-scrollbars',
+ '--force-device-scale-factor=1', `--user-data-dir=${join(outDir, '.profile')}`, '--no-first-run', 'about:blank'], { stdio: 'ignore' });
+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
+const quit = (code: number): never => { try { proc.kill(); } catch {} return process.exit(code); };
+
+interface Target { type: string; webSocketDebuggerUrl: string }
+let list: Target[] = [];
+for (let i = 0; i < 60 && !list.length; i++) { try { list = ((await (await fetch(`http://127.0.0.1:${port}/json/list`)).json()) as Target[]).filter((t) => t.type === 'page'); } catch {} if (!list.length) await sleep(200); }
+if (!list.length) { console.error('Chrome did not start.'); quit(1); }
+const ws = new WebSocket(list[0].webSocketDebuggerUrl);
+await new Promise((r) => (ws.onopen = r));
+type Reply = { id?: number; method?: string; params?: any; result?: any; error?: { message: string } };
+let id = 0; const pending = new Map<number, (d: Reply) => void>(); const errors: string[] = [];
+ws.onmessage = (m: MessageEvent<string>) => {
+ const d: Reply = JSON.parse(m.data);
+ if (d.id && pending.has(d.id)) { pending.get(d.id)!(d); pending.delete(d.id); }
+ if (d.method === 'Runtime.exceptionThrown') errors.push(d.params.exceptionDetails.exception?.description || d.params.exceptionDetails.text);
+ if (d.method === 'Runtime.consoleAPICalled' && d.params.type === 'error') errors.push(d.params.args.map((a: { value?: unknown; description?: string }) => a.value ?? a.description).join(' '));
+};
+const send = (method: string, params: object = {}): Promise<any> => new Promise((res, rej) => { const i = ++id; pending.set(i, (d) => (d.error ? rej(new Error(`${method}: ${d.error.message}`)) : res(d.result))); ws.send(JSON.stringify({ id: i, method, params })); });
+const evalJs = async (expression: string): Promise<any> => { const r = await send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true }); if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description || r.exceptionDetails.text); return r.result.value; };
+
+await send('Page.enable'); await send('Runtime.enable');
+await send('Emulation.setDeviceMetricsOverride', { width: W, height: H, deviceScaleFactor: 1, mobile: false });
+await send('Page.navigate', { url });
+let ready = false;
+for (let i = 0; i < 100 && !ready; i++) { await sleep(150); try { ready = await evalJs('typeof __step === "function" && document.readyState === "complete"'); } catch {} }
+if (!ready) { console.error('Page never exposed __step — is ?debug in the url, and does the page use run()?', errors.join('\n')); quit(1); }
+await evalJs('document.fonts.ready.then(() => true)');
+await sleep(400);
+if (setupJs) await evalJs(setupJs);
+
+const t0 = Date.now();
+for (let i = 0; i < FRAMES; i++) {
+ if (i > 0) await evalJs(`__step(${1 / FPS})`);
+ if (frameJs) await evalJs(frameJs);
+ const { data } = (await send('Page.captureScreenshot', { format: 'png' })) as { data: string };
+ writeFileSync(join(outDir, `f${String(i).padStart(4, '0')}.png`), Buffer.from(data, 'base64'));
+ if (i % 60 === 0) process.stdout.write(`frame ${i}/${FRAMES} ${((Date.now() - t0) / 1000).toFixed(1)}s\n`);
+}
+console.log(`done: ${FRAMES} frames in ${((Date.now() - t0) / 1000).toFixed(1)}s`);
+if (errors.length) { console.error('page errors:\n' + [...new Set(errors)].join('\n')); quit(2); }
+ws.close(); quit(0);
diff --git a/scripts/clip.ts b/scripts/clip.ts
new file mode 100644
index 0000000..cb3e0d8
--- /dev/null
+++ b/scripts/clip.ts
@@ -0,0 +1,69 @@
+// Measure a reference clip. Needs ffmpeg on PATH; run with Node ≥ 22.18.
+//
+// node scripts/clip.ts period <clip> <x> <y> <w> <h> [--fps 60] [--min 10] [--max 200]
+// Loop length of a cropped region: frame-differences it against several
+// reference frames and prints the best lags in frames and seconds.
+//
+// node scripts/clip.ts blobs <clip> <x> <y> <w> <h> <bandY0> <bandY1> [--fps 30] [--dark 110] [--frames N]
+// Per frame, the x centres (source px) of dark runs inside a horizontal band of
+// the crop — e.g. ink-dot feet on a ground line. Fit centres, amplitude and
+// period from this output instead of eyeballing.
+//
+// Both resample by time (fps filter), because social-media clips are usually
+// variable-frame-rate and decoded frame numbers are not a clock.
+import { execFileSync } from 'node:child_process';
+
+const [mode, clip, ...rest] = process.argv.slice(2);
+const flags = new Map<string, string>();
+const pos: number[] = [];
+for (let i = 0; i < rest.length; i++) {
+ if (rest[i].startsWith('--')) flags.set(rest[i].slice(2), rest[++i]);
+ else pos.push(Number(rest[i]));
+}
+const flag = (k: string, d: number) => (flags.has(k) ? Number(flags.get(k)) : d);
+
+function frames(x: number, y: number, w: number, h: number, fps: number): Uint8Array[] {
+ const raw = execFileSync('ffmpeg', ['-v', 'error', '-i', clip, '-vf', `fps=${fps},crop=${w}:${h}:${x}:${y},format=gray`, '-f', 'rawvideo', '-'], { maxBuffer: 1 << 30 });
+ const n = w * h, out: Uint8Array[] = [];
+ for (let i = 0; i + n <= raw.length; i += n) out.push(raw.subarray(i, i + n));
+ return out;
+}
+
+if (mode === 'period' && pos.length >= 4) {
+ const [x, y, w, h] = pos;
+ const fps = flag('fps', 60), min = flag('min', 10), max = flag('max', 200);
+ const F = frames(x, y, w, h, fps), N = w * h;
+ const refs: number[] = [];
+ for (let r = 0; r < F.length - max - 1 && refs.length < 12; r += Math.max(1, Math.floor(fps / 6))) refs.push(r);
+ if (!refs.length) refs.push(0);
+ const score = new Map<number, number>();
+ for (let lag = min; lag < Math.min(max, F.length - 1); lag++) {
+ let s = 0;
+ for (const r of refs) {
+ if (r + lag >= F.length) continue;
+ const A = F[r], B = F[r + lag];
+ for (let i = 0; i < N; i += 3) s += Math.abs(A[i] - B[i]);
+ }
+ score.set(lag, s);
+ }
+ console.log(`${F.length} frames @ ${fps} fps`);
+ [...score.entries()].sort((a, b) => a[1] - b[1]).slice(0, 8)
+ .forEach(([lag, s]) => console.log(`lag ${String(lag).padStart(4)} frames = ${(lag / fps).toFixed(3)} s score ${s}`));
+} else if (mode === 'blobs' && pos.length >= 6) {
+ const [x, y, w, h, y0, y1] = pos;
+ const fps = flag('fps', 30), dark = flag('dark', 110), minPx = flag('min-px', 2), limit = flag('frames', 0);
+ const F = frames(x, y, w, h, fps);
+ const count = limit ? Math.min(limit, F.length) : F.length;
+ for (let i = 0; i < count; i++) {
+ const fr = F[i], runs: number[] = [];
+ const col = Array.from({ length: w }, (_, cx) => { let c = 0; for (let cy = y0; cy <= y1; cy++) if (fr[cy * w + cx] < dark) c++; return c; });
+ for (let cx = 0; cx < w;) {
+ if (col[cx] >= minPx) { const s = cx; while (cx < w && col[cx] >= minPx) cx++; runs.push(+(x + (s + cx - 1) / 2).toFixed(1)); }
+ else cx++;
+ }
+ console.log(`${String(i).padStart(3)} t=${(i / fps).toFixed(3).padStart(6)} [${runs.join(', ')}]`);
+ }
+} else {
+ console.error('usage:\n clip.ts period <clip> <x> <y> <w> <h> [--fps 60] [--min 10] [--max 200]\n clip.ts blobs <clip> <x> <y> <w> <h> <bandY0> <bandY1> [--fps 30] [--dark 110] [--frames N]');
+ process.exit(1);
+}
diff --git a/scripts/frames.sh b/scripts/frames.sh
new file mode 100755
index 0000000..61ddb2b
--- /dev/null
+++ b/scripts/frames.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+# Grid frames for reading poses off a clip:
+# scripts/frames.sh <clip> <x> <y> <w> <h> <outDir> [scale=6] [count=40]
+# Resamples to 30 fps by time, crops (x,y,w,h) in source px, scales up and draws a
+# light grid every 5 source px and a red one every 10. outDir/f01.png is t = 0.
+set -euo pipefail
+clip=$1 x=$2 y=$3 w=$4 h=$5 out=$6 s=${7:-6} n=${8:-40}
+mkdir -p "$out"
+ffmpeg -y -v error -i "$clip" -vf "fps=30,crop=$w:$h:$x:$y,scale=$((w*s)):$((h*s)):flags=neighbor,drawgrid=w=$((5*s)):h=$((5*s)):t=1:[email protected],drawgrid=w=$((10*s)):h=$((10*s)):t=1:[email protected]" -frames:v "$n" "$out/f%02d.png"
+echo "wrote $n frames to $out (1 source px = $s px, f01 = t 0)"
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 0000000..866c628
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "ESNext",
+ "moduleResolution": "Bundler",
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
+ "strict": true,
+ "noEmit": true,
+ "allowImportingTsExtensions": true,
+ "verbatimModuleSyntax": true,
+ "isolatedModules": true,
+ "skipLibCheck": true,
+ "types": ["node"]
+ },
+ "include": ["lib", "examples/walker", "scripts", "vite.config.ts"]
+}
diff --git a/vite.config.ts b/vite.config.ts
new file mode 100644
index 0000000..b324c68
--- /dev/null
+++ b/vite.config.ts
@@ -0,0 +1,14 @@
+import { defineConfig } from 'vite';
+import { resolve } from 'node:path';
+
+export default defineConfig({
+ build: {
+ rollupOptions: {
+ input: {
+ index: resolve(import.meta.dirname, 'index.html'),
+ walker: resolve(import.meta.dirname, 'examples/walker/index.html'),
+ village: resolve(import.meta.dirname, 'examples/village/index.html'),
+ },
+ },
+ },
+});