Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
chore: sync the plugin mirror
Alex Greenshpun4c2f36f0e2b9
diff --git a/plugins/anidoodle/.claude-plugin/plugin.json b/plugins/anidoodle/.claude-plugin/plugin.jsonindex 09f2b2d..a815201 100644--- a/plugins/anidoodle/.claude-plugin/plugin.json+++ b/plugins/anidoodle/.claude-plugin/plugin.json@@ -2,7 +2,7 @@"name": "anidoodle","displayName": "anidoodle","description": "Code-drawn stills, drawing timelapses, films, explainers and interactive web animations in 31 styles, with scores composed in code.",- "version": "0.6.1",+ "version": "0.6.2","icon": "./assets/icon.png","author": {"name": "Alex Greenshpun",diff --git a/plugins/anidoodle/.codex-plugin/plugin.json b/plugins/anidoodle/.codex-plugin/plugin.jsonindex 5a3368d..31184b7 100644--- a/plugins/anidoodle/.codex-plugin/plugin.json+++ b/plugins/anidoodle/.codex-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "anidoodle",- "version": "0.6.1",+ "version": "0.6.2","description": "Code-drawn stills, drawing timelapses, films, explainers and interactive web animations in 31 styles, with scores composed in code.","skills": "./skills/","interface": {diff --git a/plugins/anidoodle/skills/anidoodle/SKILL.md b/plugins/anidoodle/skills/anidoodle/SKILL.mdindex 257361b..8a12dac 100644--- a/plugins/anidoodle/skills/anidoodle/SKILL.md+++ b/plugins/anidoodle/skills/anidoodle/SKILL.md@@ -83,7 +83,7 @@ a beat is 60 x fps / bpm frames, the bpm from the brief's score; one cue table hruns at load. (3) **Real reference** for anything that exists. (4) **ONE look still**, the hardestframe, critiqued in writing. ✋ **Approval.** (5) **ONE 8-second music sample.** ✋ **Approval.**(6) **Build the whole film**; mechanical checks run continuously. (7) **Review once** from the-rendered file: a contact sheet per beat, each cut as a pair, the dead-air numbers. One ranked fix+rendered file, as four readings with a scorecard (`references/workflows/review.md`). One ranked fixlist, one rebuild. (8) ✋ **Final approval.** Say what you verified and what you cannot.Three approval gates at most. Approval is a budget; spend it where being wrong is expensive.@@ -103,7 +103,7 @@ draws itself declares `kind: "drawing"` and is judged on a finer floor; a freeze`engine/` is the portable art core plus the tooling. `engine/src/canvas-core` knows nothingabout the DOM or any backend. `W`, `H`, `fps` and `durationFrames` come from the film's `meta`.Camera moves (pans, zooms, parallax, shake): `engine/src/canvas-core/camera.ts`, `references/camera.md`.-Seams between scenes: `references/motion-grammar.md`. `render.mjs --blur auto` renders with motion blur (subframes per frame+Seams between scenes: `references/motion-grammar.md` (cuts that carry motion: `seams.ts`; `tools/deck.mjs deal` deals each film different moves). `render.mjs --blur auto` renders with motion blur (subframes per framefrom its measured on-screen speed, averaged in linear light, `--shutter 180`); the default path is untouched.```bash@@ -127,7 +127,7 @@ node <skill>/engine/tools/soundfetch.mjs get piano rooms # on their yes (piano| `verify-export.mjs` | QA on the rendered file: frames, duration, score, A/V sync, true peak after the encode; opt-in first frame, loop seam, `--delivery` || `launch.mjs` | a launch film: `new <name>` scaffolds the spec; `ship <name> --shapes 16x9,9x16` renders, posters, captions, verifies and framechecks each (`framecheck.mjs`: no text cut by the frame's edge) || `test.mjs` (`npm test`) | unit suites in `engine/test/`, no browser |-| `music.mjs` | `vocab` prints a style's vocabulary; `check` gates your composed score (key, master, guards, stems, novelty, and which parts played recordings); `render`, `meter` |+| `music.mjs` | `vocab` prints a style's vocabulary; `check` gates your composed score (key, master, guards, stems, novelty, which parts played recordings) and prints its shape (ARC); `render`, `meter` || `soundfetch.mjs` | the sound pack: `list`, `get <id...\|all>`, `where`, `verify`, `remove <id>` || `sfx.mjs` | the sound-effects kit: `list`, `one`, `kit <dir>`, `test` |diff --git a/plugins/anidoodle/skills/anidoodle/engine/package.json b/plugins/anidoodle/skills/anidoodle/engine/package.jsonindex 83bb2d9..c69800a 100644--- a/plugins/anidoodle/skills/anidoodle/engine/package.json+++ b/plugins/anidoodle/skills/anidoodle/engine/package.json@@ -1,6 +1,6 @@{"name": "anidoodle-engine",- "version": "0.6.1",+ "version": "0.6.2","private": true,"type": "module","description": "Portable art core + backend adapters for illustrations, animations and films drawn entirely in code.",diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahBody.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahBody.tsnew file mode 100644index 0000000..0db1098--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahBody.ts@@ -0,0 +1,177 @@+// THE CHEETAH, SIDE VIEW. One character module: a pose goes in, the animal is drawn. Shots pose it,+// they never redraw it. It is the same animal as the face in cheetahDusk and is made the same way:+// tapered tufts over a mass, solid spots, the tear line as the one big black shape.+// Reference opened (Wikimedia Commons), for structure only:+// - "Sarah Sprints" (CC BY 2.0): the build side-on, deep chest, tucked waist, spots following the form+// - "Acinonyxrunningrespiration.png" (CC BY-SA 3.0): the two flight phases, where the spine folds and opens+// - "Speed 2 - Running Cheetah" bronze (CC BY-SA 4.0): the extended phase, how the hind legs trail+// - de Blainville's skeleton plate (public domain): scapula, the long metatarsus, the hock high off the foot+// The anatomy it commits to: a small domed head held level; a long neck in line with the back; the+// scapula riding over the ribs; chest twice as deep as the waist; hind legs longer than fore, with a+// knee, a hock and a long metatarsus; a tail two thirds of the body, ringed at the end, white-tipped;+// claws that show; dark pads on a trailing hind foot.+// Everything is authored FACING RIGHT, y down, in the animal's own units (about 920 nose-paw to tail tip).+import { rng, type Ctx, type P } from "./core";+import { mix } from "./gallery";++const NIGHT = "#0d1a22", OCHRE = "#e3a23a", GOLD = "#efb84e", CREAM = "#f2e4c5", PALE = "#fff5de", DARK = "#0a1216";+const ROWS = ["#a9601f", "#cf8a2c", OCHRE, GOLD, "#f2c263", "#f4cd7e", CREAM]; // back to belly+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const lerp = (a: number, b: number, t: number) => a + (b - a) * t;++export type Pose = {+ spine: P[]; // 10 stations: rump, hip, loin, waist, rear ribs, chest, shoulder, neck base, neck, head join+ tail: P[]; // 6, from its root to its tip+ foreN: P[]; foreF: P[]; // scapula, shoulder, elbow, wrist, toes (near side, far side)+ hindN: P[]; hindF: P[]; // hip, knee, hock, ball, toes+ head: number; // the head's own angle, radians: 0 is level, positive is nose down+};++// the build: how thick the animal is at each station. A pose moves points; it never changes these.+const SPINE_UP = [14, 38, 40, 44, 54, 66, 66, 50, 38, 34], SPINE_DN = [22, 52, 44, 42, 68, 90, 76, 48, 36, 32];+const TAIL_W = [15, 13, 12, 12, 13, 11], FORE_W = [20, 30, 19, 12, 8], HIND_W = [44, 30, 13, 12, 8];+++// a tuft: a tapered leaf from radius r0 to r1 along angle a, darker at its root (the mark cheetahDusk is made of)+const tuft = (c: Ctx, o: P, a: number, r0: number, r1: number, w: number, col: string, vein = 0.22, root = 0.6) => {+ if (r1 - r0 < 1.5 || w < 0.6) return;+ const ca = Math.cos(a), sa = Math.sin(a), b: P = [o[0] + ca * r0, o[1] + sa * r0], t: P = [o[0] + ca * r1, o[1] + sa * r1], m = r0 + (r1 - r0) * 0.42, mx = o[0] + ca * m, my = o[1] + sa * m;+ const g = c.createLinearGradient(b[0], b[1], t[0], t[1]); g.addColorStop(0, mix(col, DARK, root)); g.addColorStop(0.45, col); g.addColorStop(1, mix(col, "#ffffff", 0.16));+ c.fillStyle = g; c.beginPath(); c.moveTo(b[0], b[1]); c.quadraticCurveTo(mx - sa * w, my + ca * w, t[0], t[1]); c.quadraticCurveTo(mx + sa * w, my - ca * w, b[0], b[1]); c.fill();+ if (vein > 0) { c.strokeStyle = mix(col, DARK, 0.7); c.globalAlpha = vein; c.lineWidth = 1; c.beginPath(); c.moveTo(b[0], b[1]); c.lineTo(o[0] + ca * (r1 - 3), o[1] + sa * (r1 - 3)); c.stroke(); c.globalAlpha = 1; }+};++// a ribbon: a smooth curve through the points with its own thickness on each side. Side a is on the+// left hand of travel (the top, for a chain running to the right); side b is the other.+type Rib = { c: P[]; a: P[]; b: P[]; ang: number[]; len: number };+const cr = (p0: number, p1: number, p2: number, p3: number, t: number) => 0.5 * (2 * p1 + (p2 - p0) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t * t + (3 * p1 - p0 - 3 * p2 + p3) * t * t * t);+const ribbon = (pts: P[], wa: number[], wb: number[] = wa, per = 12): Rib => {+ const g = (i: number) => pts[clamp(i, 0, pts.length - 1)], cs: P[] = [], ua: number[] = [], ub: number[] = [];+ for (let i = 0; i < pts.length - 1; i++) for (let k = 0; k < per + (i === pts.length - 2 ? 1 : 0); k++) {+ const t = k / per, e = t * t * (3 - 2 * t);+ cs.push([cr(g(i - 1)[0], g(i)[0], g(i + 1)[0], g(i + 2)[0], t), cr(g(i - 1)[1], g(i)[1], g(i + 1)[1], g(i + 2)[1], t)]); ua.push(lerp(wa[i], wa[i + 1], e)); ub.push(lerp(wb[i], wb[i + 1], e));+ }+ const a: P[] = [], b: P[] = [], ang: number[] = []; let len = 0;+ cs.forEach((p, i) => { const q0 = cs[Math.max(0, i - 1)], q1 = cs[Math.min(cs.length - 1, i + 1)], th = Math.atan2(q1[1] - q0[1], q1[0] - q0[0]), nx = Math.sin(th), ny = -Math.cos(th); ang.push(th); a.push([p[0] + nx * ua[i], p[1] + ny * ua[i]]); b.push([p[0] - nx * ub[i], p[1] - ny * ub[i]]); if (i) len += Math.hypot(p[0] - cs[i - 1][0], p[1] - cs[i - 1][1]); });+ return { c: cs, a, b, ang, len };+};+// a place on the ribbon: s along it (0-1), v across it (-1 is side a, +1 is side b)+const on = (r: Rib, s: number, v: number) => {+ const x = clamp(s) * (r.c.length - 1), i = Math.min(r.c.length - 2, Math.floor(x)), f = x - i, e = v < 0 ? r.a : r.b, k = Math.abs(v), L = (q: P[], d: 0 | 1) => lerp(q[i][d], q[i + 1][d], f);+ return { p: [lerp(L(r.c, 0), L(e, 0), k), lerp(L(r.c, 1), L(e, 1), k)] as P, ang: r.ang[i], w: Math.hypot(L(r.a, 0) - L(r.b, 0), L(r.a, 1) - L(r.b, 1)) };+};+const fillRib = (c: Ctx, r: Rib, col: string) => { c.fillStyle = col; c.beginPath(); r.a.forEach((p, i) => (i ? c.lineTo(p[0], p[1]) : c.moveTo(p[0], p[1]))); [...r.b].reverse().forEach((p) => c.lineTo(p[0], p[1])); c.closePath(); c.fill(); };+const blob = (c: Ctx, pts: P[], per = 8) => { const n = pts.length, g = (i: number) => pts[((i % n) + n) % n]; c.beginPath(); for (let i = 0; i < n; i++) for (let k = 0; k < per; k++) { const t = k / per, x = cr(g(i - 1)[0], g(i)[0], g(i + 1)[0], g(i + 2)[0], t), y = cr(g(i - 1)[1], g(i)[1], g(i + 1)[1], g(i + 2)[1], t); if (i + k) c.lineTo(x, y); else c.moveTo(x, y); } c.closePath(); };+const spot = (c: Ctx, p: P, rx: number, ry: number, a: number, col: string) => { c.fillStyle = col; c.beginPath(); c.ellipse(p[0], p[1], rx, ry, a, 0, Math.PI * 2); c.fill(); };++// a foot: four toes, each its own mark, each with its claw (a cheetah's never fully sheathe). A+// trailing hind foot shows its pads.+const paw = (c: Ctx, r: Rib, shade: number, hind: boolean) => {+ const sh = (col: string) => (shade ? mix(col, NIGHT, shade) : col), { p, ang } = on(r, 0.88, 0), pads = hind && Math.cos(ang) < -0.35; // a hind foot trailing behind shows its sole+ for (const k of [-1.5, 1.5, -0.5, 0.5]) {+ const a = ang + k * 0.15, L = 34 - Math.abs(k) * 3;+ tuft(c, p, a, 0, L, 6.6, sh(Math.abs(k) > 1 ? CREAM : PALE), 0.3, 0.35);+ tuft(c, [p[0] + Math.cos(a) * (L - 3), p[1] + Math.sin(a) * (L - 3)], a + 0.5, 0, 8, 1.9, sh("#2a1a12"), 0);+ }+ if (pads) { const q = on(r, 0.93, 0.8); spot(c, q.p, 5, 2.3, ang, sh("#3a2418")); const t = on(r, 1, 0.7); spot(c, [t.p[0] + Math.cos(ang) * 6, t.p[1] + Math.sin(ang) * 6], 2.4, 1.7, ang, sh("#3a2418")); }+};++// a leg: its mass, the fur lying toward the foot (laid from the foot upward, so each tuft overlaps+// the one below it), the spots thinning out toward the wrist, the fold where it meets the body.+const limb = (c: Ctx, joints: P[], widths: number[], seed: number, shade: number, hind: boolean) => {+ // the leg starts inside the body: the haunch and the point of the shoulder taper back into it, never a cut end+ const d = Math.hypot(joints[1][0] - joints[0][0], joints[1][1] - joints[0][1]) || 1, ext = widths[0] * 0.85, pts: P[] = [[joints[0][0] - ((joints[1][0] - joints[0][0]) / d) * ext, joints[0][1] - ((joints[1][1] - joints[0][1]) / d) * ext], ...joints], w = [widths[0] * 0.45, ...widths];+ const r = ribbon(pts, w, w, 10), L = Math.round(ext + (hind ? 320 : 315)), q = rng(seed), sh = (col: string) => (shade ? mix(col, NIGHT, shade) : col);+ fillRib(c, r, sh("#c2832a"));+ for (let i = Math.floor((L * 0.88) / 7); i >= 0; i--) {+ const s = (i * 7) / L, w0 = on(r, s, 0).w, rows = Math.max(2, Math.round(w0 / 11));+ for (let j = 0; j < rows; j++) {+ const v = lerp(-0.78, 0.78, rows === 1 ? 0.5 : j / (rows - 1)) + (q() - 0.5) * 0.3, at = on(r, s + (q() - 0.5) * (6 / L), v), under = hind ? v < -0.35 : v > 0.35, pale = clamp(s * 1.5 - 0.5) * 0.55;+ tuft(c, at.p, at.ang + (q() - 0.5) * 0.22, 0, clamp(w0 * 0.8, 16, 34) * (0.75 + q() * 0.5), clamp(w0 * 0.2, 2.6, 7), sh(mix(under ? "#f4cd7e" : q() < 0.5 ? GOLD : OCHRE, CREAM, pale)), 0.08, 0.26);+ }+ }+ for (let i = 1; i * 15 < L * 0.8; i++) {+ const s = (i * 15) / L, w0 = on(r, s, 0).w, n = Math.max(1, Math.round(w0 / 19));+ for (let j = 0; j < n; j++) { const v = (n === 1 ? 0 : lerp(-0.62, 0.62, j / (n - 1))) + (q() - 0.5) * 0.3, at = on(r, s + (q() - 0.5) * 0.02 + (j % 2) * (7 / L), v), z = clamp(w0 * 0.075, 1.7, 6.2) * (0.8 + q() * 0.4); spot(c, at.p, z * 1.15, z * 0.85 * Math.sqrt(1 - v * v * 0.6), at.ang, sh(DARK)); }+ }+ // the fold: the stifle under the thigh, the back of the shoulder. Thinner than an outline, and it fades.+ const e = hind ? r.a : r.b, m = Math.floor(e.length * 0.3); c.strokeStyle = sh(DARK); c.lineWidth = 2.2; c.lineCap = "round";+ for (let i = 1; i < m; i++) { c.globalAlpha = 0.34 * (1 - i / m); c.beginPath(); c.moveTo(e[i - 1][0], e[i - 1][1]); c.lineTo(e[i][0], e[i][1]); c.stroke(); }+ c.globalAlpha = 1;+ paw(c, r, shade, hind);+};++const tail = (c: Ctx, pts: P[]) => {+ const r = ribbon(pts, TAIL_W, TAIL_W, 10), L = 299, q = rng(23);+ fillRib(c, r, "#c2832a");+ for (let i = 0; i * 11 < L; i++) { const s = (i * 11) / L; for (const v of [0.6, -0.6, 0]) { const at = on(r, s, v); tuft(c, at.p, at.ang + (q() - 0.5) * 0.25 - v * 0.12, 0, 26 + q() * 8, 6.5, v > 0.3 ? "#f4cd7e" : v < -0.3 ? "#cf8a2c" : OCHRE, 0.18); } }+ // spots that close up into rings toward the end, then the white tip+ for (let i = 1; i * 17 < L * 0.62; i++) for (const v of [-0.5, 0.25]) { const at = on(r, (i * 17) / L + (v > 0 ? 8 / L : 0), v + (q() - 0.5) * 0.2); spot(c, at.p, 5, 3.8, at.ang, DARK); }+ for (const [s, wd] of [[0.68, 9], [0.78, 11], [0.88, 12]] as const) { const k = ribbon([on(r, s - 0.006, -1.05).p, on(r, s, 0).p, on(r, s + 0.006, 1.05).p], [wd / 2, wd / 2 + 1.5, wd / 2], undefined, 6); fillRib(c, k, DARK); }+ const end = on(r, 0.95, 0); for (let j = -3; j <= 3; j++) tuft(c, end.p, end.ang + j * 0.2, 0, 30 - Math.abs(j) * 3, 6.5, j % 2 ? PALE : CREAM, 0.15);+};++// the head in profile, authored point by point in its own frame (origin mid-skull, nose toward +x).+// The coat still opens in rings from the bridge of the nose, as it does on the face seen from the front.+const SKULL: P[] = [[-37, 2], [-33, -16], [-19, -30], [2, -33], [20, -27], [33, -17], [45, -9], [57, -5], [61, 3], [57, 11], [50, 22], [34, 28], [10, 31], [-16, 28], [-33, 17]];+const head = (c: Ctx, at: P, ang: number) => {+ c.save(); c.translate(at[0], at[1]); c.rotate(ang); c.scale(1.18, 1.18);+ // the far ear's tip, then the skull+ blob(c, [[-12, -28], [-17, -43], [-27, -45], [-30, -30]]); c.fillStyle = mix("#a9601f", NIGHT, 0.45); c.fill();+ blob(c, SKULL); c.fillStyle = "#c98a2e"; c.fill();+ c.save(); blob(c, SKULL); c.clip();+ const q = rng(61), N: P = [44, -8];+ for (let ring = 6; ring >= 0; ring--) { const rad = 6 + ring * 14, n = 9 + ring * 3; for (let j = 0; j < n; j++) { const a = Math.PI + lerp(-1.25, 1.35, (j + (ring % 2) * 0.5) / n), low = clamp((Math.sin(a) * -1 - 0.2) * 2.2); tuft(c, N, a + (q() - 0.5) * 0.06, rad, rad + 21, 5.2, mix(ROWS[Math.min(5, 5 - Math.min(5, ring)) ] , CREAM, low * 0.85), 0.18); } }+ // muzzle, chin and throat: pale+ blob(c, [[58, 5], [47, 1], [35, 6], [26, 16], [24, 30], [44, 32], [54, 20]]); c.fillStyle = PALE; c.fill();+ for (let j = 0; j < 9; j++) tuft(c, [50, 6], Math.PI * 0.5 + 0.25 + j * 0.16, 2, 24, 4.4, j % 2 ? CREAM : PALE, 0.14);+ c.restore();+ // crown and cheek spots, small, none on the muzzle+ for (let i = 0; i < 46; i++) { const x = -32 + q() * 56, y = -30 + q() * 54; if (Math.hypot(x - 22, y + 11) < 12 || (x > 12 && y > -4) || y > 20 - (x + 32) * 0.1) continue; spot(c, [x, y], 1.7 + q() * 1.1, 1.4 + q() * 0.8, q() * 3, DARK); }+ // the near ear, laid back by the wind: dark behind, pale inside, a fur rim+ blob(c, [[-5, -27], [-12, -44], [-27, -49], [-35, -37], [-29, -22]]); c.fillStyle = DARK; c.fill();+ for (let j = 0; j < 7; j++) tuft(c, [-14, -25], -Math.PI / 2 - 0.25 - j * 0.13, 3, 17 - Math.abs(j - 3) * 1.6, 3.2, j % 2 ? CREAM : "#e9c98a", 0.12);+ for (let j = 0; j < 9; j++) tuft(c, [-18, -31], -0.5 - j * 0.3, 13, 20, 3, j % 3 ? "#a9601f" : OCHRE, 0);+ // the tear line: from the inner corner of the eye, round the muzzle, to the corner of the mouth+ fillRib(c, ribbon([[27, -7], [30, 2], [36, 10], [37, 16]], [1.6, 3.6, 3.8, 1.4], undefined, 8), DARK);+ // the eye under its brow: lids, amber iris, pupil, the light in it+ blob(c, [[11, -10], [18, -17], [28, -15], [31, -8], [23, -5], [15, -6]]); c.fillStyle = DARK; c.fill();+ blob(c, [[14, -10], [19, -14.5], [26, -13], [28, -8.5], [22, -7], [16, -7.5]]); c.fillStyle = "#f39a1e"; c.fill();+ spot(c, [21.5, -10.5], 2.9, 3.1, 0, "#070b0e"); spot(c, [22.8, -11.8], 1, 1, 0, PALE);+ c.strokeStyle = DARK; c.lineCap = "round"; c.lineWidth = 2.4; c.beginPath(); c.moveTo(9, -15); c.quadraticCurveTo(20, -22, 31, -17); c.stroke();+ // nose pad, nostril, the mouth and the split of the lip, the chin's edge+ blob(c, [[52, -6], [58, -6], [62, 1], [60, 7], [54, 5]]); c.fillStyle = "#1a0f0c"; c.fill();+ c.strokeStyle = "rgba(255,245,222,0.4)"; c.lineWidth = 1.2; c.beginPath(); c.moveTo(54, -3); c.lineTo(59, -2); c.stroke();+ c.strokeStyle = "#1a0f0c"; c.lineWidth = 2; c.beginPath(); c.moveTo(57, 7); c.quadraticCurveTo(55, 13, 48, 14); c.quadraticCurveTo(42, 16, 36, 15); c.stroke();+ c.lineWidth = 1.2; c.globalAlpha = 0.5; c.beginPath(); c.moveTo(50, 22); c.quadraticCurveTo(40, 30, 24, 30); c.stroke(); c.globalAlpha = 1;+ for (let row = 0; row < 3; row++) for (let k = 0; k < 3; k++) spot(c, [50 - k * 5 - row, 6.5 + row * 2.6 - k * 0.6], 0.8, 0.8, 0, "#2a1a12");+ // whiskers, swept back+ c.strokeStyle = PALE; c.lineWidth = 1.1; c.globalAlpha = 0.85;+ for (let k = 0; k < 5; k++) { c.beginPath(); c.moveTo(47 - k * 2, 8 + k * 1.6); c.quadraticCurveTo(26, 14 + k * 5, -2 + k * 3, 24 + k * 7); c.stroke(); }+ c.globalAlpha = 1; c.restore();+};++/** Where her head sits on this pose: the middle of the skull. A head drawn another way (cheetahTurn's) goes here. */+export const headAnchor = (pose: Pose): P => { const end = on(ribbon(pose.spine, SPINE_UP, SPINE_DN, 14), 1, 0); return [end.p[0] + Math.cos(end.ang) * 14, end.p[1] + Math.sin(end.ang) * 14]; };+export const drawCheetah = (c: Ctx, pose: Pose, o: { head?: false } = {}) => {+ tail(c, pose.tail);+ limb(c, pose.hindF, HIND_W, 31, 0.36, true); limb(c, pose.foreF, FORE_W, 32, 0.36, false);+ // the body: its mass, then the coat in seven rows from the belly up, each row laid from the tail forward+ const r = ribbon(pose.spine, SPINE_UP, SPINE_DN, 14), L = 517, q = rng(7);+ fillRib(c, r, "#b9731f");+ c.fillStyle = "#e9d6ad"; c.beginPath(); for (let i = 0; i <= 60; i++) { const at = on(r, 0.14 + (i / 60) * 0.86, 0.98).p; if (i) c.lineTo(at[0], at[1]); else c.moveTo(at[0], at[1]); } for (let i = 60; i >= 0; i--) { const e = i / 60, at = on(r, 0.14 + e * 0.86, lerp(0.62, 0.42, e)).p; c.lineTo(at[0], at[1]); } c.closePath(); c.fill();+ const VS = [-0.84, -0.58, -0.3, 0, 0.28, 0.52, 0.74, 0.93], RC = [...ROWS, CREAM];+ for (let j = VS.length - 1; j >= 0; j--) for (let i = 0; i * 19 < L; i++) {+ const s = (i * 19 + (j % 2) * 9 + (q() - 0.5) * 7) / L; if (s > 1 || s < 0.05) continue;+ const at = on(r, s, VS[j]), k = clamp(at.w / 120, 0.55, 1), neck = clamp((s - 0.72) * 5), rump = 1 - clamp((s - 0.04) * 9), col = mix(mix(RC[j], CREAM, j >= 4 ? neck * 0.5 : 0), ROWS[2], j >= 4 ? rump : 0);+ tuft(c, at.p, at.ang + Math.PI - Math.max(0, VS[j]) * 0.22 + (q() - 0.5) * 0.1, 0, (40 + q() * 12) * k * (j >= 6 ? 0.62 : 1), 12 * k * (j >= 6 ? 0.8 : 1), j >= 6 ? mix(col, OCHRE, 0.1 + q() * 0.12) : mix(col, DARK, q() * 0.08), 0.22, j >= 5 ? 0.3 : 0.6);+ }+ // spots: solid, round, following the surface (they narrow toward the top and the belly line), none on the belly+ const sr = rng(5);+ for (let i = 0; i * 21 < L - 8; i++) for (let j = 0; j < 8; j++) {+ const v = -0.93 + j * 0.2 + (sr() - 0.5) * 0.09, s = (i * 21 + (j % 2) * 10.5 + (sr() - 0.5) * 6 + 8) / L, at = on(r, s, v), k = clamp(at.w / 130, 0.5, 1), z = (5.4 + sr() * 2.4) * k * (1 - clamp(v) * 0.25);+ spot(c, at.p, z * 1.12, z * 0.92 * Math.sqrt(1 - v * v * 0.72), at.ang, DARK);+ }+ limb(c, pose.hindN, HIND_W, 33, 0, true); limb(c, pose.foreN, FORE_W, 34, 0, false);+ if (o.head !== false) head(c, headAnchor(pose), pose.head);+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahDusk.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahDusk.tsindex d3693ae..280e506 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahDusk.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahDusk.ts@@ -101,6 +101,7 @@ const tear = (c: Ctx, side: number, prog: number) => {for (let i = 0; i <= m; i++) { const t = i / n, a = bz(t), b = bz(Math.min(1, t + 0.01)), d = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1, nx = -(b[1] - a[1]) / d, ny = (b[0] - a[0]) / d, w = (7 + 15 * Math.sin(Math.PI * Math.pow(t, 0.6)) * (1 - t * 0.35)) * (i === m && prog < 1 ? 0.3 : 1); L.push([a[0] + nx * w, a[1] + ny * w]); R.push([a[0] - nx * w, a[1] - ny * w]); }c.fillStyle = DARK; c.beginPath(); [...L, ...R.reverse()].forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y))); c.closePath(); c.fill();};+export const duskGrass = PARTS.grass, FACE: P = F;const grass = (c: Ctx, f: number, grow: number) => { for (const g of PARTS.grass) tuft(c, [g.x, H + 20], -Math.PI / 2 + g.a + Math.sin(f * (Math.PI / 45) + g.ph) * 0.07, 0, g.h * grow, g.w, g.col, 0); };// the night's stars: they are out while it is night, at the start and again at the end, never still@@ -108,7 +109,7 @@ const STARS = (() => { const r = rng(19); return Array.from({ length: 46 }, () =const stars = (c: Ctx, f: number, k: number) => { if (k <= 0) return; for (const st of STARS) { c.globalAlpha = k * (0.35 + 0.65 * (0.5 + 0.5 * Math.sin((f / N) * Math.PI * 2 * st.cyc + st.ph))); c.fillStyle = PALE; c.beginPath(); c.arc(st.x, st.y, st.s, 0, Math.PI * 2); c.fill(); } c.globalAlpha = 1; };// ---------------------------------------------------------------- the camera-const camAt = (f: number) => {+export const camAt = (f: number) => {const a = inOut(ramp(f, 180, 290)), b = ramp(f, 290, 338), z = Math.pow(2, lerp(0, Math.log2(1.14), a) + inOut(b) * (Math.log2(52) - Math.log2(1.14))), lk = out3(b * 1.5);return { z, look: [lerp(lerp(540, 506, a), EYE_L[0], lk), lerp(lerp(540, 532, a), EYE_L[1] - 2, lk)] as P };};@@ -122,18 +123,13 @@ const grainLayer = (env: Env): Layer => { // the paper's tooth and the dusk settreturn L;};-const draw = (ctx: Ctx, f: number, env: Env) => {- const c = ctx, s = env.scale, cam = camAt(f), pupilCol = mix(PUPIL, NIGHT, ramp(f, 312, 336));- c.setTransform(s, 0, 0, s, 0, 0); c.fillStyle = NIGHT; c.fillRect(0, 0, W, H);- if (f < 60) stars(c, f, 1 - ramp(f, 14, 52));- c.setTransform(s * cam.z, 0, 0, s * cam.z, s * (540 - cam.look[0] * cam.z), s * (540 - cam.look[1] * cam.z));- // the moon, setting; the sun, rising behind the grass with its rays opening- const set = ramp(f, 4, 52); if (set < 1) crescent(c, MOON[0] - set * set * 160, MOON[1] + set * set * 1000, MOON_R, PALE);- const rise = out3(ramp(f, 8, 74)), sy = lerp(1700, 430, rise), rays = back(ramp(f, 40, 86));- for (let j = 0; j < 96; j++) tuft(c, [540, sy], (j / 96) * Math.PI * 2 + f * 0.0016, 440, 440 + (80 + (j % 2) * 26) * rays, 12, j % 2 ? RUST : "#8f3a26", 0);- const sg = c.createRadialGradient(540, sy, 80, 540, sy, 470); sg.addColorStop(0, "#ff8a4a"); sg.addColorStop(1, CORAL); c.fillStyle = sg; c.beginPath(); c.arc(540, sy, 470, 0, Math.PI * 2); c.fill();+// The face on its own, for a caller that has set the transform: all of it, or one part. cheetahRun+// turns this head in space, so it takes the parts as layers: the neck, the head with no features (its back), the whole head.+export const duskFace = (c: Ctx, f: number, part: "all" | "neck" | "coat" | "head" = "all") => {+ const pupilCol = mix(PUPIL, NIGHT, ramp(f, 312, 336));// neck and shoulders rise- for (const n of PARTS.neck) { const g = back(ramp(f, n.t0, n.t0 + 16)); tuft(c, [n.x, n.y - 70 + (1 - g) * 60], Math.PI / 2, 0, 150 * g, 52 * g, n.col, 0.3); }+ if (part === "all" || part === "neck") for (const n of PARTS.neck) { const g = back(ramp(f, n.t0, n.t0 + 16)); tuft(c, [n.x, n.y - 70 + (1 - g) * 60], Math.PI / 2, 0, 150 * g, 52 * g, n.col, 0.3); }+ if (part === "neck") return;ear(c, [262, 300], -1, f); ear(c, [818, 300], 1, f);// the head's own mass, then the coat over it: rings of tufts from the nose outward, breathing once it is wholeconst mass = ramp(f, 70, 132); // it spreads just under the coat as the rings open, never a bare disc@@ -143,6 +139,7 @@ const draw = (ctx: Ctx, f: number, env: Env) => {for (const t of PARTS.coat) { const g = back(ramp(f, t.t0, t.t0 + 15)); if (g <= 0) continue; const br = 1 + 0.045 * alive * Math.sin(f * (Math.PI / 45) + t.ring * 0.9); tuft(c, F, t.a, t.r0, t.r0 + (t.r1 - t.r0) * g * br, t.w * Math.min(1, g), t.col); }c.restore();for (const p of PARTS.spots) { const g = back(ramp(f, p.t0, p.t0 + 9)); if (g <= 0) continue; c.fillStyle = DARK; c.beginPath(); c.ellipse(p.x, p.y, p.s * 1.12 * g, p.s * 0.94 * g, p.a, 0, Math.PI * 2); c.fill(); }+ if (part === "coat") return;// the bridge of the nose: a pale fan falling from between the eyesfor (let i = -4; i <= 4; i++) { const g = back(ramp(f, 108 + Math.abs(i) * 2, 126 + Math.abs(i) * 2)); tuft(c, [540, 452], Math.PI / 2 + i * 0.075, 20, 20 + (194 - Math.abs(i) * 12) * g, 13 * g, i % 2 ? "#f4cd7e" : "#f8dca0", 0.18); }tear(c, 1, inOut(ramp(f, 134, 162))); tear(c, -1, inOut(ramp(f, 134, 162)));@@ -160,15 +157,41 @@ const draw = (ctx: Ctx, f: number, env: Env) => {const mo = ramp(f, 152, 166); if (mo > 0) { c.strokeStyle = "#1a0f0c"; c.lineWidth = 5; c.lineCap = "round"; c.beginPath(); c.moveTo(540, 732); c.lineTo(540, 732 + 36 * mo); if (mo >= 1) { const q = ramp(f, 166, 176); c.moveTo(540, 768); c.quadraticCurveTo(540 - 28 * q, 768 + 32 * q, 540 - 70 * q, 768 + 18 * q); c.moveTo(540, 768); c.quadraticCurveTo(540 + 28 * q, 768 + 32 * q, 540 + 70 * q, 768 + 18 * q); } c.stroke(); }const wh = out3(ramp(f, 160, 184)); if (wh > 0) for (const sd of [-1, 1]) for (let k = 0; k < 5; k++) { const sway = Math.sin(f * (Math.PI / 60) + k) * 6 * alive, a: P = [540 + sd * 96, 742 + k * 9], m: P = [540 + sd * 250, 720 + k * 22 + sway * 0.5], e: P = [540 + sd * (400 + k * 14), 690 + k * 46 + sway]; c.strokeStyle = PALE; c.globalAlpha = 0.85; c.lineWidth = 2; c.beginPath(); c.moveTo(a[0], a[1]); for (let i = 1; i <= 16; i++) { const t = (i / 16) * wh, u = 1 - t; c.lineTo(u * u * a[0] + 2 * u * t * m[0] + t * t * e[0], u * u * a[1] + 2 * u * t * m[1] + t * t * e[1]); } c.stroke(); }c.globalAlpha = 1;- grass(c, f, 1);+};+// Another film may borrow this one's world (cheetahRun does): its own camera, a clock for the sun's+// rays and the grass that runs on while the face's own time is held, the face moved aside or left+// out, the grass and the grain left for the borrower to lay. With no options it is this film, exactly.+export type DuskOpts = { cam?: { z: number; look: P }; world?: number; face?: false; grass?: false; grain?: false };+export const drawDusk = (ctx: Ctx, f: number, env: Env, o: DuskOpts = {}) => {+ const c = ctx, s = env.scale, cam = o.cam ?? camAt(f), wf = o.world ?? f;+ c.setTransform(s, 0, 0, s, 0, 0); c.fillStyle = NIGHT; c.fillRect(0, 0, W, H);+ if (f < 60) stars(c, f, 1 - ramp(f, 14, 52));+ c.setTransform(s * cam.z, 0, 0, s * cam.z, s * (540 - cam.look[0] * cam.z), s * (540 - cam.look[1] * cam.z));+ // the moon, setting; the sun, rising behind the grass with its rays opening+ const set = ramp(f, 4, 52); if (set < 1) crescent(c, MOON[0] - set * set * 160, MOON[1] + set * set * 1000, MOON_R, PALE);+ const rise = out3(ramp(f, 8, 74)), sy = lerp(1700, 430, rise), rays = back(ramp(f, 40, 86));+ for (let j = 0; j < 96; j++) tuft(c, [540, sy], (j / 96) * Math.PI * 2 + wf * 0.0016, 440, 440 + (80 + (j % 2) * 26) * rays, 12, j % 2 ? RUST : "#8f3a26", 0);+ const sg = c.createRadialGradient(540, sy, 80, 540, sy, 470); sg.addColorStop(0, "#ff8a4a"); sg.addColorStop(1, CORAL); c.fillStyle = sg; c.beginPath(); c.arc(540, sy, 470, 0, Math.PI * 2); c.fill();+ if (o.face !== false) duskFace(c, f);+ if (o.grass !== false) grass(c, wf, 1);// screen space: the crescent carried out of the pupil to its place in the sky, and the grass coming backc.setTransform(s, 0, 0, s, 0, 0);if (f >= 290) { const u = ramp(f, 290, 338), e = inOut(u), from: P = [540 + (EYE_L[0] - 10 - cam.look[0]) * Math.min(cam.z, 1.6), 540 + (EYE_L[1] - 12 - cam.look[1]) * Math.min(cam.z, 1.6)]; crescent(c, lerp(from[0], MOON[0], e), lerp(from[1], MOON[1], e) - Math.sin(Math.PI * u) * 40, 9.5 * Math.pow(MOON_R / 9.5, e), PALE); }if (f >= 322) { stars(c, f, ramp(f, 326, 352)); grass(c, f, inOut(ramp(f, 322, 359))); }- c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; c.drawImage(grainLayer(env).canvas, 0, 0);+ c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; if (o.grain !== false) c.drawImage(grainLayer(env).canvas, 0, 0);};+const draw = (ctx: Ctx, f: number, env: Env) => drawDusk(ctx, f, env);// the score: four bars at 80 bpm are the film's 12 s exactly, so the loop is the music's own+/** The night the film ends on, held: the stars, the crescent in its place, the grass. At t = 359 it is the film's last frame, and it runs on from there. */+export const duskNight = (ctx: Ctx, t: number, env: Env) => {+ const c = ctx, s = env.scale;+ c.setTransform(s, 0, 0, s, 0, 0); c.fillStyle = NIGHT; c.fillRect(0, 0, W, H);+ crescent(c, MOON[0], MOON[1], MOON_R, PALE); stars(c, t, 1); grass(c, t, 1);+ c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; c.drawImage(grainLayer(env).canvas, 0, 0);+};+export const DUSK_PALE = PALE;+const audio = (sr: number): [Float32Array, Float32Array] => {const n = Math.round((N / 30) * sr), L = new Float32Array(n), R = new Float32Array(n), m = renderLoop(cheetahDuskScore(), sr); // its tail folded back onto its start: no cut at the seamfor (let i = 0; i < n && i < m.L.length; i++) { L[i] = m.L[i]; R[i] = m.R[i]; }diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRig.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRig.tsnew file mode 100644index 0000000..21a61c4--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRig.ts@@ -0,0 +1,91 @@+// THE CHEETAH'S SKELETON. A rig is a set of angles; fk() turns it into the points cheetahBody draws.+// Bones never change length, so a leg swings in arcs and folds at its joints, it never stretches.+// Angles are in degrees, absolute, y down: 0 points forward (the animal faces right), 90 down, 180 back.+// The gallop is the rotary gallop of the reference: two flight phases a stride, the spine folding+// (gathered, hind feet reaching past the fore) and opening (extended), the forelegs landing one+// after the other, then the hind legs. The head is held level at its own height whatever the body does.+import type { P } from "./core";+import type { Pose } from "./cheetahBody";++type Leg = [number, number, number, number];+export type Rig = {+ pitch: number; lumb: number; thor: number; // the body's tilt (nose down is positive); how far the loin and the chest fold+ headH: number; head: number; // the head's height above the ground; its own angle (nose down is positive)+ fore: Leg; foreF: Leg; // scapula, upper arm, forearm, hand+ hind: Leg; hindF: Leg; // thigh, shank, metatarsus, toes+ tail: number[]; // its five segments+};++const D = Math.PI / 180, clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v)), lerp = (a: number, b: number, t: number) => a + (b - a) * t;+const step = (p: P, deg: number, len: number): P => [p[0] + Math.cos(deg * D) * len, p[1] + Math.sin(deg * D) * len];+const off = (p: P, deg: number, x: number, y: number): P => { const c = Math.cos(deg * D), s = Math.sin(deg * D); return [p[0] + x * c - y * s, p[1] + x * s + y * c]; };+export const FORE_BONES = [54, 98, 103, 60], HIND_BONES = [102, 105, 79, 34], TAIL_BONES = [65, 66, 66, 59, 43];+const REAR = [65.1, 75.3, 43.3], FRONT = [65.3, 70, 60.3], NECK = 138; // spine segments out from the waist; the neck's chord+const chain = (p: P, dirs: number[], bones: number[]): P[] => { const out: P[] = [p]; dirs.forEach((d, i) => out.push(step(out[i], d, bones[i]))); return out; };++/** The points, with the waist at (x, y) and the ground at `ground`. */+export const fk = (r: Rig, x: number, y: number, ground: number): Pose => {+ const waist: P = [x, y], p = r.pitch;+ const fwd = [p + 5 + r.thor * 0.3, p + 2 + r.thor * 0.7, p - 5 + r.thor], back = [p + 3.5 - r.lumb * 0.3, p + 5 - r.lumb * 0.75, p + 7 - r.lumb * 1.1];+ const ribs = step(waist, fwd[0], FRONT[0]), chest = step(ribs, fwd[1], FRONT[1]), shoulder = step(chest, fwd[2], FRONT[2]);+ const loin = step(waist, back[0] + 180, REAR[0]), hip = step(loin, back[1] + 180, REAR[1]), rump = step(hip, back[2] + 180, REAR[2]);+ // the neck reaches whatever is left between the shoulders and a head that keeps its own height+ const dy = clamp(ground - r.headH - shoulder[1], -NECK * 0.82, NECK * 0.82), dx = Math.sqrt(NECK * NECK - dy * dy), join: P = [shoulder[0] + dx, shoulder[1] + dy];+ const nx = dy / NECK, ny = -dx / NECK, bow = (t: number, b: number): P => [lerp(shoulder[0], join[0], t) + nx * b, lerp(shoulder[1], join[1], t) + ny * b];+ return {+ spine: [rump, hip, loin, waist, ribs, chest, shoulder, bow(0.38, 7), bow(0.73, 5), join],+ tail: chain(off(rump, back[2], 4, -14), r.tail, TAIL_BONES),+ foreN: chain(off(shoulder, fwd[2], -10, -24), r.fore, FORE_BONES), foreF: chain(off(shoulder, fwd[2], -2, -20), r.foreF, FORE_BONES),+ hindN: chain(off(hip, back[1], 7, 15), r.hind, HIND_BONES), hindF: chain(off(hip, back[1], 15, 17), r.hindF, HIND_BONES),+ head: r.head * D,+ };+};++const low = (leg: P[]) => Math.max(leg[3][1], leg[4][1]) + 5; // a foot's sole: the lower of its ball and its toes, plus the pad+export const lowest = (q: Pose) => ({ fore: Math.max(low(q.foreN), low(q.foreF)), hind: Math.max(low(q.hindN), low(q.hindF)) });+const blend = (a: number[], b: number[], t: number) => a.map((v, i) => lerp(v, b[i], t));+export const mixRig = (a: Rig, b: Rig, t: number): Rig => ({+ pitch: lerp(a.pitch, b.pitch, t), lumb: lerp(a.lumb, b.lumb, t), thor: lerp(a.thor, b.thor, t), headH: lerp(a.headH, b.headH, t), head: lerp(a.head, b.head, t),+ fore: blend(a.fore, b.fore, t) as Leg, foreF: blend(a.foreF, b.foreF, t) as Leg, hind: blend(a.hind, b.hind, t) as Leg, hindF: blend(a.hindF, b.hindF, t) as Leg, tail: blend(a.tail, b.tail, t),+});++/** A standing pose settles onto the ground: the body tilts until fore and hind feet both bear, and its height follows. */+export const settle = (r: Rig): { rig: Rig; y: number } => {+ let rig = r;+ for (let k = 0; k < 8; k++) { const q = fk(rig, 0, 0, 0), l = lowest(q); rig = { ...rig, pitch: rig.pitch + (Math.atan2(l.hind - l.fore, q.foreN[4][0] - q.hindN[4][0]) / D) * 0.9 }; }+ const l = lowest(fk(rig, 0, 0, 0)); return { rig, y: -Math.max(l.fore, l.hind) };+};++// ---------------------------------------------------------------- the held poses+export const STAND: Rig = { pitch: 0, lumb: 0, thor: 0, headH: 356, head: 6, fore: [80, 118, 88, 68], foreF: [76, 108, 92, 72], hind: [58, 128, 86, 18], hindF: [66, 134, 90, 20], tail: [118, 100, 98, 122, 160] }; // the tail at rest: down behind the hocks, its tip turned up+// the bow: forelegs walked out flat along the ground, chest down between them, the rump left high, the back hollow+export const BOW: Rig = { pitch: 0, lumb: -22, thor: -12, headH: 150, head: -14, fore: [52, 38, 8, 2], foreF: [50, 44, 12, 4], hind: [78, 112, 88, 14], hindF: [84, 118, 92, 16], tail: [250, 262, 285, 318, 350] };+// the crouch before the start: weight back over folded hind legs, the chest low, the head stretched forward+export const CROUCH: Rig = { pitch: 0, lumb: 16, thor: 6, headH: 196, head: 10, fore: [88, 150, 62, 50], foreF: [84, 142, 68, 54], hind: [36, 142, 72, 12], hindF: [44, 148, 78, 14], tail: [176, 170, 176, 190, 204] };+// the stop: forelegs braced out ahead, the rump dropped under, the tail thrown up for balance+export const SKID: Rig = { pitch: 0, lumb: 20, thor: 2, headH: 262, head: -4, fore: [62, 62, 56, 30], foreF: [60, 70, 62, 34], hind: [30, 138, 66, 10], hindF: [40, 146, 74, 12], tail: [228, 246, 262, 280, 300] };++// ---------------------------------------------------------------- the gallop+// One stride. Keys: 0 extended flight · .14 the forefeet reach the ground · .27 over the forelegs ·+// .40 they push off · .52 gathered flight · .66 the hind feet land ahead · .80 over the hind legs · .92 they drive off.+const T = [0, 0.14, 0.27, 0.4, 0.52, 0.66, 0.8, 0.92];+const FORE = [[70, 23, 15, 15], [78, 55, 50, 35], [92, 118, 78, 45], [105, 140, 125, 140], [105, 135, 172, 225], [95, 110, 150, 215], [82, 60, 95, 150], [72, 28, 30, 50]];+const HIND = [[141, 187, 164, 159], [128, 185, 150, 150], [100, 170, 125, 135], [60, 176, 122, 122], [22, 146, 56, 30], [40, 128, 58, 8], [88, 140, 85, 10], [122, 168, 135, 100]];+// lumb thor pitch tail height of the waist in flight+const BODY = [[-12, -4, 0, 188, 262], [-8, -1, 3, 180, 266], [6, 5, 4, 176, 286], [36, 13, 2, 190, 292], [64, 22, 0, 212, 300], [54, 17, -3, 218, 296], [20, 5, -4, 204, 288], [-6, -3, -2, 194, 272]];+const TAIL_CURL = [0, -10, 4, 20, 34];+const cyc = (V: number[][], ph: number): number[] => {+ const n = T.length, f = ((ph % 1) + 1) % 1; let i = n - 1; for (let k = 0; k < n; k++) if (f >= T[k]) i = k;+ const tt = (k: number) => T[((k % n) + n) % n] + Math.floor(k / n), vv = (k: number) => V[((k % n) + n) % n], t1 = tt(i), t2 = tt(i + 1), h = t2 - t1, u = (f - t1) / h, u2 = u * u, u3 = u2 * u;+ return vv(i).map((v1, c) => { const v2 = vv(i + 1)[c], m1 = ((v2 - vv(i - 1)[c]) / (t2 - tt(i - 1))) * h, m2 = ((vv(i + 2)[c] - v1) / (tt(i + 2) - t1)) * h; return (2 * u3 - 3 * u2 + 1) * v1 + (u3 - 2 * u2 + u) * m1 + (-2 * u3 + 3 * u2) * v2 + (u3 - u2) * m2; });+};+// the far legs run the same stride a little later: one forefoot lands, then the other+const FAR_FORE = 0.085, FAR_HIND = 0.07;+export const gallopRig = (ph: number): Rig => {+ const b = cyc(BODY, ph);+ return { pitch: b[2], lumb: b[0], thor: b[1], headH: 300, head: 5 + b[2] * 0.3, fore: cyc(FORE, ph) as Leg, foreF: cyc(FORE, ph - FAR_FORE) as Leg, hind: cyc(HIND, ph) as Leg, hindF: cyc(HIND, ph - FAR_HIND) as Leg, tail: TAIL_CURL.map((k, i) => { const a = cyc(BODY, ph - 0.09 * i)[3]; return 196 + (a - 196) * (1 + i * 0.18) + k; }) }; // each segment follows the one before it, later and wider: the whip of the tail+};+// how firmly the feet are on the ground through the stride: two stances, two flights+const stance = (ph: number) => { const f = ((ph % 1) + 1) % 1, bump = (c: number, w: number) => { const d = Math.min(Math.abs(f - c), 1 - Math.abs(f - c)); return clamp(1 - d / w); }; const s = Math.max(bump(0.27, 0.15), bump(0.8, 0.15)); return s * s * (3 - 2 * s); };+/** The waist's height (negative, above the ground at 0) at this point of the stride: on its feet in the stances, carried through the air between. */+export const gallopY = (ph: number, rig = gallopRig(ph)): number => { const l = lowest(fk(rig, 0, 0, 0)), contact = -Math.max(l.fore, l.hind), air = Math.min(contact, -cyc(BODY, ph)[4]); return lerp(air, contact, stance(ph)); };diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRun.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRun.tsnew file mode 100644index 0000000..441971c--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRun.ts@@ -0,0 +1,210 @@+// CHEETAH, RUN. 27 s, looping. It is cheetahDusk with a run opened up in the middle of it, in one+// continuous shot with no cut and no wipe.+// The story in three sentences: She wakes at dusk. She stretches and runs across the whole country+// for the joy of it. She stops, turns back to us, and the night closes over, ready to begin again.+// The token: the low sun, which stays put through every move while everything nearer goes by.+// The two moves the film is for:+// THE TURN. The camera pulls back from the face and comes round to her side in one move. The face+// is the same drawing, wrapped on a head and turned in space (cheetahTurn); her body swings out+// from behind it, edge-on at first, as the ground comes up under her feet. Back the same way.+// THE RUN. She is held in frame and the country goes by in layers at their own speeds, and it+// changes as she covers ground: thorn savanna, a kopje where the birds go up, a shallow pan she+// goes through in spray, grass again (cheetahScenery).+// The picture is timed in frames on a 120 bpm grid (a beat is 15 frames, and so is a stride); the+// score is nine bars at 80 bpm, the same 27 s.+// 0-255 cheetahDusk 0-255: night, the sun, the face making itself, the eyes, alive, a blink+// 255-300 the turn: front to side, pulling back+// 300-390 the stretch: down into the bow (338), held and deepened, up again (390)+// 390-405 she gathers+// 405-575 the run: off the hind legs at 405, at speed by 450, a stride every 15 frames+// 575-630 forefeet braced, the slide, the dust goes past her, she stands+// 648-690 the turn back+// 690-810 cheetahDusk 262-360: the face, the camera into the eye, the night. 809 hands over to 0.+import { rng, type Ctx, type Env, type Layer, type P } from "./core";+import type { Film } from "./film";+import { mix } from "./gallery";+import { drawCheetah, headAnchor, type Pose } from "./cheetahBody";+import { camAt, drawDusk, DUSK_PALE, duskGrass, duskNight, FACE } from "./cheetahDusk";+import { logoCentred, setType } from "./kinetic";+import { cheetahRunScore, cheetahRunSignedScore } from "./music/pieces/cheetahRun";+import { renderLoop, renderPiece } from "./music/render";+import { BOW, CROUCH, fk, gallopRig, gallopY, lowest, mixRig, settle, SKID, STAND, type Rig } from "./cheetahRig";+import { country, drawBurst, drawFar, drawFlock, drawLens, drawPan, inPan, leaf, type Burst } from "./cheetahScenery";+import { HEAD_K, turnedHead, turnedNeck } from "./cheetahTurn";++const W = 1080, H = 1080, N = 810, GROUND = 852, FLOOR = GROUND + 24;+const NIGHT = "#0d1a22", TEAL = "#2a6a70", RUST = "#b8452a", PALE = "#fff5de", DARK = "#0a1216";+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const ramp = (f: number, a: number, b: number) => clamp((f - a) / (b - a));+const lerp = (a: number, b: number, t: number) => a + (b - a) * t;+const inOut = (t: number) => { const c = clamp(t); return c < 0.5 ? 4 * c * c * c : 1 - Math.pow(-2 * c + 2, 3) / 2; };+const out3 = (t: number) => 1 - Math.pow(1 - clamp(t), 3);+const smooth = (t: number) => { const c = clamp(t); return c * c * (3 - 2 * c); };+const back = (t: number) => { const c = clamp(t) - 1; return 1 + 2.4 * c * c * c + 1.4 * c * c; };++// ---------------------------------------------------------------- the cue table (frames)+const CUE = { swing: 255, side: 300, bow: 338, hold: 362, up: 390, go: 405, speed: 450, brake: 575, slid: 606, stood: 630, swingBack: 648, face: 690, eye: 720 } as const;+const STRIDE = 15, PH0 = 0.82; // a stride in frames; where in the stride she leaves the ground at CUE.go+const phase = (F: number) => PH0 + (F - CUE.go) / STRIDE;+// how fast the ground goes by (0-1), and how far it has gone. The far total is chosen so the near+// grass, which is cheetahDusk's own, is back exactly where that film left it when she stops.+const pace = (F: number) => smooth(ramp(F, CUE.go, CUE.speed)) * (1 - smooth(ramp(F, CUE.brake - 12, CUE.slid)));+const NEAR = 1.6, WRAP = 1400, TOP = 84; // the near grass's depth factor and its wrap; her top speed in px of ground per frame+const TRAVEL = (() => { const sub = 8, acc = [0]; for (let i = 1; i <= N * sub; i++) acc.push(acc[i - 1] + pace((i - 0.5) / sub) / sub); const total = acc[acc.length - 1], want = (Math.round((total * TOP * NEAR) / WRAP) * WRAP) / NEAR, k = want / (total * TOP); return (F: number) => { const x = clamp(F, 0, N) * sub, i = Math.min(N * sub - 1, Math.floor(x)); return lerp(acc[i], acc[i + 1], x - i) * TOP * k; }; })(); // px of ground gone by+const LAND = country(TRAVEL(N));+const frameAt = (g: number) => { let a: number = CUE.go, b: number = CUE.slid; for (let i = 0; i < 24; i++) { const m = (a + b) / 2; if (TRAVEL(m) < g) a = m; else b = m; } return b; };++// ---------------------------------------------------------------- her performance+const S = { stand: settle(STAND), bow: settle(BOW), crouch: settle(CROUCH), skid: settle(SKID) };+const HIND_X = 400, TRACK_X = 548; // where her hind foot stands on screen; where the camera holds her waist as she runs+const idle = (r: Rig, F: number): Rig => ({ ...r, headH: r.headH + Math.sin(F * (Math.PI / 45)) * 2.5, tail: r.tail.map((a, i) => a + Math.sin(F * (Math.PI / 30) - i * 0.7) * (2 + i * 2.2)) });+const held = (F: number): Rig => { // every pose she holds, and the moves between them+ if (F < CUE.side) return S.stand.rig;+ if (F < CUE.bow) return mixRig(S.stand.rig, S.bow.rig, inOut(ramp(F, CUE.side, CUE.bow)));+ if (F < CUE.hold) { const d = Math.sin(ramp(F, CUE.bow, CUE.hold) * Math.PI), q = Math.sin(F * 1.9) * d; return { ...S.bow.rig, lumb: S.bow.rig.lumb - 7 * d, headH: S.bow.rig.headH + 14 * d, head: S.bow.rig.head - 6 * d, tail: S.bow.rig.tail.map((a, i) => a + q * i * 1.6 + d * i * 3) }; }+ if (F < CUE.up) return mixRig(S.bow.rig, S.stand.rig, back(ramp(F, CUE.hold, CUE.up)));+ if (F < CUE.go) return mixRig(S.stand.rig, S.crouch.rig, inOut(ramp(F, CUE.up, CUE.go)));+ return mixRig(S.skid.rig, S.stand.rig, back(ramp(F, CUE.slid, CUE.stood)));+};+const standing = (F: number) => { const s = settle(idle(held(F), F)), q = fk(s.rig, 0, s.y, 0); return { rig: s.rig, y: s.y, x: HIND_X - q.hindN[4][0] }; };+const lead = (F: number) => 46 * Math.sin(ramp(F, CUE.go, CUE.speed + 30) * Math.PI) - 40 * Math.sin(ramp(F, CUE.brake - 6, CUE.stood) * Math.PI);+const poseAt = (F: number): Pose => {+ if (F < CUE.go || F >= CUE.slid) { const s = standing(F); return fk(s.rig, s.x + (F >= CUE.slid ? lerp(60, 0, smooth(ramp(F, CUE.slid, CUE.stood + 20))) + lead(F) : 0), s.y + FLOOR, FLOOR); }+ // running: the stride, taken up out of the crouch and given back to the braced stop+ const ph = phase(F), g = gallopRig(ph), a = standing(CUE.go - 0.001), b = standing(CUE.slid), wIn = out3(ramp(F, CUE.go, CUE.go + 9)), wOut = inOut(ramp(F, CUE.brake, CUE.brake + 13));+ let rig = mixRig(a.rig, g, wIn), y = lerp(a.y, gallopY(ph, g), wIn), x = lerp(a.x, TRACK_X, smooth(ramp(F, CUE.go, CUE.go + 24)));+ if (wOut > 0) { rig = mixRig(rig, b.rig, wOut); y = lerp(y, b.y, wOut); x = lerp(x, b.x + 60, wOut); }+ const l = lowest(fk(rig, 0, y, 0)), sink = Math.max(l.fore, l.hind); if (sink > 0) y -= sink; // never through the ground+ return fk(rig, x + lead(F), y + FLOOR, FLOOR);+};+// what her feet throw up, each where it was made on the ground: a kick at every footfall, a long cloud from the braced stop+const BURSTS = (() => {+ const out: (Burst & { born: number; g: number })[] = [];+ const add = (born: number, x: number, big: number, seed: number) => { const g = TRAVEL(born) + (x - 540); out.push({ born, g, x, y: FLOOR, age: 0, seed, wet: inPan(LAND, g), big }); };+ for (let n = 0; n < 13; n++) for (const [ph, fore] of [[0.2, true], [0.68, false]] as const) { const born = CUE.go + (n + ph - PH0) * STRIDE; if (born < CUE.go + 2 || born > CUE.brake + 2) continue; const q = poseAt(born); add(born, fore ? q.foreN[4][0] : q.hindN[4][0], fore ? 0.85 : 1.25, 300 + n * 2 + (fore ? 1 : 0)); }+ for (let i = 0; i < 9; i++) { const born = CUE.brake + 3 + i * 3.5, q = poseAt(born); add(born, q.foreN[4][0] + 10, 1.9 - i * 0.08, 500 + i); }+ return out;+})();+const bursts = (c: Ctx, F: number, wet: boolean) => { const X = TRAVEL(F); for (const b of BURSTS) if (b.wet === wet && F >= b.born && F < b.born + 20) drawBurst(c, { ...b, x: b.x - (X - TRAVEL(b.born)) * (wet ? 1 : 0.92), age: F - b.born }); };+// the frame takes a small knock as each pair of feet comes down+const knock = (F: number) => { if (F < CUE.go || F > CUE.brake + 20) return 0; const ph = (((phase(F) % 1) + 1) % 1), since = Math.min((ph - 0.2 + 1) % 1, (ph - 0.68 + 1) % 1) * STRIDE; return 4.5 * pace(F) * Math.exp(-since / 2.4) * Math.cos(since * 1.9); };++// ---------------------------------------------------------------- the world+// cheetahDusk's blade, mark for mark, so the grass is one grass across both seams+const blade = (c: Ctx, o: P, a: number, len: number, w: number, col: string) => {+ if (len < 1.5 || w < 0.6) return;+ const ca = Math.cos(a), sa = Math.sin(a), t: P = [o[0] + ca * len, o[1] + sa * len], m = len * 0.42, mx = o[0] + ca * m, my = o[1] + sa * m;+ const g = c.createLinearGradient(o[0], o[1], t[0], t[1]); g.addColorStop(0, mix(col, DARK, 0.6)); g.addColorStop(0.45, col); g.addColorStop(1, mix(col, "#ffffff", 0.16));+ c.fillStyle = g; c.beginPath(); c.moveTo(o[0], o[1]); c.quadraticCurveTo(mx - sa * w, my + ca * w, t[0], t[1]); c.quadraticCurveTo(mx + sa * w, my - ca * w, o[0], o[1]); c.fill();+};+const wrap = (x: number, span: number, lo: number) => ((((x - lo) % span) + span) % span) + lo;+const SCENE = (() => {+ const q = rng(3);+ // the near grass: cheetahDusk's seventy blades where that film has them, and more beyond its frame for when the camera is further back+ const more = rng(43), near = [...duskGrass, ...Array.from({ length: 22 }, (_, i) => ({ x: i % 2 ? -160 + more() * 160 : W + more() * 160, h: 90 + more() * 220, a: (more() - 0.5) * 0.5, w: 9 + more() * 8, col: more() < 0.15 ? TEAL : mix(NIGHT, TEAL, more() * 0.5), ph: more() * 6.28 }))];+ const far = Array.from({ length: 150 }, () => ({ x: q() * 1320, h: 26 + q() * 60, w: 5 + q() * 5, col: mix(NIGHT, TEAL, q() * 0.55), dy: q() * 10, a: (q() - 0.5) * 0.5, ph: q() * 6.28 }));+ const streaks = Array.from({ length: 34 }, () => ({ x: q() * 2200, y: 700 + q() * 150, len: 140 + q() * 420, w: 2.2 + q() * 4.5, col: mix(RUST, NIGHT, 0.35 + q() * 0.5), al: 0.3 + q() * 0.3 }));+ const flecks = Array.from({ length: 14 }, () => ({ x: q() * 2600, y: 880 + q() * 180, len: 200 + q() * 300, w: 1.4 + q() * 1.6, al: 0.1 + q() * 0.14 }));+ return { near, far, streaks, flecks };+})();+const SIDE_CAM = { z: 410 / 470, look: [540, 430 - 8 / (410 / 470)] as P }; // the sun where the look still has it: (540, 548), radius 410+const PIVOT: P = [540, FLOOR - 130];+// a camera of its own for the side: in on her for the stretch, back out to give the run its room, in a little as she flies+const push = (F: number) => 1 + 0.26 * inOut(ramp(F, CUE.side, CUE.bow)) * (1 - inOut(ramp(F, CUE.up - 6, CUE.go + 22))) + 0.07 * smooth(ramp(F, CUE.speed, CUE.speed + 45)) * (1 - smooth(ramp(F, CUE.brake - 30, CUE.brake))) + 0.12 * inOut(ramp(F, CUE.slid, CUE.stood + 6)) * (1 - inOut(ramp(F, CUE.swingBack - 18, CUE.swingBack)));++const grainLayer = (env: Env): Layer => { // the paper's tooth and the dusk settling at the edges: cheetahDusk's, grain for grain+ const key = "cheetahRun:grain"; let L = env.cache.get(key) as Layer | undefined; if (L) return L;+ L = env.canvas(Math.round(W * env.scale), Math.round(H * env.scale)); env.cache.set(key, L);+ const c = L.ctx, q = rng(77); c.setTransform(env.scale, 0, 0, env.scale, 0, 0);+ for (let i = 0; i < 200000; i++) { const x = q() * W, y = q() * H, d = Math.hypot(x - 540, y - 520) / 740; if (q() > d * d * d * 1.1) continue; c.fillStyle = DARK; c.globalAlpha = 0.42; c.fillRect(x, y, 1.1, 1.1); }+ for (let i = 0; i < 30000; i++) { const x = q() * W, y = q() * H, lt = q() < 0.5; c.fillStyle = lt ? "#fff5de" : "#000000"; c.globalAlpha = lt ? 0.06 : 0.08; c.fillRect(x, y, 1.1, 1.1); }+ return L;+};++const side = (ctx: Ctx, F: number, env: Env) => {+ const c = ctx, s = env.scale, out = F < CUE.swingBack, w = out ? ramp(F, CUE.swing, CUE.side) : 1 - ramp(F, CUE.swingBack, CUE.face), e = inOut(w), turning = w < 1;+ // cheetahDusk's world through a camera that pulls back as it comes round: its sun stays, far off+ const tau = out ? lerp(255, 262, ramp(F, CUE.swing, CUE.side)) : 262, d = camAt(tau), Z = push(F), zz = Math.exp(lerp(Math.log(d.z), Math.log(SIDE_CAM.z), e)) * Z;+ const cam = { z: zz, look: [lerp(d.look[0], SIDE_CAM.look[0], e) + ((PIVOT[0] - 540) * (Z - 1)) / zz, lerp(d.look[1], SIDE_CAM.look[1], e) + ((PIVOT[1] - 540) * (Z - 1)) / zz] as P };+ drawDusk(c, tau, env, { cam, world: F, face: false, grass: false, grain: false });+ // her, and how the turn places her: the head's centre on screen, its size, how far round we are+ const pose = poseAt(F), anchor = headAnchor(pose), yaw = (Math.PI / 2) * e, k0 = d.z, k = Math.exp(lerp(Math.log(k0), Math.log(HEAD_K), e)), kb = k / HEAD_K, sx = Math.sin(yaw);+ const P0: P = [(FACE[0] - d.look[0]) * d.z + 540, (FACE[1] - d.look[1]) * d.z + 540], hc: P = [lerp(P0[0], anchor[0], e), lerp(P0[1], anchor[1], e)];+ // the ground comes up under her as the camera pulls back: everything that stands on it rides on this line+ const drop = turning ? hc[1] + (FLOOR - anchor[1]) * kb - FLOOR : 0, shake = knock(F);+ const screen = () => c.setTransform(s * Z, 0, 0, s * Z, s * PIVOT[0] * (1 - Z), s * (PIVOT[1] * (1 - Z) + drop + shake));+ const v = pace(F), X = TRAVEL(F), lean = smooth(v);+ if (drop < 1400) {+ screen();+ drawFar(c, LAND, X, F, GROUND, lean);+ drawFlock(c, LAND, X, F, GROUND, frameAt);+ for (const g of SCENE.streaks) leaf(c, wrap(g.x - X * 0.8, 2200, -500) + g.len, g.y, Math.PI, g.len * (0.4 + 0.6 * v), g.w, g.col, g.al * v);+ c.fillStyle = mix(NIGHT, DARK, 0.35); c.fillRect(-40, GROUND, W + 80, H - GROUND + 400);+ for (const g of SCENE.far) leaf(c, wrap(g.x - X, 1320, -120), GROUND + 6 + g.dy, -Math.PI / 2 + g.a * (1 - lean) + Math.sin(F * (Math.PI / 45) + g.ph) * 0.06 * (1 - lean) - lean * 1.1, g.h * (1 + lean * 0.35), g.w, g.col);+ drawPan(c, LAND, X, F, GROUND, v);+ }+ const SWAP = 0.64; // past this point of the turn the head is small and nearly side-on, and the profile head takes over+ // the chest under the face goes first: it is a front, and a front narrows away and sinks behind her as we come round+ if (turning && yaw < 0.36) { c.save(); c.setTransform(s, 0, 0, s, 0, 0); c.beginPath(); c.rect(-10, -10, hc[0] + 240 * k * Math.cos(yaw) + 10, H + 20); c.clip(); turnedNeck(c, env, out ? 255 : 262, yaw, hc[0], hc[1] + (1 - Math.cos(yaw)) * 1500 * k, k); c.restore(); }+ if (sx > 0.03) {+ // her body: edge-on behind the face at first, its full length by the time we are beside her+ if (turning) c.setTransform(s * kb * sx, 0, 0, s * kb, s * (hc[0] - anchor[0] * kb * sx), s * (hc[1] - anchor[1] * kb)); else screen();+ const l = lowest(pose), air = clamp((FLOOR - Math.max(l.fore, l.hind)) / 60), x0 = pose.spine[0][0], x1 = pose.spine[9][0];+ for (let i = 0; i < 5; i++) { c.fillStyle = DARK; c.globalAlpha = 0.2 * (1 - air * 0.45); c.beginPath(); c.ellipse((x0 + x1) / 2 + 20, FLOOR + 8, ((x1 - x0) * 0.62 + 40) * (1 - i * 0.11) * (1 - air * 0.12), 15 - i * 2.1, 0, 0, Math.PI * 2); c.fill(); }+ c.globalAlpha = 1;+ bursts(c, F, false);+ drawCheetah(c, pose, turning && w < SWAP ? { head: false } : {});+ bursts(c, F, true);+ }+ if (turning && w < SWAP) turnedHead(c, env, out ? 255 : 262, yaw, hc[0], hc[1], k);+ // the near grass, in cheetahDusk's own camera: its blades, swept over and streaming while she runs+ c.setTransform(s * cam.z, 0, 0, s * cam.z, s * (540 - cam.look[0] * cam.z), s * (540 - cam.look[1] * cam.z));+ for (const g of SCENE.near) blade(c, [wrap(g.x - X * NEAR, WRAP, -160), H + 20], -Math.PI / 2 + g.a * (1 - lean * 0.8) + Math.sin(F * (Math.PI / 45) + g.ph) * 0.07 - lean * 1.02, g.h * (1 + lean * 0.45), g.w, g.col);+ screen();+ drawLens(c, LAND, X, H);+ for (const g of SCENE.flecks) leaf(c, wrap(g.x - X * 2.1, 2600, -600) + g.len, g.y, Math.PI, g.len, g.w, PALE, g.al * v);+ c.setTransform(1, 0, 0, 1, 0, 0); c.globalAlpha = 1; c.drawImage(grainLayer(env).canvas, 0, 0);+};++const draw = (ctx: Ctx, F: number, env: Env) => {+ if (F < CUE.swing) return drawDusk(ctx, F, env);+ if (F < CUE.face) return side(ctx, F, env);+ drawDusk(ctx, F < CUE.eye ? lerp(262, 270, ramp(F, CUE.face, CUE.eye)) : F - 450, env, { world: F });+};++// the score: nine bars at 80 bpm are the film's 27 s exactly, so the loop is the music's own+const audio = (sr: number): [Float32Array, Float32Array] => {+ const n = Math.round((N / 30) * sr), L = new Float32Array(n), R = new Float32Array(n), m = renderLoop(cheetahRunScore(), sr); // its tail folded back onto its start: no cut at the seam+ for (let i = 0; i < n && i < m.L.length; i++) { L[i] = m.L[i]; R[i] = m.R[i]; }+ return [L, R];+};++export const cheetahRun: Film = {+ meta: { title: "Cheetah, run", W, H, fps: 30, bpm: 120, durationFrames: N, raster: "cpu", kind: "loop", poster: 500, score: { tempo: 80, form: "9 bars of 12/8, looping: drone and cell, the cycle enters, one long note, held breath and go, the cell in her stride, the stop, home" }, sync: [{ frame: 405, label: "she goes" }, { frame: 575, label: "forefeet braced" }] },+ assets: { images: {} },+ shots: [{ id: "run", start: 0, end: N, draw }],+ audio: Object.assign(audio, { scores: [cheetahRunScore()] }),+};++// ---------------------------------------------------------------- the signed cut, for posting+// The loop played once, then four seconds on the night it ends in: the wordmark is written in the+// sky in the moon's own white, its dot landing on the score's last note, and the address is set+// under it. The stars and the grass keep moving; nothing else is added to the picture.+const END = N + 120, SIGN = { write: N + 10, dot: N + 38, url: N + 48, set: N + 66 };+const signed = (ctx: Ctx, F: number, env: Env) => {+ if (F < N) return draw(ctx, F, env);+ duskNight(ctx, F - 450, env);+ logoCentred(ctx, env, 540, 452, 92, ramp(F, SIGN.write, SIGN.write + (SIGN.dot - SIGN.write) / 0.9), { color: DUSK_PALE, pen: false });+ setType(ctx, env, "github.com/alexgreensh/anidoodle", 540, 628, 34, ramp(F, SIGN.url, SIGN.set), { color: DUSK_PALE, align: "center", weight: 600, track: 0.01 });+};+const signedAudio = (sr: number): [Float32Array, Float32Array] => {+ const n = Math.round((END / 30) * sr), L = new Float32Array(n), R = new Float32Array(n), m = renderPiece(cheetahRunSignedScore(), sr);+ for (let i = 0; i < n && i < m.L.length; i++) { L[i] = m.L[i]; R[i] = m.R[i]; }+ return [L, R];+};+export const cheetahRunSigned: Film = {+ meta: { title: "Cheetah, run (signed)", W, H, fps: 30, bpm: 120, durationFrames: END, raster: "cpu", kind: "story", poster: 500, score: { tempo: 80, form: "the nine bars once, then a tenth that closes them: the cell lands on the tonic and rings" }, sync: [{ frame: 405, label: "she goes" }, { frame: 575, label: "forefeet braced" }] },+ assets: { images: {} },+ shots: [{ id: "run", start: 0, end: END, draw: signed }],+ audio: Object.assign(signedAudio, { scores: [cheetahRunSignedScore()] }),+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRunSigned.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRunSigned.tsnew file mode 100644index 0000000..188015c--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahRunSigned.ts@@ -0,0 +1,2 @@+// The signed cut of "Cheetah, run", for posting: the film once, then the wordmark and the address on the night it ends in.+export { cheetahRunSigned } from "./cheetahRun";diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahScenery.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahScenery.tsnew file mode 100644index 0000000..85928ea--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahScenery.ts@@ -0,0 +1,108 @@+// THE COUNTRY SHE RUNS THROUGH. Speed is read from the world, so the world is in layers at their own+// distances, and each goes by at its own rate: the sun does not move at all, the far range creeps,+// the acacias drift, the scrub and rocks pass, the grass at her feet streams, and now and then+// something close to the lens whips across the whole frame. It is also a journey, not a treadmill:+// what she passes changes as the ground goes by under her.+// the thorn savanna (acacias, termite mounds) · a kopje (boulders, dead trees; the birds go up+// here) · a shallow pan (water, reeds, the sun laid down in it, spray off her feet) · grass again.+// Every element has a place on the ground, G, in px of ground travelled; a layer at depth factor f+// puts it on screen at 540 + (G - X) * f, where X is how far she has run. Nothing wraps, nothing repeats.+import { rng, type Ctx, type P } from "./core";+import { mix } from "./gallery";++const NIGHT = "#0d1a22", TEAL = "#2a6a70", RUST = "#b8452a", CORAL = "#f2643c", PALE = "#fff5de", DARK = "#0a1216", OCHRE = "#e3a23a";+const clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const lerp = (a: number, b: number, t: number) => a + (b - a) * t;+export const leaf = (c: Ctx, x: number, y: number, a: number, len: number, w: number, col: string, alpha = 1) => {+ if (alpha <= 0.004 || len < 1) return;+ const ca = Math.cos(a), sa = Math.sin(a), tx = x + ca * len, ty = y + sa * len, mx = x + ca * len * 0.42, my = y + sa * len * 0.42;+ c.globalAlpha = alpha; c.fillStyle = col; c.beginPath(); c.moveTo(x, y); c.quadraticCurveTo(mx - sa * w, my + ca * w, tx, ty); c.quadraticCurveTo(mx + sa * w, my - ca * w, x, y); c.fill(); c.globalAlpha = 1;+};+const UP = -Math.PI / 2;++// ---------------------------------------------------------------- the things that stand in it+// an umbrella thorn: a leaning trunk, a fork of boughs, and the flat crown laid in tiers+const acacia = (c: Ctx, x: number, base: number, h: number, seed: number, col: string, lit: string) => {+ const q = rng(seed), lean = (q() - 0.5) * 0.3, fx = x + lean * h * 0.4, fy = base - h * 0.5;+ leaf(c, x, base + 4, UP + lean * 0.8, h * 0.58, h * 0.055, col);+ for (const a of [-1.0, -0.45, 0.2, 0.8]) { const ang = UP + a + (q() - 0.5) * 0.2, len = h * (0.42 + q() * 0.16), tx = fx + Math.cos(ang) * len, ty = fy + Math.sin(ang) * len; leaf(c, fx, fy, ang, len, h * 0.026, col); const w = h * (0.34 + q() * 0.2); for (let k = 0; k < 3; k++) leaf(c, tx - w * (0.5 + (q() - 0.5) * 0.3), ty - k * h * 0.03 + q() * 4, 0, w * (1 - k * 0.18), h * (0.05 - k * 0.008), k === 2 ? lit : col); }+};+const deadTree = (c: Ctx, x: number, base: number, h: number, seed: number, col: string) => { const q = rng(seed), lean = (q() - 0.5) * 0.3; leaf(c, x, base + 4, UP + lean, h, h * 0.05, col); for (let k = 0; k < 5; k++) { const t = 0.35 + q() * 0.55, sd = k % 2 ? 1 : -1; leaf(c, x + Math.cos(UP + lean) * h * t, base + Math.sin(UP + lean) * h * t, UP + lean + sd * (0.5 + q() * 0.6), h * (0.2 + q() * 0.25), h * 0.016, col); } };+const mound = (c: Ctx, x: number, base: number, h: number, col: string) => { leaf(c, x, base + 6, UP, h, h * 0.42, col); leaf(c, x + h * 0.2, base + 6, UP + 0.12, h * 0.6, h * 0.3, col); };+const bush = (c: Ctx, x: number, base: number, h: number, seed: number, col: string, lit: string) => { const q = rng(seed); for (let k = 0; k < 9; k++) leaf(c, x + (q() - 0.5) * h * 0.5, base + 5, UP + (k / 8 - 0.5) * 1.9 + (q() - 0.5) * 0.2, h * (0.6 + q() * 0.4), h * 0.2, k % 4 === 0 ? lit : col); };+// boulders: each a lens lying on the one below it+const kopje = (c: Ctx, x: number, base: number, h: number, seed: number, col: string, lit: string) => { const q = rng(seed); for (let k = 0; k < 5; k++) { const w = h * (1.1 - k * 0.17) * (0.8 + q() * 0.4), ox = (q() - 0.5) * h * 0.5, y = base - k * h * 0.2 - h * 0.06; leaf(c, x + ox - w / 2, y, 0, w, h * (0.34 - k * 0.03), k === 4 ? lit : col); } };+const reeds = (c: Ctx, x: number, base: number, h: number, seed: number, col: string, F: number, lean: number) => { const q = rng(seed); for (let k = 0; k < 7; k++) { const a = UP + (q() - 0.5) * 0.4 + Math.sin(F * (Math.PI / 45) + k) * 0.05 - lean * 0.7, len = h * (0.6 + q() * 0.4), ox = (q() - 0.5) * h * 0.4; leaf(c, x + ox, base + 5, a, len, 3.2, col); if (k % 2) leaf(c, x + ox + Math.cos(a) * len * 0.82, base + 5 + Math.sin(a) * len * 0.82, a, len * 0.2, 5.5, mix(col, OCHRE, 0.35)); } };++// ---------------------------------------------------------------- where everything stands+export type Country = ReturnType<typeof country>;+/** Lay the country out along `total` px of ground. */+export const country = (total: number) => {+ const z = (g: number) => (g < total * 0.31 ? "thorn" : g < total * 0.6 ? "kopje" : g < total * 0.86 ? "pan" : "grass");+ const q = rng(911), span = (f: number) => [-760 / f, total + 760 / f] as const;+ type Item = { g: number; h: number; seed: number; kind: string };+ const scatter = (f: number, gap: (zone: string) => number, kind: (zone: string, r: number) => string, h: (kind: string, r: number) => number): Item[] => { const [a, b] = span(f), out: Item[] = []; for (let g = a; g < b; ) { const zone = z(g), k = kind(zone, q()); out.push({ g, h: h(k, q()), seed: Math.floor(q() * 1e6), kind: k }); g += gap(zone) * (0.55 + q() * 0.9); } return out; };+ const trees = scatter(0.22, (zn) => (zn === "thorn" ? 1150 : zn === "kopje" ? 1900 : zn === "pan" ? 4200 : 1500), (zn, r) => (zn === "kopje" && r < 0.55 ? "dead" : "acacia"), (k, r) => (k === "dead" ? 190 + r * 130 : 240 + r * 190));+ const mid = scatter(0.5, (zn) => (zn === "pan" ? 430 : zn === "kopje" ? 520 : 640), (zn, r) => (zn === "thorn" ? (r < 0.4 ? "mound" : "bush") : zn === "kopje" ? (r < 0.7 ? "kopje" : "bush") : zn === "pan" ? "reeds" : "bush"), (k, r) => (k === "mound" ? 95 + r * 85 : k === "kopje" ? 130 + r * 130 : k === "reeds" ? 105 + r * 75 : 62 + r * 52));+ const lens = [0.1, 0.27, 0.43, 0.57, 0.7, 0.83, 0.93].map((t, i) => ({ g: total * t + (q() - 0.5) * 300, seed: 40 + i, kind: i % 3 === 1 ? "trunk" : "grass" }));+ const flock = Array.from({ length: 18 }, () => ({ dx: (q() - 0.5) * 520, t0: q() * 9, vx: -1 + q() * 5, vy: 5 + q() * 6, size: 0.7 + q() * 0.6, ph: q() * 6.28 }));+ return { total, zone: z, trees, mid, lens, flock, flockG: total * 0.37, pan: [total * 0.6 + 260, total * 0.86 - 260] as const };+};++// ---------------------------------------------------------------- drawing it, back to front+const ridge = (c: Ctx, X: number, f: number, horizon: number, h0: number, h1: number, ph: number, col: string) => {+ c.fillStyle = col; c.beginPath(); c.moveTo(-20, horizon + 30);+ for (let x = -20; x <= 1100; x += 14) { const u = x + X * f + ph, n = 0.5 + 0.5 * (Math.sin(u / 211) * 0.5 + Math.sin(u / 97 + 1.7) * 0.3 + Math.sin(u / 43 + 0.6) * 0.2), peak = Math.pow(n, 1.6); c.lineTo(x, horizon - lerp(h0, h1, peak)); }+ c.lineTo(1100, horizon + 30); c.closePath(); c.fill();+};+/** Everything behind her: the two ranges, the trees, the scrub and rocks. `horizon` is the ground line on screen. */+export const drawFar = (c: Ctx, w: Country, X: number, F: number, horizon: number, lean: number) => {+ ridge(c, X, 0.03, horizon, 40, 170, 0, mix(CORAL, NIGHT, 0.6));+ ridge(c, X, 0.075, horizon, 16, 92, 900, mix(RUST, NIGHT, 0.8));+ const tree = mix(NIGHT, TEAL, 0.1), treeLit = mix(RUST, NIGHT, 0.55), near = mix(NIGHT, TEAL, 0.2), nearLit = mix(TEAL, NIGHT, 0.45);+ for (const t of w.trees) { const x = 540 + (t.g - X) * 0.22; if (x < -260 || x > 1340) continue; if (t.kind === "dead") deadTree(c, x, horizon, t.h, t.seed, tree); else acacia(c, x, horizon, t.h, t.seed, tree, treeLit); }+ for (const m of w.mid) { const x = 540 + (m.g - X) * 0.5; if (x < -200 || x > 1280) continue; if (m.kind === "mound") mound(c, x, horizon, m.h, mix(RUST, NIGHT, 0.72)); else if (m.kind === "kopje") kopje(c, x, horizon, m.h, m.seed, near, mix(RUST, NIGHT, 0.6)); else if (m.kind === "reeds") reeds(c, x, horizon, m.h, m.seed, nearLit, F, lean); else bush(c, x, horizon, m.h, m.seed, near, nearLit); }+};+/** The pan: shallow water lying on the ground she runs over, with the sun laid down in it. */+export const drawPan = (c: Ctx, w: Country, X: number, F: number, horizon: number, v: number) => {+ const a = 540 + (w.pan[0] - X), b = 540 + (w.pan[1] - X); if (b < -40 || a > 1120) return;+ const x0 = Math.max(-20, a), x1 = Math.min(1100, b), y0 = horizon + 8, y1 = horizon + 86;+ c.save(); c.beginPath(); c.moveTo(x0 - (a > -20 ? 60 : 0), y1); c.lineTo(x0, y0); c.lineTo(x1, y0); c.lineTo(x1 + (b < 1100 ? 60 : 0), y1); c.closePath(); c.clip();+ c.fillStyle = mix(TEAL, NIGHT, 0.52); c.fillRect(-80, y0, 1240, y1 - y0);+ const q = rng(70);+ // the sun in it, in broken bars under the sun itself; then the ripples going by+ for (let i = 0; i < 26; i++) { const yy = y0 + 4 + q() * (y1 - y0 - 8), half = 70 + q() * 230 * (1 - (yy - y0) / (y1 - y0) * 0.5), dx = (q() - 0.5) * 60 + Math.sin(F * 0.21 + i) * 9; leaf(c, 540 + dx - half, yy, 0, half * 2, 2.2 + q() * 2.6, i % 3 ? CORAL : "#ff8a4a", 0.5 + q() * 0.35); }+ for (let i = 0; i < 30; i++) { const gx = q() * 2400, yy = y0 + 3 + q() * (y1 - y0 - 6), len = 60 + q() * 200; leaf(c, ((((gx - X) % 2400) + 2400) % 2400) - 600, yy, 0, len * (1 + v), 1.2 + q() * 1.4, PALE, 0.1 + q() * 0.16); }+ c.restore();+};+export const inPan = (w: Country, g: number) => g > w.pan[0] + 30 && g < w.pan[1] - 30;+/** The birds she puts up as she comes through the kopje: out of the grass ahead of her, up and across the sun. */+export const drawFlock = (c: Ctx, w: Country, X: number, F: number, horizon: number, frameAt: (g: number) => number) => {+ const t0 = frameAt(w.flockG - 700); if (F < t0) return;+ const col = mix(NIGHT, DARK, 0.4);+ for (const b of w.flock) {+ const t = F - t0 - b.t0; if (t < 0 || t > 110) continue;+ const x = 540 + (w.flockG - X) * 0.82 + b.dx + b.vx * t, y = horizon - 6 - b.vy * t * (1 - t / 260) - Math.sin(t * 0.25 + b.ph) * 6, flap = Math.sin(t * 0.85 + b.ph), s = 13 * b.size;+ if (x < -60 || x > 1140 || y < -40) continue;+ leaf(c, x, y, Math.PI + 0.25 + flap * 0.75, s * 1.5, s * 0.36, col); leaf(c, x, y, -0.25 - flap * 0.75, s * 1.5, s * 0.36, col); leaf(c, x - s * 0.5, y, 0, s, s * 0.22, col);+ }+};+/** What crosses close to the lens: a spray of grass, or a thorn trunk with a bough, dark and huge, gone in a few frames. */+export const drawLens = (c: Ctx, w: Country, X: number, bottom: number) => {+ for (const o of w.lens) {+ const x = 540 + (o.g - X) * 3.1; if (x < -700 || x > 1780) continue;+ const q = rng(o.seed), col = mix(NIGHT, DARK, 0.55);+ if (o.kind === "trunk") { leaf(c, x - 60, bottom + 60, UP + 0.06, 1500, 150, col); leaf(c, x - 30, bottom - 620, UP + 1.05, 700, 46, col); leaf(c, x - 60, bottom - 760, UP - 0.9, 560, 38, col); }+ else for (let k = 0; k < 16; k++) leaf(c, x + (q() - 0.5) * 420, bottom + 60, UP - 0.75 + (q() - 0.5) * 0.5, 520 + q() * 560, 26 + q() * 30, k % 5 === 0 ? mix(TEAL, NIGHT, 0.6) : col);+ }+};+export type Burst = { x: number; y: number; age: number; seed: number; wet: boolean; big: number };+/** What her feet throw up: dust off the plain, spray out of the pan. */+export const drawBurst = (c: Ctx, b: Burst) => {+ const q = rng(b.seed), n = b.wet ? 16 : 11, life = b.wet ? 13 : 18, k = b.age / life; if (k < 0 || k > 1) return;+ for (let i = 0; i < n; i++) {+ const a = b.wet ? UP + (q() - 0.5) * 1.9 : Math.PI + 0.15 + q() * 0.95, sp = 0.4 + q() * 0.6, d = q();+ if (b.wet) { const vx = Math.cos(a) * 9 * sp * b.big, vy = Math.sin(a) * 15 * sp * b.big, t = b.age; leaf(c, b.x + vx * t, b.y + vy * t + 0.75 * t * t, Math.atan2(vy + 1.5 * t, vx), 9 + sp * 13, 2.4 + d * 1.6, d < 0.4 ? PALE : mix(PALE, TEAL, 0.45), 0.9 * (1 - k)); }+ else leaf(c, b.x - d * 70 * k * b.big, b.y - 4 - d * 56 * k * b.big, a, (24 + d * 58) * b.big * Math.min(1, k * 3), (7 + q() * 8) * b.big, mix(mix(OCHRE, PALE, 0.4), NIGHT, 0.12 + q() * 0.25), (0.62 - d * 0.15) * (1 - k));+ }+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahTurn.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahTurn.tsnew file mode 100644index 0000000..7df4fad--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/cheetahTurn.ts@@ -0,0 +1,63 @@+// THE HEAD THAT TURNS. cheetahDusk's face is a flat drawing; here it is wrapped onto a head (a ball,+// with the muzzle standing out of it) and that head is turned about its upright axis, so the camera+// can come round from the front to the side and it is the same face all the way: at yaw 0 it is the+// drawing, untouched; by 90 degrees one eye and one tear line are left, the nose is the profile's+// leading edge, and the back of the head has come round from behind, in the same coat.+// How: the face is drawn once into a layer and laid over a grid of small triangles. Each corner of the+// grid has a depth; turning moves it sideways by that depth; each triangle carries its piece of the+// drawing across with an affine map. Nothing is generated and nothing is sampled from a clock.+import { type Ctx, type Env, type Layer, type P } from "./core";+import { duskFace, FACE } from "./cheetahDusk";++const R = 372, SQ = 0.95, OVER = 1.25; // the head's radius in the drawing; its slight flattening; the layer's oversampling+const X0 = 60, X1 = 1020, Y0 = 150, Y1 = 1070, NX = 34, NY = 32;+type Part = "neck" | "coat" | "head";+const layer = (env: Env, f: number, part: Part): Layer => {+ const key = `cheetahTurn:${part}:${f}`; let L = env.cache.get(key) as Layer | undefined; if (L) return L;+ const k = env.scale * OVER; L = env.canvas(Math.round(1080 * k), Math.round(1080 * k)); env.cache.set(key, L);+ L.ctx.setTransform(k, 0, 0, k, 0, 0); duskFace(L.ctx, f, part); L.ctx.setTransform(1, 0, 0, 1, 0, 0);+ return L;+};+const ball = (x: number, y: number) => { const dx = x - FACE[0], dy = (y - FACE[1]) / SQ, r2 = dx * dx + dy * dy; return r2 < R * R ? Math.sqrt(R * R - r2) : 0; };+// the front of the head: the ball, and the muzzle pushed forward out of it below the eyes+const front = (x: number, y: number) => ball(x, y) + 150 * Math.exp(-((x - 540) ** 2 + (y - 735) ** 2) / (2 * 105 * 105));+const GRID = (() => { const g: { x: number; y: number; zf: number; zb: number; in: boolean }[] = []; for (let j = 0; j <= NY; j++) for (let i = 0; i <= NX; i++) { const x = X0 + ((X1 - X0) * i) / NX, y = Y0 + ((Y1 - Y0) * j) / NY, b = ball(x, y); g.push({ x, y, zf: front(x, y), zb: -b, in: b > 0 }); } return g; })();++/** The head, turned by `yaw` radians (0 faces us, positive brings the nose round to the right), its centre at (cx, cy) on screen, drawn at scale k. */+export const turnedHead = (c: Ctx, env: Env, f: number, yaw: number, cx: number, cy: number, k: number) => {+ const s = env.scale, cs = Math.cos(yaw), sn = Math.sin(yaw), head = layer(env, f, "head"), coat = layer(env, f, "coat");+ const put = (x: number, y: number, z: number): [number, number, number] => [cx + k * ((x - FACE[0]) * cs + z * sn), cy + k * (y - FACE[1]), -(x - FACE[0]) * sn + z * cs];+ const F = GRID.map((g) => put(g.x, g.y, g.zf)), B = yaw > 0.02 ? GRID.map((g) => put(g.x, g.y, g.zb)) : [];+ const tris: { img: Layer; a: number; b: number; c: number; v: [number, number, number][]; d: number }[] = [];+ for (let j = 0; j < NY; j++) for (let i = 0; i < NX; i++) {+ const p = j * (NX + 1) + i, q = p + 1, r = p + NX + 1, t = r + 1;+ for (const [a, b, cc] of [[p, q, r], [q, t, r]] as const) {+ const area = (v: [number, number, number][]) => (v[b][0] - v[a][0]) * (v[cc][1] - v[a][1]) - (v[cc][0] - v[a][0]) * (v[b][1] - v[a][1]);+ if (area(F) > 0.02 * k * k) tris.push({ img: head, a, b, c: cc, v: F, d: F[a][2] + F[b][2] + F[cc][2] }); // facing us+ if (B.length && GRID[a].in && GRID[b].in && GRID[cc].in && area(B) < -0.02 * k * k) tris.push({ img: coat, a, b, c: cc, v: B, d: B[a][2] + B[b][2] + B[cc][2] }); // the back, come round+ }+ }+ tris.sort((m, n) => m.d - n.d);+ const o = OVER;+ for (const t of tris) {+ const s0 = GRID[t.a], s1 = GRID[t.b], s2 = GRID[t.c], d0 = t.v[t.a], d1 = t.v[t.b], d2 = t.v[t.c];+ const ax = s1.x - s0.x, ay = s1.y - s0.y, bx = s2.x - s0.x, by = s2.y - s0.y, det = ax * by - bx * ay; if (!det) continue;+ const ux = d1[0] - d0[0], uy = d1[1] - d0[1], vx = d2[0] - d0[0], vy = d2[1] - d0[1];+ const m11 = (ux * by - vx * ay) / det, m12 = (vx * ax - ux * bx) / det, m21 = (uy * by - vy * ay) / det, m22 = (vy * ax - uy * bx) / det;+ const tx = d0[0] - m11 * s0.x - m12 * s0.y, ty = d0[1] - m21 * s0.x - m22 * s0.y;+ // clip to the triangle, grown a hair so neighbours leave no seam, then lay the drawing through the map+ const gx = (d0[0] + d1[0] + d2[0]) / 3, gy = (d0[1] + d1[1] + d2[1]) / 3, grow = (p: [number, number, number]): P => { const dx = p[0] - gx, dy = p[1] - gy, l = Math.hypot(dx, dy) || 1; return [p[0] + (dx / l) * 0.8, p[1] + (dy / l) * 0.8]; };+ const e0 = grow(d0), e1 = grow(d1), e2 = grow(d2);+ c.save(); c.setTransform(s, 0, 0, s, 0, 0); c.beginPath(); c.moveTo(e0[0], e0[1]); c.lineTo(e1[0], e1[1]); c.lineTo(e2[0], e2[1]); c.closePath(); c.clip();+ c.setTransform(m11 / o, m21 / o, m12 / o, m22 / o, s * tx, s * ty); c.drawImage(t.img.canvas, 0, 0); c.restore();+ }+};++/** The chest under the face, as cheetahDusk has it: a flat front that narrows away as the camera comes round. */+export const turnedNeck = (c: Ctx, env: Env, f: number, yaw: number, cx: number, cy: number, k: number) => {+ const w = Math.cos(yaw) ** 2; if (w < 0.03) return;+ const s = env.scale, L = layer(env, f, "neck");+ c.save(); c.setTransform(s * k * w, 0, 0, s * k, s * (cx - FACE[0] * k * w), s * (cy - FACE[1] * k)); c.drawImage(L.canvas, 0, 0, 1080, 1080); c.restore();+};+/** The size the turned head must be drawn at to stand in for the profile head cheetahBody draws. */+export const HEAD_K = 0.118;diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/arc.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/arc.tsnew file mode 100644index 0000000..c503bb6--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/arc.ts@@ -0,0 +1,55 @@+// THE SHAPE OF A SCORE. craft.ts reads how a piece is WRITTEN; this reads how the finished sound+// MOVES over its length: where it is quiet, where it is loudest, and how it ends. A score can pass+// every other check and still feel like it wanders, because nothing in it is the high point and+// nothing in it is the rest. The shape that reads as one piece: a soft way in, a body, one clear+// loudest moment on the picture's payoff, and an ending that takes things away.+// Advisory, like craft: these are findings to answer, never a gate. A lullaby is flat on purpose.+// const a = arcReport([L, R], 48000, { loop: false, payoffS: 13.5 }); console.log(arcText(a));+import { loudness } from "./meter";++export type ArcFinding = { level: "warn" | "info"; msg: string; fix: string };+export type ArcReport = {+ durationS: number; loop: boolean;+ medianLu: number; // the piece's usual level: the median momentary loudness of everything above silence+ peakLu: number; peakS: number; peakAt: number; // the loudest moment, when, and how far through (0..1)+ peakOverMedian: number;+ introUnderBody: number; // how far the first 2.5 s sit under the median (positive = quieter)+ endUnderPeak: number; // how far the last second sits under the loudest moment+ seamJump: number; // loops: the level step from the last second to the first+ insideJump: number; // loops: the largest step between two neighbouring seconds anywhere else in the piece+ lra: number;+ findings: ArcFinding[];+};+const mean = (a: number[]) => { const p = a.map((l) => Math.pow(10, l / 10)); return 10 * Math.log10(p.reduce((x, y) => x + y, 0) / Math.max(1, p.length)); };+const SILENT = -70;++/** How the sound moves over the piece. `payoffS` is the second the picture pays off, when the film has one. */+export const arcReport = (chans: Float32Array[], sr: number, o: { loop?: boolean; payoffS?: number } = {}): ArcReport => {+ if (!chans.length || !chans[0]) throw new Error("arcReport needs at least one channel of sound");+ const l = loudness(chans, sr), m = l.momentary, hop = l.hopS, dur = chans[0].length / sr, loop = !!o.loop, at = (i: number) => i * hop + 0.2;+ const live = m.filter((x) => x > SILENT).sort((a, b) => a - b), medianLu = live.length ? live[Math.floor(live.length / 2)] : SILENT;+ let pi = 0; m.forEach((x, i) => { if (x > m[pi]) pi = i; });+ const peakLu = m.length ? m[pi] : SILENT, peakS = at(pi), peakAt = dur > 0 ? peakS / dur : 0, win = (a: number, b: number) => { const w = m.filter((_, i) => at(i) >= a && at(i) <= b); return w.length ? mean(w) : SILENT; };+ const introUnderBody = medianLu - win(0, 2.5), endUnderPeak = peakLu - win(dur - 1, dur), seamJump = m.length ? Math.abs(win(dur - 1, dur) - win(0, 1)) : 0;+ // a loop's join is heard when it is a bigger step than the piece makes anywhere else: a phrase ending into a quiet bar is the music, not a seam+ let insideJump = 0; for (let t = 0; t + 2 <= dur; t++) insideJump = Math.max(insideJump, Math.abs(win(t + 1, t + 2) - win(t, t + 1)));+ const lra = Number.isFinite(l.lra) ? l.lra : 0, silent = peakLu <= SILENT;+ const f: ArcFinding[] = [], r1 = (x: number) => x.toFixed(1), pc = (x: number) => `${Math.round(x * 100)}%`;+ if (silent) return { durationS: dur, loop, medianLu, peakLu, peakS, peakAt, peakOverMedian: 0, introUnderBody: 0, endUnderPeak: 0, seamJump: 0, insideJump: 0, lra, findings: f }; // nothing sounds: nothing to shape+ if (dur >= 8 && peakLu - medianLu < 2) f.push({ level: "warn", msg: `nothing is the high point: the loudest moment is only ${r1(peakLu - medianLu)} LU over the usual level`, fix: "hold something back (the low drum, the top octave, a doubling) until the payoff, and thin the bars before it" });+ if (dur >= 20 && lra < 5) f.push({ level: "warn", msg: `little contrast: the loudness range is ${r1(lra)} LU over ${r1(dur)} s`, fix: "a piece this long wants 5 to 8: give one section fewer parts, or a bar of near silence before the high point" });+ if (o.payoffS !== undefined && Math.abs(peakS - o.payoffS) > 1.5) f.push({ level: "warn", msg: `the loudest moment is at ${r1(peakS)} s, the picture pays off at ${r1(o.payoffS)} s`, fix: "move the fullest bar onto the payoff, or thin whatever is out-shouting it" });+ if (loop) { if (seamJump > 3 && seamJump > insideJump) f.push({ level: "warn", msg: `the level steps ${r1(seamJump)} LU where the loop comes round, more than anywhere inside it (${r1(insideJump)} LU)`, fix: "end as thin as it begins, or begin as full as it ends" }); }+ else {+ if (dur >= 8 && introUnderBody < 0) f.push({ level: "info", msg: `it opens ${r1(-introUnderBody)} LU over its usual level: there is nothing left to build to`, fix: "open with fewer parts and no low drum, 5 to 12 LU under the body, for the first two or three seconds" });+ if (dur >= 8 && introUnderBody > 12) f.push({ level: "info", msg: `the first 2.5 s sit ${r1(introUnderBody)} LU under the rest: it reads as nothing happening yet`, fix: "frame 0 wants one sound with a reason (a drone, the first chord), even a soft one" });+ if (dur >= 8 && peakAt > 0.8) f.push({ level: "warn", msg: `the loudest moment is ${pc(peakAt)} of the way through: the ending out-shouts the film`, fix: "an ending resolves, it does not climb: stop on a bar line, leave a breath, then one soft element" });+ else if (dur >= 8 && endUnderPeak < 8) f.push({ level: "info", msg: `the last second is only ${r1(endUnderPeak)} LU under the loudest moment`, fix: "let the ending take parts away: the close sits 8 to 20 dB under the peak" });+ }+ return { durationS: dur, loop, medianLu, peakLu, peakS, peakAt, peakOverMedian: peakLu - medianLu, introUnderBody, endUnderPeak, seamJump, insideJump, lra, findings: f };+};++export const arcText = (a: ArcReport) => {+ const r1 = (x: number) => x.toFixed(1), head = `ARC usual ${r1(a.medianLu)} LUFS · loudest ${r1(a.peakLu)} at ${r1(a.peakS)} s (${Math.round(a.peakAt * 100)}% through, ${r1(a.peakOverMedian)} LU over) · range ${r1(a.lra)} LU · ${a.loop ? `loop seam step ${r1(a.seamJump)} LU (largest inside ${r1(a.insideJump)})` : `opens ${r1(a.introUnderBody)} LU under, ends ${r1(a.endUnderPeak)} LU under the peak`}`;+ return [head, ...(a.findings.length ? a.findings.map((f) => ` ${f.level.toUpperCase().padEnd(4)} ${f.msg}\n -> ${f.fix}`) : [" the shape holds: nothing to answer"])].join("\n");+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/index.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/index.tsindex 29b7858..11b2c7e 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/index.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/index.ts@@ -18,6 +18,7 @@ export * from "./vocabVoices";export * from "./compose";export * from "./novelty";export * from "./craft";+export * from "./arc";export * from "./craftTables";export * from "./calibration";export * as instruments from "./instruments";diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/meter.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/meter.tsindex a411eae..986c64b 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/meter.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/meter.ts@@ -53,7 +53,7 @@ export const loudness = (chans: Float32Array[], sr: number) => {const stG = stAbs.map(lufs).filter((l) => l > stRel).sort((a, b) => a - b);const pct = (p: number) => (stG.length ? stG[Math.min(stG.length - 1, Math.max(0, Math.round((p / 100) * (stG.length - 1))))] : NaN);const shortTerm = st.map(lufs);- return { integrated, lra: pct(95) - pct(10), shortMax: Math.max(...shortTerm), momentaryMax: Math.max(...blocks.map(lufs)), shortTerm, hopS: 0.1 };+ return { integrated, lra: pct(95) - pct(10), shortMax: Math.max(...shortTerm), momentaryMax: Math.max(...blocks.map(lufs)), shortTerm, momentary: blocks.map(lufs), hopS: 0.1 }; // momentary: one 400 ms block every hop, block i centred at i * hopS + 0.2 s};export const truePeak = (chans: Float32Array[]) => {diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/pieces/cheetahRun.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/pieces/cheetahRun.tsnew file mode 100644index 0000000..00f3b8e--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/pieces/cheetahRun.ts@@ -0,0 +1,70 @@+// CHEETAH, RUN: the score. Nine bars of 12/8 at 80 bpm, exactly the film's 27 s, written to loop.+// One idea held all the way through: a G drone, the G major pentatonic, one marimba cell that grows,+// and a hand-percussion cycle that comes in under it, fills for the run and thins away again. It+// draws on East African mallet and lyre music for its shape (a drone, a cycling pattern, a melody+// that returns to the drone note); every note here is written for this film.+// The cell: up from the fifth through the sixth to the tonic, D E G. The 12/8 lilt never changes, so+// the run is the same music at full strength, not a different piece: her stride is 15 frames, a+// quarter note here, six to the bar across the bar's four beats.+// BARS [film]: 1 the drone and the cell, alone [night, the sun] · 2-3 the cell answers itself, the+// drums begin [the face makes itself, alive] · 4 one long note over a harp sweep [the turn, the bow] ·+// 5 the drone steps to E, two beats held, then a run of eighths up [she gathers; she goes at 405] ·+// 6 the cell in her stride, the highest note, full drums [at speed] · 7 three strides and everything+// stops [forefeet braced at 575] · 8-9 the cell comes home, the drone turns back [she stands, the+// turn back, into the eye], and round again.+import { type Piece } from "../plan";+import { composePiece, type Material } from "../compose";++const SHAKE = "C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected]";+export const cheetahRunMaterial = (): Material => ({+ style: "world", title: "Cheetah, run", seed: 5521, mood: "joy", bpm: 80, key: "G", mode: "majorPentatonic", meter: "12/8", loop: true, tail: 1.2,+ voices: { lead: "marimba" }, levels: { lead: 4, counter: -5, kick: -4.5, ghost: -6, perc: 8, chords: -3 }, moodControls: { energy: 0.5, warmth: 0.5, brightness: 0.68, tension: 0.4, space: 0.5 },+ chords: {+ G: { voicing: "[G2 D3 G3]", bass: "G1:4" },+ E: { voicing: "[E2 B2 E3]", bass: "E1:4" },+ D: { voicing: "[D3 A3 D4]", bass: "D2:4" },+ },+ motifs: {+ call: "r:2 D5:1/3 E5:1/3 G5:4/3",+ answer: "E5:1/3 D5:1/3 B4:1/3 D5:1 r:1 D5:1/3 E5:1/3 G5:1/3",+ alive: "A5:2/3 G5:1/3 E5:1 D5:1/3 E5:1/3 G5:1/3 D5:1",+ stretch: "E5:1/3 G5:1/3 A5:7/3 G5:1",+ gather: "r:2 B4:1/3 D5:1/3 E5:1/3 G5:1/3 A5:1/3 B5:1/3",+ stride: "D6:2/[email protected] B5:2/3 A5:2/3 G5:2/3 A5:2/3 B5:2/3",+ brace: "D6:2/[email protected] B5:2/3 G5:2/3 r:2",+ stand: "r:1 D5:1/3 E5:1/3 G5:1/3 E5:1 D5:1",+ home: "r:1 B4:1/3 D5:1/3 E5:1/3 D5:2",+ rest: "r:4",+ echo: "r:3 G4:1/3 D5:1/3 G5:1/3",+ sweep: "G3:1/3 D4:1/3 G4:1/3 B4:1/3 D5:1/3 G5:1/3 r:2",+ roll: "G4:1/3 D5:1/3 G5:1/3 D5:1/3 B4:1/3 D5:1/3 G4:1/3 D5:1/3 G5:1/3 D5:1/3 B4:1/3 D5:1/3",+ rollStop: "G4:1/3 D5:1/3 G5:1/3 D5:1/3 r:8/3",+ settle: "r:2 [G4 D5]:2",+ },+ grooves: {+ // the cycle: a low stroke on one and a lighter one on three, a rim answer, a shaker on the lilt+ cycle: { kick: ["G2:2 G2:[email protected] r:1"], ghost: ["r:1 C4:1/[email protected] r:2/3 r:1 C4:1/[email protected] r:2/3"], perc: ["C4:1/[email protected] r:1/3 C4:1/[email protected] C4:1/[email protected] r:1/3 C4:1/[email protected] C4:1/[email protected] r:1/3 C4:1/[email protected] C4:1/[email protected] r:1/3 C4:1/[email protected]"] },+ thin: { kick: ["G2:2 r:2"], perc: ["C4:1/[email protected] r:2/3 r:1 C4:1/[email protected] r:2/3 r:1"] },+ launch: { kick: ["r:2 G2:1 G2:[email protected]"], ghost: ["r:2 C4:2/3 C4:2/[email protected] C4:2/3"], perc: ["r:2 C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected]"] },+ gallop: { kick: ["G2:1 G2:[email protected] G2:1 G2:[email protected]", "G2:1 G2:1/[email protected] r:8/3"], ghost: ["C4:2/3 C4:2/[email protected] C4:2/3 C4:2/[email protected] C4:2/3 C4:2/[email protected]", "C4:2/3 C4:2/[email protected] r:8/3"], perc: [SHAKE, "C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] C4:1/[email protected] r:8/3"] },+ },+ sections: [+ { kind: "intro", bars: 1, harmony: ["G"], lead: ["call"], energy: 0.35 },+ { kind: "verse", bars: 3, harmony: ["G", "~", "~"], lead: ["answer", "alive", "stretch"], counter: ["rest", "echo", "sweep"], groove: "cycle", energy: 0.45 },+ { kind: "build", bars: 1, harmony: ["E"], lead: ["gather"], groove: "launch", energy: 0.6 },+ { kind: "drop", bars: 2, harmony: ["G", "~"], lead: ["stride", "brace"], counter: ["roll", "rollStop"], groove: "gallop", energy: 0.9 },+ { kind: "breath", bars: 2, harmony: ["G", "D"], lead: ["stand", "home"], counter: ["settle", "rest"], groove: "thin", energy: 0.35 },+ ],+});+export const cheetahRunScore = (): Piece => composePiece(cheetahRunMaterial());+// The signed cut: the same nine bars played once, then a tenth that closes them. The cell one last+// time, landing on the tonic and held, over a rolled harp chord and one soft low stroke; no cycle.+// The ending takes away: it is the quietest bar of the piece, and it is left to ring.+export const cheetahRunSignedMaterial = (): Material => {+ const m = cheetahRunMaterial();+ return { ...m, title: "Cheetah, run (signed)", loop: false, tail: 2.2,+ motifs: { ...m.motifs, sign: "r:1 D5:1/[email protected] E5:1/[email protected] G5:7/[email protected]", signHarp: "G3:1/[email protected] D4:1/[email protected] G4:1/[email protected] r:1 [G4 D5]:[email protected]" },+ grooves: { ...m.grooves, last: { kick: ["G2:[email protected]"] } },+ sections: [...m.sections, { kind: "outro", bars: 1, harmony: ["G"], lead: ["sign"], counter: ["signHarp"], groove: "last", energy: 0.25 }] };+};+export const cheetahRunSignedScore = (): Piece => composePiece(cheetahRunSignedMaterial());diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/render.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/render.tsindex e79fbb1..486f3de 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/render.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/render.ts@@ -6,7 +6,7 @@ import { type Piece, type Part, resequence, beatsPerBar } from "./plan";import { perform, type Performance, type Played } from "./perform";import { renderPiano, PIANO_REAL, type PianoOpts } from "./piano";import { keysVoice, renderPianoV2 } from "./keys";-import { bankFor, samplerVoice, sampleZones, registerBank, type SampleBank, type SampleTrim } from "./sampler";+import { bankFor, pinnedPitch, samplerVoice, sampleZones, registerBank, type SampleBank, type SampleTrim } from "./sampler";import * as I from "./instruments";import * as O from "./orchestra";import { chokeTimes, type KitCtx } from "./drums";@@ -65,7 +65,9 @@ const v2Job = (piece: Piece, pt: Part, pi: number, keys: Played[], perf: Performconst transient = style.master === "gentle" && tg && isStruck(pt.inst, pt.opts) ? tg : undefined;const post: StemPost | undefined = lofi || amp !== undefined || transient ? { id: pt.id, seed: piece.seed, ...(lofi ? { lofi, period } : {}), ...(amp !== undefined ? { amp } : {}), ...(transient ? { transient } : {}) } : undefined;const bank = pt.opts?.sampled === false ? undefined : bankFor(pt.inst, typeof pt.opts?.variant === "string" ? pt.opts.variant : undefined);- const base = bank ? { kind: "sampled" as const, bank: bank.id, bankHash: bank.hash, inst: pt.inst, keys, pedal: perf.pedal, sr, n, seed: pt.inst === "piano" ? piece.seed + pi : piece.seed * 101 + pi, opts: pt.opts }+ // a recorded timpani pinned to a note plays it, as the modelled one does: a drum lane's written pitch is a placeholder+ const pin = bank && pt.inst === "timpani" && typeof pt.opts?.pitch === "number" ? pinnedPitch(pt.opts.pitch as number, bank.entry.range) : undefined, played = pin === undefined ? keys : keys.map((k) => ({ ...k, p: pin }));+ const base = bank ? { kind: "sampled" as const, bank: bank.id, bankHash: bank.hash, inst: pt.inst, keys: played, pedal: perf.pedal, sr, n, seed: pt.inst === "piano" ? piece.seed + pi : piece.seed * 101 + pi, opts: pt.opts }: pt.inst === "piano" ? (o.piano ? { kind: "piano" as const, keys, pedal: perf.pedal, sr, n, seed: piece.seed + pi, v1: o.piano } : { kind: "piano" as const, keys, pedal: perf.pedal, sr, n, seed: piece.seed + pi, opts: pt.opts ?? {} }): { kind: "voice" as const, inst: pt.inst, opts: pt.opts, keys, sr, n, seed: piece.seed * 101 + pi, ctx };const roomHashes: [string, string, number, number][] = [effectiveSpace(piece.plan.space)?.room ?? prof.space?.room, prof.drumRoom?.room].flatMap((id) => { const r = roomFor(id); return r && id ? [[id, r.sha256, r.rt60, r.directFrames ?? 0] as [string, string, number, number]] : []; });diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/sampler.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/sampler.tsindex 7743653..6c909f0 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/sampler.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/sampler.ts@@ -61,6 +61,8 @@ export const sampleCutoff = (e: SampleEntry, z: SampleZone, k: Played, sr: numbereturn Math.min(sr * 0.45, 350 + 17650 * t * t);};export const sampleGain = (e: SampleEntry, z: SampleZone, v: number) => e.normalized ? pianoVelocity(v) * db(-8 * Math.max(0, 0.6 - v)) : v <= 0 ? 0 : db(clamp(16 * (v - layerV(e, z.layer)), -6, 6));+/** A drum tuned to one note (a timpani in a drum lane) plays that note whatever the lane wrote, moved by octaves into what was recorded. */+export const pinnedPitch = (pitch: number, range: readonly [number, number] | readonly number[]) => { if (!Number.isFinite(pitch)) throw new Error(`a pinned pitch must be a note number, got ${pitch}`); let p = Math.round(pitch); while (p < range[0]) p += 12; while (p > range[1]) p -= 12; return p < range[0] ? range[0] : p; };/** Nearest pitch, then nearest layer, then this note's seeded recording. State stays local to a render. */export const sampleZones = (bank: SampleBank, keys: Played[], seed: number, pedal: PedalSpan[] = [], art?: "rel") => {const previous = new Map<string, SampleBank["zones"][number]>(), e = bank.entry, pool = bank.zones.filter(({ zone }) => zone.art === art);diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/seams.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/seams.tsnew file mode 100644index 0000000..cf061c5--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/seams.ts@@ -0,0 +1,115 @@+// SEAMS WITH NUMBERS. A cut between two moving shots reads as one move when the motion carries+// across it: the outgoing shot accelerates, the cut lands at its fastest frame, and the incoming+// shot opens already travelling the same way at the same speed, then comes to rest. This file is+// the arithmetic for that, and the checks that hold a film to it. It draws nothing: the numbers+// go into each scene's own camera (camera.ts), so nothing is ever slid across an empty frame.+// Which seam a story is asking for, and when none of these is, is references/motion-grammar.md.+//+// const m = matchedMove({ dir: 0, exitDist: 260, exitF: 12, entryF: 40 });+// sceneA camera look = restA + m.out(local, CUT) accelerates away over its last 12 frames, the last being CUT - 1+// sceneB camera look = restB + m.in(local, CUT) arrives over the 40 frames from CUT, at rest on restB+// const z = matchedZoom({ push: 1.2, exitF: 6, entryF: 15 });+// sceneA zoom = zoomA * z.out(local, CUT); sceneB zoom = zoomB * z.in(local, CUT); a flight through the cut+// checkSeam(velocityAt(lookA, CUT - 1), velocityAt(lookB, CUT + 1), { W, fps }) findings, empty when it holds+// checkSeamPlan([{ type: "iris" }, { type: "matched cut" }, ...]) a seam used a third time+//+// The incoming shot owns the cut frame, as everywhere in the engine: the outgoing shot's last+// frame on screen is CUT - 1, and that frame is its fastest. The step a viewer sees into CUT - 1 and+// the step they see out of CUT are the same size.+// Everything is a pure function of its arguments. Distances are in the units of the thing they+// are added to (world units for a camera's look), speeds in those units per frame.+import type { P } from "./core";+import { clamp, ramp } from "./launchKit";++export type Ease = (t: number) => number;+/** Slow start, fastest at the end: the curve of a move that leaves. */+export const easeIn: Ease = (t) => { const c = clamp(t); return c * c * c; };+/** Fastest at the start, zero slope at the end: the curve of a move that arrives. Its mirror image. */+export const easeOut: Ease = (t) => 1 - easeIn(1 - t);++/** Speed on the last frame of a move of `dist` over `frames` (its fastest, on easeIn). */+export const exitSpeed = (dist: number, frames: number, ease: Ease = easeIn) => dist * (ease(1) - ease(1 - 1 / frames));+/** How far an arriving move over `frames` must travel to start at `speed` per frame. */+export const entryDistance = (speed: number, frames: number, ease: Ease = easeOut) => speed / (ease(1 / frames) - ease(0));++export type MatchedMove = {+ speed: number; // per frame, on both sides of the cut+ entryDist: number; // how far out the incoming shot starts+ /** What to add to the outgoing camera's look: 0 until the exit begins, `exitDist` along `dir` on its last frame, `cut - 1`. */+ out: (local: number, cut: number) => P;+ /** What to add to the incoming camera's look: `entryDist` short of rest at the cut, 0 from `entryF` frames after it. */+ in: (local: number, cut: number) => P;+};+/** A cut hidden in travel. `dir` is the direction of travel in radians (0 is +x); the two sides share it and the speed. */+export const matchedMove = (o: { dir?: number; exitDist: number; exitF: number; entryF: number }): MatchedMove => {+ if (!(o.exitF >= 2) || !(o.entryF >= 2) || !Number.isFinite(o.exitF) || !Number.isFinite(o.entryF)) throw new Error(`matchedMove: an exit and an entry need at least 2 frames each (got ${o.exitF} and ${o.entryF})`);+ if (!Number.isFinite(o.exitDist) || !Number.isFinite(o.dir ?? 0)) throw new Error(`matchedMove: exitDist and dir must be numbers (got ${o.exitDist} and ${o.dir})`);+ const ux = Math.cos(o.dir ?? 0), uy = Math.sin(o.dir ?? 0), speed = exitSpeed(o.exitDist, o.exitF), entryDist = entryDistance(speed, o.entryF);+ return {+ speed, entryDist,+ out: (local, cut) => { const d = o.exitDist * easeIn(ramp(local, cut - 1 - o.exitF, cut - 1)); return [ux * d, uy * d]; },+ in: (local, cut) => { const d = -entryDist * (1 - easeOut(ramp(local, cut, cut + o.entryF))); return [ux * d, uy * d]; },+ };+};++/** The smallest an incoming shot may open at, as a share of its resting size. */+export const MIN_ZOOM_FROM = 0.4;+export type MatchedZoom = {+ rate: number; // change of log(zoom) per frame, on both sides of the cut+ from: number; // the scale the incoming shot opens at, relative to its rest+ /** Multiply the outgoing camera's zoom by this: 1 until the exit begins, `push` on its last frame, `cut - 1`. */+ out: (local: number, cut: number) => number;+ /** Multiply the incoming camera's zoom by this: `from` at the cut, 1 from `entryF` frames after it. */+ in: (local: number, cut: number) => number;+};+/** A flight through the cut: the outgoing shot is pushed into, the incoming one opens already growing at the same rate. A zoom is a ratio, so both run in log space. */+export const matchedZoom = (o: { push?: number; exitF: number; entryF: number }): MatchedZoom => {+ const push = o.push ?? 1.2;+ if (!(push > 1)) throw new Error(`matchedZoom: push is how far the camera goes in, above 1 (got ${push})`);+ if (!(o.exitF >= 2) || !(o.entryF >= 2) || !Number.isFinite(o.exitF) || !Number.isFinite(o.entryF)) throw new Error(`matchedZoom: an exit and an entry need at least 2 frames each (got ${o.exitF} and ${o.entryF})`);+ const lp = Math.log(push), rate = exitSpeed(lp, o.exitF), lf = -entryDistance(rate, o.entryF);+ // the incoming shot opens small and has to be painted that much wider than the frame: under 0.4 no scene is+ if (!(Math.exp(lf) >= MIN_ZOOM_FROM)) throw new Error(`matchedZoom: the incoming shot would open at ${Math.exp(lf).toFixed(2)} of its size (the least is ${MIN_ZOOM_FROM}): push less, lengthen the exit or shorten the entry`);+ return {+ rate, from: Math.exp(lf),+ out: (local, cut) => Math.exp(lp * easeIn(ramp(local, cut - 1 - o.exitF, cut - 1))),+ in: (local, cut) => Math.exp(lf * (1 - easeOut(ramp(local, cut, cut + o.entryF)))),+ };+};++/** Per-frame velocity of anything that moves, at frame f: where it is, less where it was. */+export const velocityAt = (pos: (f: number) => P, f: number): P => { const a = pos(f - 1), b = pos(f); return [b[0] - a[0], b[1] - a[1]]; };+/** The fastest an element should cross the frame, in screen px per frame: two and a half frame widths a second. Past it blur stops reading as motion and shows as a streak with stepped copies. */+export const speedCeiling = (W: number, fps: number) => (2.5 * W) / fps;++export type SeamFinding = { level: "warn" | "error"; msg: string; fix: string };+/**+ * Does motion carry across a cut? `a` is the screen velocity of the outgoing shot's last step on screen+ * (into frame cut - 1), `b` of the incoming shot's first (out of frame cut), in screen px per frame.+ * Empty when the seam holds. A turn of more than 30 degrees counts as a turn.+ */+export const checkSeam = (a: P, b: P, o: { W: number; fps: number; rest?: number }): SeamFinding[] => {+ if (![...a, ...b, o.W, o.fps].every(Number.isFinite) || !(o.W > 0) || !(o.fps > 0)) throw new Error(`checkSeam: velocities, W and fps must be numbers, W and fps above 0 (got [${a}], [${b}], W ${o.W}, fps ${o.fps})`);+ const out: SeamFinding[] = [], va = Math.hypot(a[0], a[1]), vb = Math.hypot(b[0], b[1]), rest = o.rest ?? 0.5, top = speedCeiling(o.W, o.fps), r1 = (v: number) => v.toFixed(1);+ if (va <= rest && vb <= rest) return out; // both at rest: a plain cut, judged by what it matches, not by this+ if (va <= rest || vb <= rest) out.push({ level: "error", msg: `one side of the cut is at rest and the other is moving (${r1(va)} then ${r1(vb)} px a frame): it reads as a jerk`, fix: "bring both sides to rest, or open the incoming shot at the outgoing speed (matchedMove)" });+ else {+ if ((a[0] * b[0] + a[1] * b[1]) / (va * vb) < Math.cos(Math.PI / 6)) out.push({ level: "error", msg: "the direction of travel turns at the cut", fix: "keep one screen direction across the seam" });+ const ratio = vb / va;+ if (ratio < 0.7 || ratio > 1.4) out.push({ level: "warn", msg: `the speed ${ratio < 1 ? "drops" : "jumps"} at the cut (${r1(va)} then ${r1(vb)} px a frame)`, fix: "size the entry with entryDistance(exit speed, entry frames)" });+ }+ if (Math.max(va, vb) > top) out.push({ level: "warn", msg: `${r1(Math.max(va, vb))} px a frame is past what blur can carry at this size (about ${r1(top)})`, fix: "shorten the travel and hide the rest behind the cut, or make it a cut on the beat" });+ return out;+};++/** The seams a film plans, in order. `cut` is a plain or matched cut; `signature` marks the film's own move. */+export type PlannedSeam = { type: string; cut?: boolean; signature?: boolean };+/** A designed seam used a third time has turned into a preset. Cuts are exempt; the signature move gets three (open, middle, close). */+export const checkSeamPlan = (plan: PlannedSeam[]): SeamFinding[] => {+ const out: SeamFinding[] = [], n = new Map<string, { count: number; sig: boolean }>();+ for (const s of plan) { if (s.cut) continue; const type = s.type.trim().toLowerCase(), e = n.get(type) ?? { count: 0, sig: false }; e.count++; e.sig ||= !!s.signature; n.set(type, e); }+ const sigs = [...n].filter(([, e]) => e.sig);+ if (sigs.length > 1) out.push({ level: "warn", msg: `${sigs.length} signature moves (${sigs.map(([t]) => t).join(", ")})`, fix: "a film has one move that is its own" });+ for (const [type, e] of n) { const max = e.sig ? 3 : 2; if (e.count > max) out.push({ level: "warn", msg: `"${type}" is used ${e.count} times`, fix: e.sig ? "the signature move belongs at the open, the middle and the close" : "use it for the two seams that matter most and give the others a seam of their own" }); }+ return out;+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRun.ts b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRun.tsnew file mode 100644index 0000000..0a471e6--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRun.ts@@ -0,0 +1,4 @@+import { cheetahRun } from "../canvas-core/cheetahRun";+import { mountFilm } from "./page";++mountFilm(cheetahRun);diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRunSigned.ts b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRunSigned.tsnew file mode 100644index 0000000..b45360e--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-cheetahRunSigned.ts@@ -0,0 +1,4 @@+import { cheetahRunSigned } from "../canvas-core/cheetahRunSigned";+import { mountFilm } from "./page";++mountFilm(cheetahRunSigned);diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/arc.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/arc.test.tsnew file mode 100644index 0000000..b6a22d3--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/test/arc.test.ts@@ -0,0 +1,42 @@+// ARC TESTS. src/canvas-core/music/arc.ts reads the shape of a finished score from its loudness+// over time. Built signals with a known shape go in; the numbers and the findings must say so.+// node tools/test.mjs arc+import { arcReport, arcText } from "../src/canvas-core/music/arc";++export const name = "arc";+export const run = (ok: (cond: boolean, label: string) => void) => {+ const SR = 48000;+ // a steady tone whose level follows `db(t)`: loudness then tracks the envelope and nothing else+ const tone = (seconds: number, db: (t: number) => number) => { const n = Math.round(seconds * SR), x = new Float32Array(n); for (let i = 0; i < n; i++) { const t = i / SR; x[i] = Math.pow(10, db(t) / 20) * Math.sin(2 * Math.PI * 997 * t); } return [x, x]; };+ const has = (r: { findings: { msg: string }[] }, s: string) => r.findings.some((f) => f.msg.includes(s));++ // 1. a shaped piece: soft way in, a body, one high point on the payoff, an ending that drops away+ const shaped = arcReport(tone(24, (t) => (t < 2.5 ? -30 : t < 9 ? -22 : t < 12 ? -16 : t < 20 ? -22 : t < 22 ? -26 : -40)), SR, { payoffS: 10.5 });+ ok(shaped.peakS > 9 && shaped.peakS < 12, `the loudest moment is found inside the loud section (${shaped.peakS.toFixed(1)} s)`);+ ok(Math.abs(shaped.peakOverMedian - 6) < 0.6 && Math.abs(shaped.introUnderBody - 8) < 1, `the peak reads 6 LU over the body and the way in 8 LU under it (${shaped.peakOverMedian.toFixed(1)}, ${shaped.introUnderBody.toFixed(1)})`);+ ok(shaped.endUnderPeak > 20 && shaped.findings.length === 0, `a shaped piece has nothing to answer (the end sits ${shaped.endUnderPeak.toFixed(0)} LU under the peak)`);+ ok(arcText(shaped).includes("the shape holds") && arcText(shaped).startsWith("ARC"), "the report says so in one line");++ // 2. each way a score wanders is named+ const flat = arcReport(tone(24, () => -20), SR);+ ok(has(flat, "nothing is the high point") && has(flat, "little contrast"), "one level from start to finish: no high point, no contrast");+ ok(has(arcReport(tone(24, (t) => (t < 20 ? -24 : -14)), SR), "the ending out-shouts"), "the loudest moment in the last fifth is flagged");+ ok(has(arcReport(tone(24, (t) => (t < 2.5 ? -14 : t < 12 ? -22 : t < 14 ? -17 : t < 22 ? -22 : -40)), SR), "nothing left to build to"), "opening over the body's level is flagged");+ ok(has(arcReport(tone(24, (t) => (t < 2.5 ? -50 : t < 12 ? -22 : t < 14 ? -16 : t < 22 ? -22 : -40)), SR), "nothing happening yet"), "a first 2.5 s far under the rest is flagged");+ ok(has(arcReport(tone(24, (t) => (t < 2.5 ? -30 : t < 9 ? -22 : t < 12 ? -16 : -19)), SR), "only 3.0 LU under"), "an ending that barely comes down is flagged");+ ok(has(arcReport(tone(24, (t) => (t < 2.5 ? -30 : t < 9 ? -22 : t < 12 ? -16 : t < 22 ? -22 : -40)), SR, { payoffS: 18 }), "the picture pays off at 18.0 s"), "a high point away from the picture's payoff is flagged");++ // 3. a loop has no beginning and no end: only its seam and its contrast are read+ const loop = arcReport(tone(12, (t) => (t < 6 ? -24 : -18)), SR, { loop: true });+ ok(has(loop, "where the loop comes round") && !has(loop, "out-shouts") && !has(loop, "build to"), `a loop that ends 6 LU over where it starts is flagged at the seam only (${loop.seamJump.toFixed(1)} LU)`);+ ok(arcReport(tone(12, (t) => (t < 4 ? -24 : t < 8 ? -18 : -24)), SR, { loop: true }).findings.length === 0, "a loop that swells in the middle and returns has nothing to answer");+ // a phrase that ends into a quiet bar: the join is no bigger a step than the piece makes inside itself+ const breath = arcReport(tone(12, (t) => (t < 3 ? -30 : t < 6 ? -18 : t < 9 ? -30 : -21)), SR, { loop: true }); ok(breath.seamJump > 3 && breath.insideJump >= breath.seamJump && !has(breath, "comes round"), `a loop whose join steps ${breath.seamJump.toFixed(1)} LU is left alone when it steps ${breath.insideJump.toFixed(1)} LU inside too`);++ // 4. short pieces and silence do not crash or nag+ ok(arcReport(tone(3, () => -20), SR).findings.length === 0, "a three-second sting is not asked for an arc");+ const quiet = arcReport([new Float32Array(SR * 2), new Float32Array(SR * 2)], SR); ok(Number.isFinite(quiet.peakS) && quiet.findings.length === 0 && !arcText(quiet).includes("NaN"), "two seconds of silence give finite numbers and no findings");+ const long = arcReport([new Float32Array(SR * 24), new Float32Array(SR * 24)], SR), longLoop = arcReport([new Float32Array(SR * 24)], SR, { loop: true }); ok(long.findings.length === 0 && longLoop.findings.length === 0 && !arcText(long).includes("NaN"), "24 seconds of silence are not told they lack a high point");+ let threw = false; try { arcReport([], SR); } catch { threw = true; } ok(threw, "no channels at all is refused with a message");+ ok(!arcText(arcReport(tone(2, () => -20), SR)).includes("NaN"), "a two-second piece prints no NaN");+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/cheetahRig.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/cheetahRig.test.tsnew file mode 100644index 0000000..1448dd8--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/test/cheetahRig.test.ts@@ -0,0 +1,48 @@+// CHEETAH RIG TESTS. The skeleton (src/canvas-core/cheetahRig.ts) is pure arithmetic, so the things+// that make her move like an animal and not like rubber are held to numbers here: node tools/test.mjs+import { BOW, CROUCH, fk, FORE_BONES, gallopRig, gallopY, HIND_BONES, lowest, mixRig, settle, SKID, STAND, TAIL_BONES } from "../src/canvas-core/cheetahRig";+import type { P } from "../src/canvas-core/core";++export const name = "cheetahRig";+export const run = (ok: (cond: boolean, label: string) => void) => {+ const dist = (a: P, b: P) => Math.hypot(a[0] - b[0], a[1] - b[1]);+ const bones = (pts: P[], B: number[]) => Math.max(...B.map((b, i) => Math.abs(dist(pts[i], pts[i + 1]) - b)));++ // 1. bones never change length, in the stride or in a blend between two held poses+ let worst = 0, finite = true;+ for (let i = 0; i < 400; i++) {+ const q = fk(i % 2 ? gallopRig(i / 400) : mixRig(STAND, BOW, i / 400), 0, 0, 0);+ worst = Math.max(worst, bones(q.foreN, FORE_BONES), bones(q.foreF, FORE_BONES), bones(q.hindN, HIND_BONES), bones(q.hindF, HIND_BONES), bones(q.tail, TAIL_BONES));+ for (const pts of [q.spine, q.tail, q.foreN, q.foreF, q.hindN, q.hindF]) for (const p of pts) if (!Number.isFinite(p[0]) || !Number.isFinite(p[1])) finite = false;+ }+ ok(worst < 1e-6, `every leg and tail bone keeps its length (worst error ${worst.toExponential(1)} px)`);+ ok(finite, "every point is finite through the stride and the blends");++ // 2. the stride is a loop: phase 1 is phase 0, and no joint jumps between neighbouring frames+ const a = fk(gallopRig(0), 0, gallopY(0), 0), b = fk(gallopRig(1), 0, gallopY(1), 0);+ ok(dist(a.foreN[4], b.foreN[4]) < 1e-6 && dist(a.hindN[4], b.hindN[4]) < 1e-6 && dist(a.tail[5], b.tail[5]) < 1e-6, "the stride closes: phase 1 lands exactly on phase 0");+ let jump = 0; const at = (ph: number) => fk(gallopRig(ph), 0, gallopY(ph), 0);+ for (let i = 0; i < 300; i++) { const p = at(i / 300), q = at((i + 1) / 300); for (const k of ["foreN", "foreF", "hindN", "hindF"] as const) jump = Math.max(jump, dist(p[k][4], q[k][4])); }+ ok(jump < 12, `no foot jumps within the stride (largest move in 1/300 of a stride: ${jump.toFixed(1)} px)`);++ // 3. she never goes through the ground, and she really leaves it twice a stride+ const lowAt = (ph: number) => { const l = lowest(fk(gallopRig(ph), 0, gallopY(ph), 0)); return Math.max(l.fore, l.hind); };+ let sink = -Infinity, flights = 0, wasAir = lowAt(299 / 300) < -12; // the stride is a loop: start from where the last one ended+ for (let i = 0; i < 300; i++) { const low = lowAt(i / 300); sink = Math.max(sink, low); const air = low < -12; if (air && !wasAir) flights++; wasAir = air; }+ ok(sink < 0.01, `no foot below the ground in the stride (lowest ${sink.toFixed(2)} px)`);+ ok(flights === 2, `two flight phases a stride, the extended and the gathered (found ${flights})`);++ // 4. the spine folds and opens: the hips come well forward under her in the gathered phase+ const span = (ph: number) => { const q = at(ph); return q.spine[6][0] - q.spine[1][0]; };+ ok(span(0) - span(0.52) > 20, `shoulder-to-hip distance closes in the gathered phase (${span(0).toFixed(0)} px extended, ${span(0.52).toFixed(0)} px gathered)`);+ const g = at(0.56); ok(Math.max(g.hindN[4][0], g.hindF[4][0]) > Math.min(g.foreN[4][0], g.foreF[4][0]), "gathered, a hind foot reaches past a forefoot");++ // 5. the head rides level while the body works under it+ let hi = Infinity, lo = -Infinity, hipHi = Infinity, hipLo = -Infinity;+ for (let i = 0; i < 100; i++) { const q = at(i / 100); hi = Math.min(hi, q.spine[9][1]); lo = Math.max(lo, q.spine[9][1]); hipHi = Math.min(hipHi, q.spine[1][1]); hipLo = Math.max(hipLo, q.spine[1][1]); }+ ok(lo - hi < 4 && hipLo - hipHi > 30, `the head moves ${(lo - hi).toFixed(1)} px through a stride while the hips move ${(hipLo - hipHi).toFixed(0)} px`);++ // 6. a held pose stands on all four feet+ for (const [n, r] of Object.entries({ STAND, BOW, CROUCH, SKID })) { const s = settle(r), l = lowest(fk(s.rig, 0, s.y, 0)); ok(Math.abs(l.fore) < 2 && Math.abs(l.hind) < 2, `${n} settles with fore and hind feet on the ground (${l.fore.toFixed(1)}, ${l.hind.toFixed(1)} px)`); }+ const s = settle(BOW), q = fk(s.rig, 0, s.y, 0); ok(q.spine[1][1] < q.spine[6][1] - 120, "in the bow the hips stay high above the shoulders");+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/sampler.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/sampler.test.tsindex e77b6c8..91eb8d6 100644--- a/plugins/anidoodle/skills/anidoodle/engine/test/sampler.test.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/test/sampler.test.ts@@ -1,5 +1,5 @@// Tiny synthetic recordings: pitch, dynamics, dampers, bank routing and cache identity, no files.-import { registerBank, bankFor, clearBanks, samplerVoice, sampleZones, sampleCutoff, sampleGain, bankIdentity, type SampleBank, type SampleZone } from "../src/canvas-core/music/sampler";+import { registerBank, bankFor, clearBanks, samplerVoice, sampleZones, sampleCutoff, sampleGain, bankIdentity, type SampleBank, type SampleZone, pinnedPitch } from "../src/canvas-core/music/sampler";import { renderPiece, voiceJobs, runVoiceJob, voiceJobKey, calibrateBank } from "../src/canvas-core/music/render";import { nocturne } from "../src/canvas-core/music/pieces/nocturne";import { marimbaCurious } from "../src/canvas-core/music/pieces/families";@@ -191,4 +191,9 @@ export const run = (ok: (cond: boolean, label: string) => void) => {const sustained = bank(); sustained.entry.kind = "sustained";ok(throws(() => registerBank("strings", sustained), /sustained zone without a loop/), "sustained zones without loops are rejected");} finally { clearBanks(); }++ // a drum pinned to a note lands inside what was recorded, on the same note name+ ok(pinnedPitch(31, [37, 59]) === 43 && pinnedPitch(60, [37, 59]) === 48 && pinnedPitch(43, [37, 59]) === 43, "a pinned pitch moves by octaves into the recorded range (G1 to G2, C4 to C3) and stays put when it is inside");+ ok([24, 31, 38, 60, 72, 90].every((p) => { const q = pinnedPitch(p, [37, 59]); return q >= 37 && q <= 59 && (q - p) % 12 === 0; }), "every pinned pitch stays in range and keeps its note name");+ { let threw = 0; for (const bad of [NaN, Infinity, -Infinity]) try { pinnedPitch(bad, [37, 59]); } catch { threw++; } ok(threw === 3, "a pinned pitch that is not a number is refused, never looped on"); }};diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/seams.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/seams.test.tsnew file mode 100644index 0000000..35396a4--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/test/seams.test.ts@@ -0,0 +1,61 @@+// SEAM TESTS. src/canvas-core/seams.ts is arithmetic, so the claim it makes (motion carries across+// the cut at one speed, in one direction, and comes to rest exactly) is held to numbers here.+// node tools/test.mjs seams+import { checkSeam, checkSeamPlan, easeIn, easeOut, entryDistance, exitSpeed, matchedMove, matchedZoom, MIN_ZOOM_FROM, speedCeiling, velocityAt } from "../src/canvas-core/seams";+import type { P } from "../src/canvas-core/core";++export const name = "seams";+export const run = (ok: (cond: boolean, label: string) => void) => {+ const near = (a: number, b: number, eps = 1e-9) => Math.abs(a - b) <= eps;+ const throws = (fn: () => unknown) => { try { fn(); return false; } catch { return true; } };+ const CUT = 100;++ // 1. the two curves are mirror images, and the helpers invert each other+ ok([0, 0.2, 0.5, 0.9, 1].every((t) => near(easeOut(t), 1 - easeIn(1 - t))) && easeIn(0) === 0 && easeOut(1) === 1, "easeOut is easeIn mirrored; both run 0 to 1");+ ok(near(entryDistance(exitSpeed(300, 24), 24), 300), "an entry as long as its exit travels the same distance");+ ok(exitSpeed(300, 12) > exitSpeed(300, 24), "a shorter exit over the same distance leaves faster");++ // 2. a matched move: one speed on both sides of the cut, in one direction, at rest at both ends+ for (const dir of [0, Math.PI, 0.6, -Math.PI / 2]) {+ const m = matchedMove({ dir, exitDist: 260, exitF: 12, entryF: 40 });+ // what is on screen: the outgoing shot up to CUT - 1, the incoming one from CUT. Each side's own step, as a viewer sees it+ const a = velocityAt((f) => m.out(f, CUT), CUT - 1), b = velocityAt((f) => m.in(f, CUT), CUT + 1), va = Math.hypot(a[0], a[1]), vb = Math.hypot(b[0], b[1]);+ ok(near(va, m.speed, 1e-6) && near(vb, m.speed, 1e-6), `dir ${dir.toFixed(2)}: ${va.toFixed(2)} px a frame into the cut, ${vb.toFixed(2)} out of it`);+ ok(near(Math.atan2(a[1], a[0]), Math.atan2(b[1], b[0]), 1e-6), `dir ${dir.toFixed(2)}: the direction of travel is the same on both sides`);+ ok(checkSeam(a, b, { W: 1920, fps: 30 }).length === 0, `dir ${dir.toFixed(2)}: checkSeam has nothing to say`);+ const s = m.out(CUT - 13, CUT), e = m.in(CUT + 40, CUT), late = m.in(CUT + 400, CUT), early = m.out(0, CUT), end = m.out(CUT - 1, CUT);+ ok(near(Math.hypot(s[0], s[1]), 0) && near(Math.hypot(early[0], early[1]), 0) && near(Math.hypot(e[0], e[1]), 0) && near(Math.hypot(late[0], late[1]), 0), `dir ${dir.toFixed(2)}: at rest before the exit and from the end of the entry on`);+ ok(near(Math.hypot(end[0], end[1]), 260, 1e-9), `dir ${dir.toFixed(2)}: the whole exit is travelled by the outgoing shot's last frame on screen, CUT - 1`);+ const last = velocityAt((f) => m.in(f, CUT), CUT + 40); ok(Math.hypot(last[0], last[1]) < m.speed * 0.01, `dir ${dir.toFixed(2)}: it lands with no speed left`);+ }+ let mono = true; { const m = matchedMove({ exitDist: 260, exitF: 12, entryF: 40 }); for (let f = CUT - 13; f < CUT + 40; f++) if (f !== CUT - 1 && (f < CUT - 1 ? m.out(f + 1, CUT)[0] < m.out(f, CUT)[0] : m.in(f + 1, CUT)[0] < m.in(f, CUT)[0])) mono = false; }+ ok(mono, "neither side ever travels backwards");+ ok(throws(() => matchedMove({ exitDist: 100, exitF: 1, entryF: 20 })) && throws(() => matchedMove({ exitDist: 100, exitF: 10, entryF: 0 })) && throws(() => matchedMove({ exitDist: NaN, exitF: 10, entryF: 20 })) && throws(() => matchedMove({ exitDist: 100, exitF: Infinity, entryF: 20 })), "a one-frame exit, a zero-frame entry, an endless exit or a distance that is not a number is refused");+ // the card's own numbers at 30 fps: a 0.2 s exit and a 0.5 s entry, measured on the frames a viewer sees+ { const m = matchedMove({ exitDist: 260, exitF: 6, entryF: 15 }), a = velocityAt((f) => m.out(f, CUT), CUT - 1), b = velocityAt((f) => m.in(f, CUT), CUT + 1); ok(near(a[0], b[0], 1e-6) && checkSeam(a, b, { W: 1920, fps: 30 }).some((x) => x.msg.includes("past what blur")) === (a[0] > speedCeiling(1920, 30)), `a 6-frame exit and a 15-frame entry: ${a[0].toFixed(1)} px a frame on both displayed sides`); }++ // 3. a matched zoom: the same rate of growth on both sides, in log space, landing on 1+ const z = matchedZoom({ push: 1.2, exitF: 6, entryF: 15 });+ ok(near(z.out(CUT - 7, CUT), 1) && near(z.out(CUT - 1, CUT), 1.2) && near(z.in(CUT, CUT), z.from) && near(z.in(CUT + 15, CUT), 1) && near(z.in(CUT + 99, CUT), 1), "zoom: 1 before, the push at the cut, `from` after it, 1 at rest");+ const rOut = Math.log(z.out(CUT - 1, CUT) / z.out(CUT - 2, CUT)), rIn = Math.log(z.in(CUT + 1, CUT) / z.in(CUT, CUT));+ ok(near(rOut, z.rate, 1e-9) && near(rIn, z.rate, 1e-9), `zoom: growing ${(100 * (Math.exp(rOut) - 1)).toFixed(1)}% a frame into the cut and ${(100 * (Math.exp(rIn) - 1)).toFixed(1)}% out of it`);+ ok(z.from > 0.4 && z.from < 1, `zoom: the incoming shot opens at ${z.from.toFixed(2)} of its size, inside what a scene can be drawn at`);+ ok(throws(() => matchedZoom({ push: 0.9, exitF: 6, entryF: 15 })) && throws(() => matchedZoom({ exitF: 1, entryF: 15 })), "a push of 1 or less, or a one-frame exit, is refused");+ ok(throws(() => matchedZoom({ push: 2, exitF: 6, entryF: 30 })) && throws(() => matchedZoom({ push: 4, exitF: 2, entryF: 60 })) && matchedZoom({ push: 1.2, exitF: 6, entryF: 15 }).from >= MIN_ZOOM_FROM, `a zoom whose incoming shot would open under ${MIN_ZOOM_FROM} of its size is refused`);++ // 4. checkSeam names each way a cut between moving shots goes wrong+ const o = { W: 1920, fps: 30 }, has = (f: { msg: string }[], s: string) => f.some((x) => x.msg.includes(s));+ ok(checkSeam([0, 0], [0.2, 0], o).length === 0, "two shots at rest: nothing to match");+ ok(has(checkSeam([40, 0], [0, 0], o), "at rest") && has(checkSeam([0, 0], [40, 0], o), "at rest"), "one side at rest, one moving: flagged");+ ok(has(checkSeam([40, 0], [-40, 0], o), "turns") && has(checkSeam([40, 0], [0, 40], o), "turns") && has(checkSeam([40, 0], [30, 26], o), "turns") && !has(checkSeam([40, 0], [39, 9], o), "turns"), "a reversal, a right angle and a 41 degree turn are flagged; 13 degrees is not");+ ok(throws(() => checkSeam([NaN, 0], [40, 0], o)) && throws(() => checkSeam([40, 0], [40, 0], { W: 1920, fps: 0 })) && throws(() => checkSeam([40, 0], [40, 0], { W: undefined as unknown as number, fps: 30 })), "a velocity that is not a number, or a missing size or frame rate, is refused, never passed");+ ok(has(checkSeam([40, 0], [20, 0], o), "drops") && has(checkSeam([40, 0], [80, 0], o), "jumps") && checkSeam([40, 0], [46, 0], o).length === 0, "half or double the speed is flagged; 15% off is not");+ ok(near(speedCeiling(1920, 60), 80) && has(checkSeam([200, 0], [200, 0], o), "past what blur"), "the ceiling is 2.5 widths a second (80 px a frame at 1920 and 60 fps), and a move past it is flagged");++ // 5. the seam plan: a designed seam twice, the signature three times, cuts as often as wanted+ const p = (type: string, n: number, x: object = {}) => Array.from({ length: n }, () => ({ type, ...x }));+ ok(checkSeamPlan([...p("iris", 2), ...p("matched cut", 6, { cut: true }), ...p("ink bloom", 3, { signature: true })]).length === 0, "two irises, six cuts and the signature three times pass");+ ok(has(checkSeamPlan(p("iris", 3)), '"iris" is used 3 times') && has(checkSeamPlan(p("ink bloom", 4, { signature: true })), "4 times"), "a third iris and a fourth signature are flagged");+ ok(has(checkSeamPlan([...p("bloom", 1, { signature: true }), ...p("wipe", 1, { signature: true })]), "2 signature moves"), "two signature moves are flagged");+ ok(has(checkSeamPlan([{ type: "Iris" }, { type: "iris" }, { type: " iris " }]), "3 times"), "a seam is counted whatever its capitals and spaces");+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/deck.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/deck.mjsnew file mode 100644index 0000000..7288187--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/deck.mjs@@ -0,0 +1,83 @@+// DECK. Left to choose, a film reaches for the first move it remembers: the same push-in, the same+// bloom, the same end card. This deals from references/motion-deck.json instead, weighted toward+// what fits the film (its kind, its energy) and toward the quiet workhorses, and prints each card+// with its numbers. The seed is printed, so a deal can be repeated and written into the brief.+// A card is a prompt, never an order: keep it, adapt it to the subject and medium, or drop it and+// say why. Styles and motion are a grammar to compose from (references/motion-grammar.md).+// node tools/deck.mjs deal --kind story --energy high --seconds 27 [--seed 7] [--avoid id,id] [--json]+// node tools/deck.mjs deal --cat seam --n 3 --kind launch # three seams only+// node tools/deck.mjs list [--cat camera] # every card, one line each+// node tools/deck.mjs test # the deck and the dealer hold their own rules+// Weights: role (workhorse 3, accent 2, signature 1) x energy fit (same 1, "any" 0.7, other 0.25).+// A deal has one opening, one close, at most one signature card, and no card twice.+import { existsSync, readFileSync, readdirSync } from "node:fs";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";++const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", ".."), DECK = JSON.parse(readFileSync(join(ROOT, "references", "motion-deck.json"), "utf8"));+const CATS = ["open", "seam", "camera", "reveal", "type", "acting", "emphasis", "close"], MIDDLE = CATS.filter((c) => c !== "open" && c !== "close");+const KINDS = ["story", "drawing", "loop", "explainer", "infographic", "launch", "interactive"], ENERGY = ["calm", "medium", "high"], ROLE_W = { workhorse: 3, accent: 2, signature: 1 };+// mulberry32: the deal is a pure function of the seed+const rand = (seed) => { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; };++export const fits = (m, kind) => !kind || m.kinds.includes("any") || m.kinds.includes(kind);+export const weight = (m, energy) => ROLE_W[m.role] * (!energy || m.energy === energy ? 1 : m.energy === "any" ? 0.7 : 0.25);+export const count = (seconds) => Math.max(4, Math.min(12, Math.round(seconds / 4))); // a short film still gets an opening, a close and two more to choose from+/** A deal: one opening, one close, the rest spread over the middle categories in a shuffled order. */+export const deal = ({ kind, energy, seconds = 20, seed = 1, n, cat, avoid = [] } = {}) => {+ const r = rand(seed), skip = new Set(avoid), picked = [];+ const pool = (c) => DECK.moves.filter((m) => m.cat === c && fits(m, kind) && !skip.has(m.id) && !picked.includes(m) && !(m.role === "signature" && picked.some((p) => p.role === "signature")));+ const draw = (c) => { const p = pool(c); if (!p.length) return false; let x = r() * p.reduce((s, m) => s + weight(m, energy), 0); for (const m of p) { x -= weight(m, energy); if (x <= 0) { picked.push(m); return true; } } picked.push(p[p.length - 1]); return true; };+ if (cat) { for (let i = 0; i < (n ?? 3); i++) if (!draw(cat)) break; return picked; }+ const total = n ?? count(seconds), order = MIDDLE.map((c) => [r(), c]).sort((a, b) => a[0] - b[0]).map((x) => x[1]);+ draw("open");+ for (let i = 0, dry = 0; picked.length < total - 1 && dry < order.length; i++) dry = draw(order[i % order.length]) ? 0 : dry + 1;+ draw("close");+ return picked.sort((a, b) => CATS.indexOf(a.cat) - CATS.indexOf(b.cat));+};++const card = (m) => ` ${m.id} [${m.cat} · ${m.role} · ${m.energy}]\n ${m.move}\n build: ${m.build}\n not when: ${m.not}`;+const selfTest = () => {+ let fails = 0; const say = (ok, label) => { if (!ok) fails++; console.log(` ${ok ? "PASS" : "FAIL"} ${label}`); };+ const M = DECK.moves, ids = M.map((m) => m.id);+ say(new Set(ids).size === ids.length, `${ids.length} cards, every id unique`);+ say(M.every((m) => CATS.includes(m.cat) && ROLE_W[m.role] && [...ENERGY, "any"].includes(m.energy) && m.kinds.length && m.kinds.every((k) => k === "any" || KINDS.includes(k))), "every card has a known category, role, energy and kind");+ say(M.every((m) => m.move.length > 40 && m.build.length > 20 && m.not.length > 15), "every card says what happens, how it is built, and when not to use it");+ say(CATS.every((c) => M.filter((m) => m.cat === c).length >= 3), "every category has at least three cards to choose between");+ // every file a card cites exists: a card that points at nothing is a rumour+ const have = new Set(); const walk = (d) => { for (const e of readdirSync(d, { withFileTypes: true })) { if (e.name === "node_modules" || e.name.startsWith(".")) continue; if (e.isDirectory()) walk(join(d, e.name)); else have.add(e.name); } };+ walk(join(ROOT, "references")); walk(join(ROOT, "engine", "src")); walk(join(ROOT, "engine", "tools"));+ const cited = [...new Set(M.flatMap((m) => `${m.build} ${m.not} ${m.move}`.match(/[A-Za-z0-9-]+\.(?:ts|mjs|md)\b/g) ?? []))], missing = cited.filter((f) => !have.has(f));+ say(!missing.length, `all ${cited.length} files the cards cite exist${missing.length ? ` missing: ${missing.join(", ")}` : ""}`);+ say(!/\u2014/.test(JSON.stringify(DECK)), "no em dashes in the deck");+ const key = (d) => d.map((m) => m.id).join(",");+ say(key(deal({ kind: "story", energy: "high", seconds: 27, seed: 7 })) === key(deal({ kind: "story", energy: "high", seconds: 27, seed: 7 })), "the same seed deals the same hand");+ say(new Set(Array.from({ length: 40 }, (_, s) => key(deal({ kind: "story", energy: "high", seconds: 27, seed: s + 1 })))).size >= 30, "forty seeds deal at least thirty different hands");+ let rules = true, kinds = true, avoided = true, sizes = true;+ for (let s = 1; s <= 300; s++) for (const kind of KINDS) {+ const energy = ENERGY[s % 3], seconds = 6 + (s % 9) * 7, d = deal({ kind, energy, seconds, seed: s, avoid: ["cam-slow-push"] });+ if (d.filter((m) => m.cat === "open").length !== 1 || d.filter((m) => m.cat === "close").length !== 1 || d.filter((m) => m.role === "signature").length > 1 || new Set(d).size !== d.length) rules = false;+ if (!d.every((m) => fits(m, kind))) kinds = false; if (d.some((m) => m.id === "cam-slow-push")) avoided = false; if (d.length > 12 || d.length > count(seconds) || d.length < 3) sizes = false;+ }+ say(rules, "2100 deals: exactly one opening, exactly one close, at most one signature card, no card twice");+ say(kinds, "no deal holds a card its kind of film cannot use"); say(avoided, "an avoided card is never dealt"); say(sizes, "a deal is a card every four seconds, never fewer than three and never more than twelve");+ const tally = (energy) => { let hi = 0, n = 0; for (let s = 1; s <= 400; s++) for (const m of deal({ kind: "story", energy, seconds: 30, seed: s })) { n++; if (m.energy === "high") hi++; } return hi / n; };+ say(tally("high") > tally("calm") * 1.5, `a high-energy film is dealt more high-energy cards than a calm one (${(tally("high") * 100).toFixed(0)}% against ${(tally("calm") * 100).toFixed(0)}%)`);+ say(deal({ cat: "seam", n: 3, kind: "launch", seed: 3 }).every((m) => m.cat === "seam") && deal({ cat: "seam", n: 3, seed: 3 }).length === 3, "--cat deals from one category only");+ console.log(`\nDECK: ${fails ? "FAIL" : "PASS"}`); process.exit(fails ? 1 : 0);+};++if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {+ const die = (m) => { console.error(`deck: ${m}`); process.exit(2); };+ const [cmd, ...args] = process.argv.slice(2), val = (k) => { const i = args.indexOf(k); return i >= 0 ? args[i + 1] : undefined; };+ const num = (k, least, whole) => { if (!args.includes(k)) return undefined; const x = Number(val(k)); if (val(k) === undefined || !Number.isFinite(x) || x < least || (whole && !Number.isInteger(x))) die(`${k} takes ${whole ? "a whole number" : "a number"} of ${least} or more (got ${val(k)})`); return x; };+ if (cmd === "test") selfTest();+ else if (cmd === "list") { const c = val("--cat"); if (c && !CATS.includes(c)) die(`--cat is one of ${CATS.join(", ")}`); for (const m of DECK.moves.filter((m) => !c || m.cat === c)) console.log(`${m.id.padEnd(30)} ${m.cat.padEnd(9)} ${m.role.padEnd(10)} ${m.energy.padEnd(7)} ${m.kinds.join(",")}`); }+ else if (cmd === "deal") {+ const kind = val("--kind"), energy = val("--energy"), c = val("--cat");+ if (kind && !KINDS.includes(kind)) die(`--kind is one of ${KINDS.join(", ")}`); if (energy && !ENERGY.includes(energy)) die(`--energy is one of ${ENERGY.join(", ")}`); if (c && !CATS.includes(c)) die(`--cat is one of ${CATS.join(", ")}`);+ const seed = num("--seed", 0, true) ?? (Date.now() % 100000), o = { kind, energy, seconds: num("--seconds", 1) ?? 20, seed, n: num("--n", c ? 1 : 3, true), cat: c, avoid: (val("--avoid") ?? "").split(",").filter(Boolean) }, d = deal(o);+ if (args.includes("--json")) console.log(JSON.stringify({ ...o, cards: d }, null, 1));+ else { console.log(`DECK seed ${seed}${kind ? ` · ${kind}` : ""}${energy ? ` · ${energy}` : ""}${c ? ` · ${c} only` : ` · ${o.seconds} s`} · ${d.length} cards\n`); console.log(d.map(card).join("\n\n")); console.log(`\nKeep, adapt or drop each card, and say why in the brief. To repeat this deal: --seed ${seed}. To deal the next film a different hand: --avoid ${d.map((m) => m.id).join(",")}`); }+ } else die("usage: deck.mjs deal|list|test (see the header of this file)");+}diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/music.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/music.mjsindex 08c0105..6a8c439 100644--- a/plugins/anidoodle/skills/anidoodle/engine/tools/music.mjs+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/music.mjs@@ -7,7 +7,7 @@// returning either); or the name of a shipped demo (listening references, never a film's score).//// node tools/music.mjs vocab [style] # the style vocabularies: palette, grooves, harmony, melody, arrangement-// node tools/music.mjs check <piece> [--fit --seconds N] # everything: key/mode, warnings, master, ghost/reverb/masking guards, stems, craft, novelty+// node tools/music.mjs check <piece> [--fit --seconds N] [--payoff S] # everything: key/mode, warnings, master, ghost/reverb/masking guards, stems, craft, arc (the shape; S = the second the picture pays off), novelty// node tools/music.mjs craft <piece> [more ...] [--json] # how it is WRITTEN: melody, harmony, rhythm, tension, mood fit (no render, advisory; errors fail)// node tools/music.mjs novelty <piece> [more ...] # vs every shipped piece (and pairwise when several); FAILS above the threshold or on a reused fragment// node tools/music.mjs list # shipped demos and fixtures@@ -232,6 +232,7 @@ const main = async () => {const r = piece.plan.loop ? M.renderLoop(piece, SR, { cache, stems: true }) : M.renderPiece(piece, SR, { seconds, tempo, cache, stems: true }); T("mix"); const g = await pending; // stems: the peak note names the parts that pile upconst ok = [report(M, r, piece, cache, g.bands), printStems(M, piece, tempo, seconds, cache, g.stems)?.ok !== false];T("report + stems"); { const cr = M.craftReport(piece, { centroidHz: M.centroid([r.L, r.R], SR).mean }); console.log(M.craftText(cr)); ok.push(!cr.findings.some((f) => f.level === "error")); } T("craft");+ { const pay = val("--payoff", undefined); if (flag("--payoff") && !(pay >= 0)) { console.error("music: --payoff takes the second the picture pays off, e.g. --payoff 13.5"); process.exit(2); } console.log(M.arcText(M.arcReport([r.L, r.R], SR, { loop: !!piece.plan.loop, payoffS: pay }))); } // the shape of the finished sound: advisory, never fails the checkif (!pc.demo) { const fam = [args[0]]; ok.push(printNovelty(M, args[0], M.novelty(piece, M.DEMOS, fam), "shipped pieces")); }console.log(ok.every(Boolean) ? "CHECK PASS: now a human listens (an mp3 or wav on a page)" : "CHECK FAIL: fix the items above, then run check again");if (!ok.every(Boolean)) process.exitCode = 1; return;diff --git a/plugins/anidoodle/skills/anidoodle/references/motion-deck.json b/plugins/anidoodle/skills/anidoodle/references/motion-deck.jsonnew file mode 100644index 0000000..0c5f196--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/references/motion-deck.json@@ -0,0 +1,181 @@+{+ "about": "The motion deck: moves this engine can already make, each with its numbers. Dealt by engine/tools/deck.mjs so two films do not reach for the same three. A dealt card is a prompt to consider, in the film's own subject and medium: keep it, adapt it, or drop it and say why. Times are seconds, distances are fractions of the frame's width, so every card holds at any size and frame rate.",+ "roles": { "workhorse": "carries a film quietly, safe to use twice", "accent": "noticed when it happens, once or twice", "signature": "can be the one move that is this film's own, used at the open, the middle and the close" },+ "moves": [+ { "id": "open-mid-move", "cat": "open", "role": "workhorse", "energy": "any", "kinds": ["any"],+ "move": "Frame 0 is already composed and already moving: the film opens partway into a camera move or an action, never on a still that then starts.",+ "build": "A path camera whose move began before frame 0 (camera.ts, path: (f) => move(f + lead)), or a cycle opened at phase 0.3, so the first second has travel in it.",+ "not": "A piece that draws itself: there the empty page is the opening." },+ { "id": "open-iris-from-subject", "cat": "open", "role": "accent", "energy": "calm", "kinds": ["story", "loop", "launch", "explainer"],+ "move": "The film opens through a round opening that grows from the thing it is about, 0.5 to 0.8 s, evenly in log space so it does not crawl then snap.",+ "build": "iris(ctx, env, seam(f, 0, len), blank, scene, { center }) in transitions.ts; shape \"blot\" for an inked film.",+ "not": "Centred on nothing. Or when the close also irises and a seam in the middle does: the third one is a preset." },+ { "id": "open-detail-first", "cat": "open", "role": "accent", "energy": "calm", "kinds": ["story", "loop", "drawing"],+ "move": "Open so close on one detail (an eye, a hand, a nib) that the subject is not yet readable, then pull back over 1.5 to 3 s until it is.",+ "build": "Camera keys from zoom 4 to 6 down to 1 with monoZoom: true; divide stroke widths by cam.weight(cam.at(f)) so the close-up reads close, not enlarged (camera.md).",+ "not": "A detail that was not drawn to be seen at that size. Check the first frame at --scale 2." },+ { "id": "open-cold-action", "cat": "open", "role": "accent", "energy": "high", "kinds": ["story", "launch"],+ "move": "No establishing shot: the first frame is the middle of the action, and the wide shot comes second, as the answer to where we are.",+ "build": "Order the shots action, then wide; the score enters on frame 0 with one sound that has a reason.",+ "not": "A calm piece, or a subject the viewer cannot name from the close shot within a second." },++ { "id": "seam-matched-cut", "cat": "seam", "role": "workhorse", "energy": "high", "kinds": ["any"],+ "move": "A hard cut hidden in travel. The outgoing shot accelerates over 0.2 to 0.4 s, its last frame is its fastest, the incoming shot opens at the same speed in the same direction and comes to rest over 0.8 to 1.4 s.",+ "build": "matchedMove({ dir, exitDist, exitF, entryF }) in seams.ts, added to each scene's camera look; hold it with checkSeam. Render with --blur auto.",+ "not": "Either shot has no room to travel, or the two travel different ways. Then both sides come to rest and it is a plain cut on a beat." },+ { "id": "seam-flight-through", "cat": "seam", "role": "accent", "energy": "high", "kinds": ["story", "launch", "explainer"],+ "move": "The camera flies into the outgoing shot and comes out in the next: a push of about 1.2 over 0.2 s, the cut, then the incoming shot growing from about two thirds of its size to rest over 0.5 s.",+ "build": "matchedZoom({ push, exitF, entryF }) in seams.ts multiplies each camera's zoom; the incoming scene must be painted wider than the frame, because it opens small.",+ "not": "The thing flown into is not what the next shot is about. Then it is a zoom laid over a join." },+ { "id": "seam-actor-carries", "cat": "seam", "role": "signature", "energy": "any", "kinds": ["any"],+ "move": "One object crosses the seam untouched while the world changes round it: same screen position, same size, same colour on the last frame of one scene and the first of the next.",+ "build": "Drive it from one function of the absolute frame that both scenes call (relay in motif.ts); checkRelay holds the two sides to 2 px.",+ "not": "The object has no reason to be in the second scene. A mascot that only watches is decoration." },+ { "id": "seam-shape-becomes", "cat": "seam", "role": "signature", "energy": "medium", "kinds": ["any"],+ "move": "A shape in the outgoing picture travels, stretches a little while moving, and becomes a shape of the next picture, landing on it exactly.",+ "build": "handoff({ from, to, t0, t1 }) in morph.ts; coverShape when the target is the whole page; checkShapes at the landing.",+ "not": "The two shapes share nothing the eye can follow (colour, edge, a rough outline). A morph between strangers is a wipe." },+ { "id": "seam-pick-and-grow", "cat": "seam", "role": "accent", "energy": "medium", "kinds": ["launch", "explainer", "story"],+ "move": "One item out of a set is chosen and grows until it is the next scene; the next scene's first frame is framed exactly like the item.",+ "build": "A camera punch-in that does not come back (launchGallery.ts); frame the incoming scene's first frame from the card's box.",+ "not": "The set was only built to be left." },+ { "id": "seam-cover-from-inside", "cat": "seam", "role": "accent", "energy": "medium", "kinds": ["launch", "story", "explainer"],+ "move": "Something already in the scene grows until it covers the frame, and when it clears the next scene is there. The next scene is complete underneath on every frame.",+ "build": "coverShape (morph.ts) on the scene's own shape, or the bloom in launchCut.ts; close it on the next picture's focal point.",+ "not": "An arbitrary shape brought in to hide the join, or the third time in one film." },+ { "id": "seam-brush", "cat": "seam", "role": "accent", "energy": "medium", "kinds": ["story", "drawing", "launch"],+ "move": "A loaded brush is pulled across in the direction the story is already moving, wet ink running ahead of the new picture, 0.6 to 0.9 s.",+ "build": "brushWipe(ctx, env, p, from, to, { angle, ink }) in transitions.ts.",+ "not": "A clean, set register. Or more than twice." },+ { "id": "seam-cut-on-beat", "cat": "seam", "role": "workhorse", "energy": "any", "kinds": ["any"],+ "move": "A plain hard cut with both sides at rest, on a strong beat, between two frames that match in one thing: a shape, a position, a direction of gaze.",+ "build": "No call. Put the cut frame on the cue table's downbeat and check the pair as stills: one thing sits in the same place on both.",+ "not": "Nothing matches, or the music has no beat there. Then use the gentle move." },+ { "id": "seam-one-canvas", "cat": "seam", "role": "workhorse", "energy": "calm", "kinds": ["explainer", "launch", "story", "interactive"],+ "move": "The scenes sit side by side in one layout larger than the frame and the camera travels between them; the route says how they relate.",+ "build": "One Camera for every plane (camera.ts); world-placed scenery so the view changes all the way (koiWorld.ts, webTour.ts).",+ "not": "The places are unrelated, or the trip between two stops is long and empty." },+ { "id": "seam-leave-as-arrived", "cat": "seam", "role": "workhorse", "energy": "any", "kinds": ["any"],+ "move": "A thing leaves the way it came, mirrored in time and shorter: what arrived over 0.5 s on a settling curve leaves over 0.25 s on an accelerating one, along the same path.",+ "build": "Run the entrance's own progress backwards through easeIn (seams.ts); if it was revealed from behind an edge it tucks back behind that edge where the edge is now.",+ "not": "The exit is the point of the scene. Then it gets a move of its own." },++ { "id": "cam-slow-push", "cat": "camera", "role": "workhorse", "energy": "calm", "kinds": ["any"],+ "move": "A hold that is never still: the camera pushes in 3 to 6 percent over the whole shot, so a quiet shot still changes every second.",+ "build": "Two Camera keys, zoom 1 to 1.04, ease \"linear\" for this one move only: an eased drift stops at both ends and the stop is the dead air.",+ "not": "A shot with a lot of its own motion. Two moves at once fight." },+ { "id": "cam-parallax-travel", "cat": "camera", "role": "workhorse", "energy": "medium", "kinds": ["story", "loop", "explainer"],+ "move": "The camera travels sideways and depth does the work: near things swing wide, far things barely stir, and something crosses the lens in front of the subject.",+ "build": "One Camera, planes at z from -0.3 (across the glass) to 4 or more (camera.md, depth planes). Never a hand-set drift per layer.",+ "not": "A flat style whose point is the flatness (a print, a diagram)." },+ { "id": "cam-follow-with-lag", "cat": "camera", "role": "workhorse", "energy": "medium", "kinds": ["story", "loop", "interactive"],+ "move": "The camera follows a moving subject a little late: the subject pulls ahead when it accelerates and the frame catches up when it slows, so speed is felt.",+ "build": "A path camera: path: (f) => ({ look: subject(f - lag), zoom }) with lag of 0.1 to 0.2 s; lead room in front of the subject.",+ "not": "The subject must stay pinned for a read (a face, a label)." },+ { "id": "cam-impact-shake", "cat": "camera", "role": "accent", "energy": "high", "kinds": ["story", "launch", "loop"],+ "move": "One impact rings through the frame: full strength on the hit, gone within a beat, with a little rotation.",+ "build": "cam.shake({ from, to, amp, seed, rot }) in camera.ts; amp is screen px, 0.8 to 1.5 percent of the width.",+ "not": "More than two a film, or on anything that is not a real contact." },+ { "id": "cam-pull-back-reveal", "cat": "camera", "role": "accent", "energy": "calm", "kinds": ["story", "explainer", "launch"],+ "move": "The camera pulls back and the thing we were looking at turns out to be a small part of something larger.",+ "build": "Camera keys in log2 zoom, monoZoom: true, 1.5 to 3 s; the large thing is painted in the world from the start, never faded in at the end.",+ "not": "The larger thing adds nothing to the story. Then it is only a zoom out." },+ { "id": "cam-rack-of-attention", "cat": "camera", "role": "accent", "energy": "calm", "kinds": ["story", "explainer", "launch"],+ "move": "Attention moves from one thing to another in the same frame without the camera moving: the first dims and softens its edges, the second gains contrast and line weight.",+ "build": "Draw both from one emphasis value 0..1: stroke weight, saturation and value contrast (no ctx.filter, the contract forbids it).",+ "not": "The two things are in different places in the story. That is a seam." },+ { "id": "cam-whip-to-rest", "cat": "camera", "role": "accent", "energy": "high", "kinds": ["story", "launch"],+ "move": "A fast pan to a new subject inside one scene that decays to rest on it: the last third of the move is the slow part.",+ "build": "Camera key with ease \"out\" over 0.4 to 0.7 s; keep the peak under speedCeiling(W, fps) (seams.ts) and render with --blur auto.",+ "not": "Past the ceiling. Then cut on the beat instead." },++ { "id": "reveal-drawn-on", "cat": "reveal", "role": "signature", "energy": "any", "kinds": ["any"],+ "move": "The thing is drawn into the picture in the order a hand would make it, the tool visible, each stroke taking the time its length asks for.",+ "build": "kind: \"drawing\" and the style plate's own draw order (workflows/drawing-process.md).",+ "not": "A fade standing in for drawing. If it cannot be drawn on, it arrives some other honest way." },+ { "id": "reveal-from-behind", "cat": "reveal", "role": "workhorse", "energy": "any", "kinds": ["any"],+ "move": "A thing comes out from behind something already in the picture (a hill, a card's edge, another figure), so the picture supplies the mask.",+ "build": "Clip with the occluder's own outline (pathShape in morph.ts) and move the thing out from under it on a settling curve, 0.4 to 0.7 s.",+ "not": "A mask in mid-air with nothing drawn where its edge is." },+ { "id": "reveal-by-light", "cat": "reveal", "role": "accent", "energy": "calm", "kinds": ["story", "loop"],+ "move": "The scene is there from the first frame but dark; light arrives (a door, a sun, a lamp) and the subject is found by it.",+ "build": "Paint the lit and unlit values of every surface and mix them by distance from the light's edge as it moves.",+ "not": "A style with no light in it (flat vector, a diagram)." },+ { "id": "reveal-assemble", "cat": "reveal", "role": "accent", "energy": "medium", "kinds": ["explainer", "launch", "story"],+ "move": "Parts arrive from the back to the front, each held above the stack with a wide soft shadow that closes as it lands, 0.08 to 0.12 s apart.",+ "build": "paperCraft.ts is the worked example; no more than about seven parts in flight at once.",+ "not": "Parts that are not real parts of the subject." },+ { "id": "reveal-count-during", "cat": "reveal", "role": "workhorse", "energy": "medium", "kinds": ["explainer", "launch", "infographic"],+ "move": "A number changes while the thing it counts is changing, and stops on the frame the action stops. Never after.",+ "build": "Drive the digits and the action from the same progress value (productUI.ts counts values this way).",+ "not": "A figure that is not true of the data on screen." },++ { "id": "type-written", "cat": "type", "role": "workhorse", "energy": "any", "kinds": ["launch", "explainer", "infographic"],+ "move": "A line is written by its tool, one stroke after another, at the speed of a hand, and holds long enough to be read twice.",+ "build": "writeOn or sentence in kinetic.ts; on its own frame, or over a calm area where the frame would pass as a poster (workflows/launch-video.md, Type).",+ "not": "Over a face, the focal detail or busy texture. In doubt the line gets its own frame." },+ { "id": "type-one-line-at-a-time", "cat": "type", "role": "workhorse", "energy": "medium", "kinds": ["launch", "explainer"],+ "move": "One line hands over to the next word by word, so there is never more than one full line on screen: the old line's words leave at twice the pace they came.",+ "build": "sentence() in kinetic.ts for the arriving line; run the leaving line's word progress backwards at half the entry stagger; the new line's first word starts on a beat.",+ "not": "Lines that must be compared. Those stay together." },+ { "id": "type-names-the-thing", "cat": "type", "role": "accent", "energy": "calm", "kinds": ["explainer", "launch", "infographic"],+ "move": "A dot lands on one thing, a line is drawn out from it, a short label is written at its end; the dot follows the thing, the label holds still.",+ "build": "drawCallout in callout.ts, pinned with cam.toScreen; one or two on screen.",+ "not": "The picture is busy where the label would sit and a backing would cover something that matters." },+ { "id": "type-label-becomes-heading", "cat": "type", "role": "signature", "energy": "medium", "kinds": ["explainer", "launch"],+ "move": "A label on one scene travels across the seam and lands as the heading of the next, on that scene's first frame.",+ "build": "A callout with handoff (callout.ts); the next scene draws it with drawLabel at the same pose; checkHandoff holds it to 2 px.",+ "not": "The label's words are not what the next scene is about." },+ { "id": "type-underline-then-point", "cat": "type", "role": "accent", "energy": "medium", "kinds": ["launch", "explainer"],+ "move": "The one word that matters is underlined by hand after the line has landed, 0.25 s, on a beat. Underlined, never struck through.",+ "build": "caption(..., \"underline\") in kinetic.ts, started when the line's progress reaches 1.",+ "not": "More than one word a line, or more than twice a film." },++ { "id": "act-anticipate", "cat": "acting", "role": "workhorse", "energy": "any", "kinds": ["story", "loop", "launch"],+ "move": "Before any large action the body goes the other way first: a crouch before a jump, a draw back before a throw, 0.15 to 0.3 s, a quarter of the action's size.",+ "build": "A held pose keyed before the action and blended through (a rig's mix between poses); bones keep their length (anatomy.md).",+ "not": "A machine, or a move meant to startle." },+ { "id": "act-follow-through", "cat": "acting", "role": "workhorse", "energy": "any", "kinds": ["story", "loop"],+ "move": "Loose parts arrive late and go further: a tail, hair, a sleeve follow the body by 0.05 to 0.1 s a segment, each segment wider than the one before.",+ "build": "Sample the driving angle at f - lag * i down the chain and scale its swing by 1 + 0.15 to 0.2 * i.",+ "not": "A stiff material. Wood and metal do not whip." },+ { "id": "act-settle", "cat": "acting", "role": "workhorse", "energy": "any", "kinds": ["any"],+ "move": "Nothing stops dead. A thing that lands goes a little past, comes back, and is at rest by 0.3 to 0.5 s; weight decides how far past.",+ "build": "One overshoot of 4 to 8 percent then a decay on easeOut; heavier things overshoot less and take longer.",+ "not": "Type meant to be read while it lands, and anything in a clean set register that should simply arrive." },+ { "id": "act-head-stays", "cat": "acting", "role": "accent", "energy": "high", "kinds": ["story", "loop"],+ "move": "In a run the body works hard and the head rides level: the eyes stay on one line while the spine folds and opens under them.",+ "build": "Solve the neck last, to a head height that does not follow the body (hold the head to a few px through a stride).",+ "not": "A bounce that is the joke (a toy, a rubber-hose character)." },+ { "id": "act-blink-and-breathe", "cat": "acting", "role": "workhorse", "energy": "calm", "kinds": ["story", "loop", "launch"],+ "move": "A character at rest is alive: the chest rises over 3 to 4 s, a blink of 0.1 to 0.15 s every few seconds at uneven gaps, an ear or a tail answers a sound.",+ "build": "Periodic over the loop length so the seam closes; blink times from rng(seed), never a fixed interval.",+ "not": "A portrait whose stillness is the point." },++ { "id": "emph-contact", "cat": "emphasis", "role": "accent", "energy": "high", "kinds": ["story", "loop", "launch"],+ "move": "A contact is shown where it happens: dust, a splash or a compressed shadow on the frame of the hit, clearing over 0.4 to 0.8 s.",+ "build": "Seeded particles born on the contact frame from the contact point; the sound effect cued to the same frame (music/sound-design.md).",+ "not": "A touch with no force in it." },+ { "id": "emph-world-answers", "cat": "emphasis", "role": "accent", "energy": "medium", "kinds": ["story", "loop"],+ "move": "The subject's action moves something else in the scene a moment later: grass bends in the wake, birds lift, water rings spread.",+ "build": "Drive the secondary thing from the primary's position at f - delay, falling off with distance.",+ "not": "A reaction that draws the eye off the subject at the moment that matters." },+ { "id": "emph-hold-the-result", "cat": "emphasis", "role": "workhorse", "energy": "calm", "kinds": ["any"],+ "move": "After the biggest change in the film the result is held, alive but unbroken, for 1 to 2 s before anything else happens.",+ "build": "A hold in the cue table after the payoff with only breathing motion in it (cam-slow-push, act-blink-and-breathe).",+ "not": "A loop under 6 s, where the hold would be most of it." },++ { "id": "close-returns-to-open", "cat": "close", "role": "signature", "energy": "any", "kinds": ["story", "loop", "launch"],+ "move": "The last frame is the first frame, earned: the film ends where it began and the viewer now knows what it means.",+ "build": "Draw the closing shot from the opening shot's own function at the same frame; for a loop, verify-export.mjs --loop holds the last frame to frame 0.",+ "not": "A film whose point is that things changed for good." },+ { "id": "close-subtract", "cat": "close", "role": "workhorse", "energy": "calm", "kinds": ["any"],+ "move": "The ending takes things away: motion slows, parts leave, the music stops on a bar line, a breath of near silence, then one soft sound on the last picture.",+ "build": "A section with fewer parts and no low drum, then one resolved note; music.mjs check prints the ARC line, which flags an ending that out-shouts the film.",+ "not": "A sting of a few seconds, which is all ending." },+ { "id": "close-mark-from-actor", "cat": "close", "role": "accent", "energy": "medium", "kinds": ["launch", "explainer"],+ "move": "The thing that travelled through the film lands as part of the mark, and the end card opens from it.",+ "build": "handoff (morph.ts) from the actor's last shape to the mark's shape; the wordmark written after it lands (logo in kinetic.ts).",+ "not": "A mark the actor does not resemble in any way." }+ ]+}diff --git a/plugins/anidoodle/skills/anidoodle/references/motion-grammar.md b/plugins/anidoodle/skills/anidoodle/references/motion-grammar.mdindex dfb74c4..0703bcd 100644--- a/plugins/anidoodle/skills/anidoodle/references/motion-grammar.md+++ b/plugins/anidoodle/skills/anidoodle/references/motion-grammar.md@@ -130,6 +130,54 @@ with the incoming scene already complete underneath. `transitionsDemo.ts` showsdefault, never repeated quickly: declare a film's flashes to `checkFlashes`, which throws onany two within half a second.+## Cuts that carry motion++A hard cut between two shots that are both moving can be the smoothest seam there is, or the+roughest. The difference is arithmetic, and `engine/src/canvas-core/seams.ts` does it.++- **Both sides at rest, or both at one speed.** A cut from a moving shot to a still one (or the+ other way) reads as a jerk. So does a cut where the travel turns, halves or doubles.+- **Accelerate out, cut after the fastest frame, arrive and settle.** The outgoing shot speeds up+ over about 0.2 to 0.4 s; the incoming shot opens at that same speed, in that same screen+ direction, and comes to rest over 0.8 to 1.4 s. The exit is the short side.+ `matchedMove({ dir, exitDist, exitF, entryF })` gives both halves, to add to each scene's+ camera look; the entry distance is worked out from the exit speed, so the two always agree.+ The incoming shot owns the cut frame: the outgoing shot's last frame on screen is the one+ before it, and that is its fastest.+- **Through the cut, in depth.** `matchedZoom({ push, exitF, entryF })` does the same for a+ camera that flies into one shot and out in the next. A zoom is a ratio, so both sides run in+ log space and grow at the same rate per frame across the cut. With the default push the+ incoming shot opens at about two thirds of its size, so its scene must be painted that much+ wider than the frame; a zoom that would open it under 0.4 is refused.+- **There is a top speed.** Past about two and a half frame widths a second+ (`speedCeiling(W, fps)`), blur stops reading as motion and shows as a streak with stepped+ copies. A move that needs more than that wants a shorter travel with the rest hidden behind+ the cut, or a plain cut on the beat. Render fast seams with `--blur auto`.+- **Match everything, once.** Whatever crosses the cut keeps its position, size, colour and+ edge; a property that flips on the cut frame pops. And the resting pose is shown once: if one+ shot settles onto a pose and the next opens on it, the first shot's last frame is the move's+ last in-between, never the pose itself, or the film stops, holds and goes.+- **Never dissolve two copies of one thing.** At the halfway point both are half there and the+ eye sees a ghost. Move one object; change what it is at the middle of its trip.++`checkSeam(velocity before, velocity after, { W, fps })` returns what is wrong with a cut, or+nothing: one side at rest, a turn of more than 30 degrees, a speed that drops or jumps. `checkSeamPlan` reads the film's list of seams and flags a designed seam used a third+time; plain and matched cuts are exempt, and the film's one signature move gets three (the open,+the middle, the close). Use this when both scenes have room to travel the same way. When they do+not, bring both to rest and cut on a beat.++## Dealing a hand++Left to choose, every film reaches for the same three moves. `node tools/deck.mjs deal --kind+story --energy high --seconds 27` deals a hand from `references/motion-deck.json`: an opening, a+close and a spread of seams, camera moves, reveals and acting notes, each with its numbers, its+engine call and when not to use it. The deal is weighted toward what fits the film and is+repeatable from its printed seed; `--avoid` keeps the next film off the last one's cards.++A card is a prompt, never an order. Keep it, adapt it to this film's subject and medium, or drop+it, and say which in the brief. The default at the top of this page still holds: a card whose+"not when" applies is dropped, and the gentle move takes its place.+## Callouts and the label handoff`engine/src/canvas-core/callout.ts` names one thing in the picture: a dot lands on it, a leaderdiff --git a/plugins/anidoodle/skills/anidoodle/references/music/README.md b/plugins/anidoodle/skills/anidoodle/references/music/README.mdindex 5f73446..ddca2be 100644--- a/plugins/anidoodle/skills/anidoodle/references/music/README.md+++ b/plugins/anidoodle/skills/anidoodle/references/music/README.md@@ -314,6 +314,7 @@ Follow [`compose.md`](compose.md). In short:2. one style + one mood + five mood controls;3. compose YOUR harmony, bass lines, motif(s), groove choice and form as `Material`;4. `node tools/music.mjs check <file>.ts#<export>` must PASS (key, master, ghost/reverb/masking guards, stems, novelty);+ answer its ARC line too (the shape of the whole: [`theory/form.md`](theory/form.md), section 3);5. `node tools/music.mjs render <file>.ts#<export> out.wav` (use wav for loops: mp3 is not gapless);6. 8 seconds (then the whole piece) to a human, as an mp3 on a page.diff --git a/plugins/anidoodle/skills/anidoodle/references/music/theory/form.md b/plugins/anidoodle/skills/anidoodle/references/music/theory/form.mdindex 3fdd779..2726511 100644--- a/plugins/anidoodle/skills/anidoodle/references/music/theory/form.md+++ b/plugins/anidoodle/skills/anidoodle/references/music/theory/form.md@@ -54,6 +54,30 @@ Working film composers structure a cue around **hit points**: the frames where s- a fade only for loops;- an open hold only for suspense.+### The shape of the whole, measured++A score can have a good tune, good harmony and a clean mix and still feel like it wanders, because+nothing in it is the high point and nothing in it is the rest. `music.mjs check` prints an **ARC** line+from the finished sound (`arc.ts`): the usual level, the loudest moment and how far through it falls,+how far the opening sits under the body, and how far the ending sits under the peak. It is advisory,+like `craft`: answer each finding, or say why the piece is that way on purpose.++- **A soft way in.** The first two or three seconds carry fewer parts and no low drum, 5 to 12 LU under+ the body. Frame 0 still has one sound with a reason: a drone, the first chord. Silence that swells+ in over a bar reads as nothing happening yet.+- **One loudest moment, on the picture's payoff.** At least 2 LU over the usual level, usually a third+ to two thirds of the way through. Pass the payoff's second (`--payoff 13.5`) and the check says if+ the fullest bar is somewhere else. Hold something back until then: the low drum, the top octave, a+ doubling.+- **Contrast is the arc.** A piece of 20 s or more wants a loudness range of 5 to 8 LU. One texture+ from start to finish measures about 2 and feels dense and flat however good each bar is.+- **The ending takes away.** The close is the most resolved moment, never the loudest: stop on a bar+ line, a breath, one soft element, 8 to 20 dB under the peak. A loudest moment in the last fifth is+ flagged.+- **A loop has no beginning or end.** Only its contrast and its seam are read. The join is flagged when+ the last second and the first differ by more than 3 LU and by more than any two neighbouring seconds+ inside the piece: a phrase that ends into a quiet bar is the music, a step found nowhere else is a seam.+## 4. Orchestration: registers and frequency slotsEvery instrument owns a register. Two parts in the same register fight (masking, seediff --git a/plugins/anidoodle/skills/anidoodle/references/workflows/review.md b/plugins/anidoodle/skills/anidoodle/references/workflows/review.mdnew file mode 100644index 0000000..8f95c12--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/references/workflows/review.md@@ -0,0 +1,85 @@+# The review: four readings, one list, one gate++`working-method.md` says to review the whole film once, from the rendered file. This is how that+one review is run. It does not add rounds: four readings of the same frozen file, one ranked fix+list, one rebuild, one check that each fix landed.++The reason for four readings is that one reader looks for one kind of fault. Someone checking+for a popped frame does not notice that the film has no point, and someone following the story+forgives a hand with six fingers. Each reading below has one job, its own evidence and the+dimensions it scores. Do them in this order, and finish one before starting the next.++Freeze a copy of the file and note its hash first. Every reading is of that copy.++## The four readings++| Reading | Looks at | What it settles | Scores |+|---|---|---|---|+| **Director** | the contact sheet at one tile per beat, sound off; then each seam as a before/after pair | Whether someone who has never seen the brief could say what the film is about, and feel the payoff. | point, first second, pacing, seams |+| **Illustrator** | full-size stills of the hardest frames; crops of faces, hands, feet and joins at `--scale 2` | Whether a proud illustrator would sign it, or it is shapes assembled (`craft-bar.md`). | drawing, style |+| **Motion and finish** | `popscan.mjs`, `gate.mjs`, strips of consecutive frames across every seam and every fast move | Whether anything pops, stalls, jumps or smears that was not meant to. | motion, finish |+| **Sound and sync** | `music.mjs check` (with its ARC line), `verify-export.mjs`, the cue table against the picture | Whether the sound is one piece with a shape, and lands on the picture. | sound |++Rules that make a reading worth having:++- **Evidence before opinion.** Every finding names a frame (or a second, for sound) and a cause.+ "The run feels slow" is an impression; "the ground travels 22 px a frame at 400 while her+ stride covers 60" is a finding.+- **Say what works first**, so it survives the fixes.+- **A picture that does not read is fixed in the picture.** Never by adding a caption.+- **The sound reading cannot hear.** Its findings are measurements; say so, and a human listens+ before the film ships.+- **A fresh reader is worth more than a second pass by the builder.** When a reading is handed+ to someone else, give them the file and the brief, never your own conclusions.++## Severity++| Level | Meaning | Examples |+|---|---|---|+| **P0** | seen on a key moment (the first second, the payoff, the last frame), or it breaks the story, a fact or the contract | the character changes between two shots; the payoff lands 3 frames off its sound; a frame differs between two renders |+| **P1** | noticed on a normal viewing | a one-frame pop mid-scene; two seconds where nothing changes; a seam where the travel reverses |+| **P2** | seen only on pause | a stroke a pixel short for three frames inside a fast move |++## The check before fixing++Before anything is changed, every P0 and P1 is looked at once more, at full size, by someone+trying to prove it wrong: it must be on the frame named, be what the finding says, and be+something a viewer would see. Some first-pass findings do not survive this, and each one that is "fixed" anyway+costs a rebuild and risks something that worked. What survives goes on the list, ranked by how+much the film gains for the time the fix takes.++## The scorecard++Score each line 1 to 5. The descriptions are for 1, 3 and 5. Where two readings disagree, the+lower score stands. A line with an open P0 cannot score above 3.++| | 1 | 3 | 5 |+|---|---|---|---|+| **Point** | a tour of nice things | one idea, but it drops out for a stretch | one idea that reads with the sound off, and something set up early that pays off |+| **First second** | a still or empty frame | moving, but the subject arrives late | frame 0 composed and already in motion; the subject known within a second |+| **Drawing** | subjects built from ellipses; rubber joints | sound, with weak hands, feet or joins | anatomy from named reference; survives a crop at twice the size |+| **Style** | one look recoloured | the medium's marks, used unevenly | the marks, the edge and the order of making all belong to the medium |+| **Motion** | everything fades and slides at one speed | good curves, with a pop or a stall | weight, anticipation, things that settle; nothing stops dead |+| **Seams** | dissolves between unrelated pictures | motivated, but one repeated until it is a preset | something carried across every seam; no designed seam used a third time (`checkSeamPlan`) |+| **Pacing** | dead holds, or everything at once | even, with no high point | one high point, calm either side of it, results held long enough to land |+| **Sound** | out of step with the picture, or wandering | in step, but flat or crowded | every cue on its frame, one clear loudest moment on the payoff, an ending that takes away |+| **Finish** | pops, banding, a frame that differs between renders | an explained flaw or two | gate and export checks pass; every flag from the scans answered |++A silent piece leaves Sound out. A still is scored on Point, Drawing, Style and Finish.++## The gate++The film ships when all of these hold:++- every line is 3 or more, Finish is 5, and the average is 4 or more;+- no P0 is open;+- `gate.mjs` and `verify-export.mjs` pass, and for a scored film `music.mjs check` passes and a+ human has listened.++After the rebuild, go down the fix list item by item against the new file and mark each one+**fixed**, **partly** or **still there**, with the frame looked at. Nothing is marked fixed from+the code alone.++Then say the scores to the person who asked, in plain words, with the one or two things you+would still change. "This is a 4 on Seams, because the brush wipe is used three times" is worth+more to them than "done".diff --git a/plugins/anidoodle/skills/anidoodle/references/working-method.md b/plugins/anidoodle/skills/anidoodle/references/working-method.mdindex f505bc8..e9f0de4 100644--- a/plugins/anidoodle/skills/anidoodle/references/working-method.md+++ b/plugins/anidoodle/skills/anidoodle/references/working-method.md@@ -13,7 +13,7 @@- **Critique it yourself first**, in writing, against the craft table, and say what is still wrong when you show it.- ✋ One approval.- **Then build end to end without stopping.** A rough complete film on day one beats a perfect first act. Mechanical checks run continuously and need nobody's approval: types, grid, contract scan, draw budget, determinism probe, dead air.-- **Review the whole, once.** From the rendered file itself: a contact sheet at one tile per beat, each cut as a before/after pair with a difference measure, the dead-air numbers, a few full-resolution frames where the sheet raises a doubt. One numbered fix list, ranked. One rebuild.+- **Review the whole, once.** From the rendered file itself: a contact sheet at one tile per beat, each cut as a before/after pair with a difference measure, the dead-air numbers, a few full-resolution frames where the sheet raises a doubt. One numbered fix list, ranked. One rebuild. How that one review is run (four readings, a scorecard, the gate): `workflows/review.md`.- **Approval is a budget.** Each gate spends the client's attention and your tokens. Spend them where being wrong is expensive, which is the look, the music sample and the final film. Three, not thirty.**What a good review looks like** (this part of the over-gated process was worth keeping): freeze a copy of the file and note its hash before looking, because the builder may be re-rendering under you (it was, twice). Report what works first, so it survives the fixes. Give causes, not impressions: not "the body is green" but "the sun disc prints over the thorax, blue times yellow". Correct your own spec in the same breath when the fault was yours (a 5-frame wing lag that I specified became antiphase on a 10-frame beat: one wing folded while the other was spread).