Hand-drawn 2D animation written as code: detail bible, a detailed ant rig, brush/watercolour pen, frame-matched recreation loop, synthesised sound. Node canvas + ffmpeg.
JavaScript
claude-animation: hand-drawn 2D animation written as code
buildwithhanif632bb0192ffd
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonnew file mode 100644index 0000000..7812281--- /dev/null+++ b/.claude-plugin/marketplace.json@@ -0,0 +1,18 @@+{+ "name": "claude-animation-skill",+ "description": "Hand-drawn 2D animation written as code: textured-editorial and brush-watercolour looks, a detailed ant rig, an ant colony kit, synthesised sound.",+ "version": "1.0.0",+ "owner": { "name": "Hanif", "url": "https://github.com/buildwithhanif" },+ "plugins": [+ {+ "name": "claude-animation",+ "source": "./plugins/claude-animation",+ "description": "Make short hand-drawn animations in JavaScript (node canvas + ffmpeg): brush, pencil, watercolour, grain and hatching; poseable rigs and a colony kit; sheet/strip/verify previews; synthesised SFX and music.",+ "category": "content",+ "keywords": ["animation", "2d", "hand-drawn", "canvas", "javascript", "storybook", "illustration", "ffmpeg", "colony"],+ "license": "MIT",+ "homepage": "https://github.com/buildwithhanif/claude-animation-skill",+ "repository": "https://github.com/buildwithhanif/claude-animation-skill"+ }+ ]+}diff --git a/.gitignore b/.gitignorenew file mode 100644index 0000000..c18bffe--- /dev/null+++ b/.gitignore@@ -0,0 +1,5 @@+node_modules+out/+ref/+*.mix.wav+.DS_Storediff --git a/LICENSE b/LICENSEnew file mode 100644index 0000000..7360120--- /dev/null+++ b/LICENSE@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2026 Hanif (@hanifproduktif)++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.diff --git a/README.md b/README.mdnew file mode 100644index 0000000..4a89449--- /dev/null+++ b/README.md@@ -0,0 +1,98 @@+# Claude Animation++**Hand-drawn 2D animation, written as code.** Give it a story and get a frame-exact MP4 that looks drawn:+paper grain, hatching, brush ink, watercolour that blooms, glossy characters with real anatomy, whole worlds+in cross-section, and sound synthesised from the same timeline as the picture.++++MIT licensed. Node + ffmpeg. No browser, no GPU, no API keys.++---++## Why this exists++Ask a model to "animate a story in JavaScript" and you get flat shapes sliding around. What makes code look+drawn isn't the model, it's **a vocabulary of detail** and **a habit of looking**. This skill is both,+written down after making the films:++**1. A detail bible.** Every surface gets base → texture → edge. Soil is hatch + strata + pebbles; chitin is a+gradient with form hatch, a specular streak, rim light and setae; leaves have serrated edges and pale veins;+fungus is a spongy mass that grows. Line weight falls off with depth. The skill makes the model ask for+detail surface by surface instead of hoping for it.++**2. Rigs with anatomy.** The ant has a segmented gaster, a petiole node, a humped thorax, a compound eye with+two highlights, toothed mandibles that open, elbowed beaded antennae, and six legs with femur, knee, tibia,+tarsus and claws, walking on a real tripod gait. It can carry, chew, rear up, sweat, blink, be a queen — and+draw itself in layers: sketch, ink, colour, polish.++++**3. A colony kit.** Leaves you can cut, leaf pieces to carry, eggs, larvae, cocoons, stores, a fungus garden,+roots, and `nestCanvas()` — chambers and tunnels baked into textured soil, returning paths an ant can walk.++**4. A harness that makes you look.** `sheet`, `strip` (12 consecutive frames around a fast action),+`verify` (a frame must be identical rendered in or out of order), and a staged `render` that never+overwrites a good file with a failed encode.++## The example film++`examples/ant-colony/` — 32 s, 16:9. "This is code." → the ant built from sketch to polish → a leafcutter+cuts a leaf and carries it through a meadow in a column of others → a dive into the mound → the nest in+cross-section: the leaf goes onto the fungus garden, the nursery, the queen laying, and a pull-back to the+whole colony as day turns to night. 240 sound cues, one music bed, all synthesised. Renders in ~27 s.++++```bash+cd plugins/claude-animation/skills/claude-animation && npm install && cd -+cd examples/ant-colony && ./make.sh # -> out/ant-colony-final.mp4+```++---++## Install++```bash+claude plugin marketplace add buildwithhanif/claude-animation-skill+claude plugin install claude-animation@claude-animation-skill+cd <plugin dir>/skills/claude-animation && npm install+```++Or clone it and point any coding agent at `plugins/claude-animation/skills/claude-animation/SKILL.md`.++**Requirements:** node 20+, ffmpeg/ffprobe.++## Quick start++```bash+SK=plugins/claude-animation/skills/claude-animation+mkdir my-film && cd my-film && cp ../$SK/templates/film-template.mjs film.mjs+CLAUDE_ANIMATION_LIB=../$SK/lib node film.mjs sheet 0,1,2,3,4+CLAUDE_ANIMATION_LIB=../$SK/lib node film.mjs render+node ../$SK/scripts/music.mjs bed.wav --dur 5 --end 4.4+node ../$SK/scripts/sound.mjs cues.json out/template.mp4 out/final.mp4 --bed bed.wav+```++## What's inside++```+plugins/claude-animation/skills/claude-animation/+ SKILL.md the rules and the map+ lib/core.mjs easing, noise, paths, IK, hatch / fibre / grain / burst / speed lines+ lib/pen.mjs brush, pencil, watercolour, lettering — stable named seeds, opt-in boil+ lib/textures.mjs paper, light bands, sun, moon, stars, grass, soil, night sky, fruit cells, film finish+ lib/nature.mjs sprout, melon leaf, tendril, vine, blossom, bee, drop+ lib/colony.mjs leaf, leaf piece, egg, larva, cocoon, seed, fungus, roots, nest cross-section+ lib/rigs/ant.mjs the detailed ant (+ build-up layers and construction guides)+ lib/rigs/bean.mjs bean-bodied people for the brush-watercolour look+ lib/film.mjs render / sheet / strip / verify, exposure (ones, twos, holds)+ scripts/sound.mjs synthesised SFX on a cue timeline + bed + loudnorm + mux+ scripts/music.mjs an original ukulele bed of any length+ scripts/rig-sheet.mjs the pose sheet a rig must pass+ templates/ film-template.mjs, beat-sheet.md+ references/ workflow, detail, characters, motion, styles, sound, traps, prior-art+examples/ant-colony/ the 32 s 16:9 film above+```++Ideas from other animation skills are credited in `references/prior-art.md`.diff --git a/docs/ant-detail.png b/docs/ant-detail.pngnew file mode 100644index 0000000..e365db7Binary files /dev/null and b/docs/ant-detail.png differdiff --git a/docs/ant-poses.png b/docs/ant-poses.pngnew file mode 100644index 0000000..a6bac22Binary files /dev/null and b/docs/ant-poses.png differdiff --git a/docs/colony-contact.jpg b/docs/colony-contact.jpgnew file mode 100644index 0000000..23d3c8fBinary files /dev/null and b/docs/colony-contact.jpg differdiff --git a/docs/colony-nest.jpg b/docs/colony-nest.jpgnew file mode 100644index 0000000..b3401ddBinary files /dev/null and b/docs/colony-nest.jpg differdiff --git a/examples/ant-colony/film.mjs b/examples/ant-colony/film.mjsnew file mode 100644index 0000000..51e1335--- /dev/null+++ b/examples/ant-colony/film.mjs@@ -0,0 +1,304 @@+// film.mjs — "The leaf and the colony": a 32 s, 16:9 showcase of the claude-animation skill.+// node film.mjs sheet 0.5,3,5,8,12,18 | strip 9.5 12 | verify | cues | render+//+// STYLE BIBLE (verbatim): textured editorial storybook. Paper #F3EEDD + grain + 40° light bands in skies.+// Ink #1E1612, heroes 2.6–3.4 px. Ant browns; leaf greens #8CCB6A→#4E9A42; soil #7A5234→#3E2616 with lit+// chambers #F0CC98→#8E6342; brood whites; fungus #FFFFFF→#DCD6C8; construction blue #5E80CC only for the+// cut line and the process section. No text between 7 s and the end card: the pictures carry it.+//+// BEATS+// 0.0– 2.2 HOOK: the ant's face, huge. "This is code." + the line that draws it.+// 2.2– 7.0 PROCESS: sketch → ink → colour → polish (sweeps), then it walks out.+// 7.0–10.8 LEAF: a fallen leaf; a blue cut-line; the ant chews along it; the piece goes up like a sail.+// 10.8–15.4 TRAIL: tracking shot with parallax, a column of leaf-carriers, morning into gold, the mound.+// 15.4–15.9 DIVE into the hole.+// 15.9–26.6 COLONY in cross-section: down the shaft, the leaf goes onto the fungus garden, the nursery+// (magnifier on a larva), the queen lays an egg, pull back to the whole nest while day turns to night.+// 26.6–32.0 END CARD: every frame is code + repo.+import path from "node:path";+import fs from "node:fs";+import { fileURLToPath } from "node:url";+const HERE = path.dirname(fileURLToPath(import.meta.url));+const LIB = process.env.CLAUDE_ANIMATION_LIB || path.join(HERE, "../../plugins/claude-animation/skills/claude-animation/lib");+const { clamp, lerp, ss, eOut, eIn, eIO, eBack, popS, at, line, ellipse, stroke, fill, poly, smooth, hatch, burst, speedLines, rrect, rng, rad, hash, pathOf, createCanvas, INK } = await import(path.join(LIB, "core.mjs"));+const { paper, lightBands, sun, moon, star4, grass } = await import(path.join(LIB, "textures.mjs"));+const { sprout, drop, blossom } = await import(path.join(LIB, "nature.mjs"));+const { leaf, leafPiece, egg, larva, cocoon, seedGrain, fungus, roots, nestCanvas } = await import(path.join(LIB, "colony.mjs"));+const { ant, antGuides } = await import(path.join(LIB, "rigs/ant.mjs"));+const { run } = await import(path.join(LIB, "film.mjs"));+const { GlobalFonts } = await import(path.join(LIB, "../node_modules/@napi-rs/canvas/index.js"));+const FD = process.env.FONT_DIR || path.join(process.env.HOME, ".claude/skills/tesseract-edit/assets/fonts");+const reg = (f, n) => { if (fs.existsSync(f)) GlobalFonts.registerFromPath(f, n); };+reg(path.join(FD, "Inter/Inter_28pt-Bold.ttf"), "IBold"); reg(path.join(FD, "Inter/Inter_28pt-SemiBold.ttf"), "ISemi"); reg("/System/Library/Fonts/Menlo.ttc", "Mono");++const W = 1920, H = 1080, FPS = 24, DUR = 32;+const CUT = { process: 2.2, leaf: 7.0, trail: 10.8, dive: 15.4, colony: 15.9, end: 26.6 };+const RENDER_SECONDS = process.env.RENDER_SECONDS || "20";+const BLUE = "#5E80CC";++// ---------------------------------------------------------------- type helpers+function typed(ctx, str, x, y, t0, t1, t, { font = "76px IBold", color = INK, align = "left", caret = false } = {}) {+ const n = Math.floor(str.length * clamp((t - t0) / (t1 - t0))); if (n <= 0 && !caret) return;+ ctx.save(); ctx.font = font; ctx.fillStyle = color; const full = ctx.measureText(str).width, x0 = align === "center" ? x - full / 2 : x, s = str.slice(0, n); ctx.fillText(s, x0, y);+ if (caret && (t < t1 + .6 || Math.floor(t * 2.5) % 2 === 0)) { const cw = ctx.measureText(s).width, fs_ = parseInt(font); ctx.fillRect(x0 + cw + 4, y - fs_ * .78, fs_ * .08, fs_ * .9); }+ ctx.restore();+}+function codeChip(ctx, str, x, y, t0, t1, t, size = 32, align = "left") {+ ctx.save(); ctx.font = `${size}px Mono`; const w = ctx.measureText(str).width + 56, h = size * 1.9, k = clamp((t - t0 + .15) / .2); if (k <= 0) { ctx.restore(); return; }+ const x0 = align === "center" ? x - w / 2 : x; ctx.globalAlpha = k; poly(ctx, rrect(x0, y - h / 2, w, h, 20)); fill(ctx, "#1E1612"); ctx.restore();+ typed(ctx, str, x0 + 28, y + size * .35, t0, t1, t, { font: `${size}px Mono`, color: "#F3EEDD", caret: true });+}++// ================================================================ 1. HOOK+function hook(ctx, t, S) {+ ctx.drawImage(S.paper, 0, 0); lightBands(ctx, W, H, t, { alpha: .45 });+ const Z = lerp(3.1, 2.75, eOut(t / 2.2)), fx = 1330, fy = 650;+ ctx.save(); ctx.translate(1560, 600); ctx.scale(Z, Z); ctx.translate(-fx, -fy);+ ant(ctx, 1200, 780, 1.3, { jaw: ss(.75, .9, t) * (1 - ss(1.4, 1.55, t)), ant: Math.sin(t * 4) * .5, blink: t > 1.2 && t < 1.3 });+ ctx.restore();+ typed(ctx, "This is code.", 100, 250, .12, .7, t, { font: "150px IBold" });+ codeChip(ctx, "ant(ctx, x, ground, 1.3, { jaw: .6 })", 100, 370, .6, 1.5, t, 34);+}++// ================================================================ 2. PROCESS: sketch → ink → colour → polish+const LOOKS = [null, { ink: 1, fill: 0, tex: 0 }, { ink: 1, fill: 1, tex: 0 }, { ink: 1, fill: 1, tex: 1 }];+const SWEEP = [3.05, 4.05, 5.05], SW = .42, STAGE = ["sketch", "ink", "colour", "polish"];+function process_(ctx, t, S) {+ ctx.drawImage(S.paper, 0, 0);+ ctx.save(); ctx.strokeStyle = "rgba(94,128,204,.13)"; ctx.lineWidth = 1.4; for (let x = 20; x < W; x += 60) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke(); } for (let y = 0; y < H; y += 60) { ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(W, y); ctx.stroke(); } ctx.restore();+ const GY = 820, SC = 2.3, walk = t > 6.2, AX = 950 + (walk ? eIn((t - 6.2) / .8) * 1300 : 0);+ line(ctx, [[260, GY], [1660, GY]], 2.4, walk ? INK : BLUE);+ const stage = SWEEP.filter((s) => t >= s + SW).length, sw = SWEEP.findIndex((s) => t >= s && t < s + SW);+ const pose = { ant: Math.sin(t * 4) * .4, gait: walk ? t * 11 : undefined, blink: t > 5.8 && t < 5.9 }, guidesA = 1 - ss(5.05, 5.7, t);+ const draw = (k) => { if (k >= 1) ant(ctx, AX, GY, SC, { ...pose, look: LOOKS[k] }); };+ if (guidesA > 0) antGuides(ctx, AX, GY, SC, ss(2.25, 2.95, t), { color: stage >= 1 ? `rgba(94,128,204,${.45 * guidesA})` : BLUE, w: 2.4 });+ if (sw >= 0) { const k = (t - SWEEP[sw]) / SW, sx = lerp(100, 1820, eIO(k));+ ctx.save(); ctx.beginPath(); ctx.rect(0, 0, sx, H); ctx.clip(); draw(sw + 1); ctx.restore();+ ctx.save(); ctx.beginPath(); ctx.rect(sx, 0, W - sx, H); ctx.clip(); draw(sw); ctx.restore();+ ctx.save(); const gl = ctx.createLinearGradient(sx - 50, 0, sx + 50, 0); gl.addColorStop(0, "rgba(94,128,204,0)"); gl.addColorStop(.5, "rgba(94,128,204,.35)"); gl.addColorStop(1, "rgba(94,128,204,0)"); ctx.fillStyle = gl; ctx.fillRect(sx - 50, 200, 100, 700); ctx.restore();+ line(ctx, [[sx, 200], [sx, 900]], 3, BLUE); } else draw(stage);+ // the stage strip: sketch · ink · colour · polish, the current one lit+ const cur = sw >= 0 ? sw + (t > SWEEP[sw] + SW * .5 ? 1 : 0) : stage;+ ctx.save(); ctx.font = "52px IBold"; ctx.textAlign = "center";+ STAGE.forEach((s, i) => { const x = 560 + i * 270, on = i === cur, k = on ? popS(t, i === 0 ? 2.25 : SWEEP[i - 1] + SW * .5, .3, 1.8) : 1;+ ctx.fillStyle = on ? INK : "rgba(30,22,18,.28)"; at(ctx, x, 150, on ? .9 + .2 * k : 1, 0, () => ctx.fillText(s, 0, 0)); if (i < 3) { ctx.fillStyle = "rgba(30,22,18,.28)"; ctx.fillText("→", x + 135, 150); } });+ ctx.restore();+ if (t > 5.45 && t < 5.85) burst(ctx, AX + 240, GY - 350, 70, 110, 9, 4, INK, Math.PI * 1.1, Math.PI * .8);+}++// ================================================================ 3–4. LEAF + TRAIL (world A)+const GA = 860, WA = 6400, MOUND = 5600;+function buildWorldA() {+ const hills = createCanvas(3600, H), h = hills.getContext("2d"), r = rng(3);+ for (const [base, col, amp] of [[640, "#BFD7A8", 60], [720, "#A8CB8E", 45]]) { h.beginPath(); h.moveTo(0, H); for (let x = 0; x <= 3600; x += 40) h.lineTo(x, base - amp * Math.sin(x * .002 + base) - 25 * Math.sin(x * .007)); h.lineTo(3600, H); h.closePath(); h.fillStyle = col; h.fill(); h.strokeStyle = "rgba(30,22,18,.35)"; h.lineWidth = 2; h.stroke(); }+ hatch(h, () => { h.beginPath(); h.rect(0, 560, 3600, 520); }, rad(-30), 9, "#7FA86A", 1, .25, [0, 560, 3600, H]);+ for (let i = 0; i < 26; i++) { const x = 80 + i * 140 + r() * 60, y = 690 - r() * 40; line(h, [[x, y], [x, y - 60]], 3, "rgba(60,90,50,.5)"); ellipse(h, x, y - 80, 26, 34); fill(h, "rgba(110,160,90,.55)"); }+ const mid = createCanvas(WA, H), m = mid.getContext("2d"), r2 = rng(8);+ // ground strip with path and pebbles+ const gg = m.createLinearGradient(0, GA, 0, H); gg.addColorStop(0, "#A2744C"); gg.addColorStop(1, "#6E4A2C"); m.fillStyle = gg; m.fillRect(0, GA, WA, H - GA);+ hatch(m, () => { m.beginPath(); m.rect(0, GA, WA, H - GA); }, rad(-30), 7, "#4E321C", 1, .3, [0, GA, WA, H]);+ for (let i = 0; i < 380; i++) { const x = r2() * WA, y = GA + 8 + r2() * (H - GA - 8), s = r2(); if (s > .9) { ellipse(m, x, y, 10 + r2() * 12, 7 + r2() * 7, r2() * 3); fill(m, "#D9C09A"); stroke(m, 1.6, "#3B2414"); } else { m.fillStyle = s > .5 ? "#5E3E24" : "#B88B5E"; ellipse(m, x, y, 2 + s * 5, 1.6 + s * 3); m.fill(); } }+ line(m, [[0, GA], [WA, GA]], 3.2);+ // meadow: grass tufts, clover and small flowers behind the path+ for (let x = 0; x < WA; x += 90 + r2() * 120) { if (x > 650 && x < 1700) continue; const hgt = 60 + r2() * 110; for (let k = 0; k < 7; k++) { const bx = x + k * 7, lean = (r2() - .5) * 40; smooth(m, [[bx, GA], [bx + lean * .3, GA - hgt * .6], [bx + lean, GA - hgt]], false); stroke(m, 3.4); smooth(m, [[bx, GA], [bx + lean * .3, GA - hgt * .6], [bx + lean, GA - hgt]], false); stroke(m, 2, k % 2 ? "#6FA45A" : "#8DB872"); }+ if (r2() > .6) { const fxx = x + 30, fh = 240 + r2() * 110; line(m, [[fxx, GA], [fxx + 6, GA - fh]], 4, "#4E8A3A"); at(m, fxx + 6, GA - fh, .42 + r2() * .2, 0, () => blossom(m, 1, r2() > .5 ? "#F5CF3A" : "#F4F0E6")); } }+ // the mound and its hole+ m.save(); m.beginPath(); m.moveTo(MOUND - 360, GA); m.quadraticCurveTo(MOUND - 200, GA - 150, MOUND, GA - 170); m.quadraticCurveTo(MOUND + 200, GA - 150, MOUND + 360, GA); m.closePath();+ const mg = m.createLinearGradient(0, GA - 170, 0, GA); mg.addColorStop(0, "#B6865A"); mg.addColorStop(1, "#8A5E3B"); m.fillStyle = mg; m.fill(); m.restore();+ hatch(m, () => { m.beginPath(); m.moveTo(MOUND - 360, GA); m.quadraticCurveTo(MOUND - 200, GA - 150, MOUND, GA - 170); m.quadraticCurveTo(MOUND + 200, GA - 150, MOUND + 360, GA); m.closePath(); }, rad(-40), 6, "#5E3E24", 1, .35, [MOUND - 360, GA - 180, MOUND + 360, GA]);+ for (let i = 0; i < 70; i++) { const a = r2(), x = MOUND - 330 + a * 660, y = GA - Math.sin(a * Math.PI) * 150 + r2() * 30; ellipse(m, x, y, 4 + r2() * 5, 3 + r2() * 3); fill(m, "#E0C49A"); stroke(m, 1.2, "#3B2414"); }+ m.beginPath(); m.moveTo(MOUND - 360, GA); m.quadraticCurveTo(MOUND - 200, GA - 150, MOUND, GA - 170); m.quadraticCurveTo(MOUND + 200, GA - 150, MOUND + 360, GA); stroke(m, 3.4);+ ellipse(m, MOUND, GA - 162, 56, 18); fill(m, "#1E120A"); stroke(m, 3);+ return { hills, mid };+}+// hero on the surface+function heroA(t) {+ if (t < 7.9) return { x: lerp(-200, 930, eOut((t - 7.0) / .9)), walk: true };+ if (t < 10.2) return { x: 930, walk: false, chew: t > 8.35 && t < 9.65 };+ if (t < 14.95) return { x: lerp(930, MOUND - 260, eIO((t - 10.2) / 4.75)), walk: true, leaf: true };+ return { x: lerp(MOUND - 260, MOUND - 60, eIO((t - 14.95) / .45)), walk: true, leaf: true, climb: true };+}+const LEAF_AT = [1260, GA - 6], CUTC = [-190, -20, 78];+function leafAndTrail(ctx, t, S) {+ const h = heroA(t), camX = t < 10.2 ? 0 : clamp(h.x - 760, 0, WA - W), dive = ss(15.35, 15.9, t);+ // sky: morning to gold+ const gold = ss(10.5, 15.4, t), sky = ctx.createLinearGradient(0, 0, 0, GA);+ sky.addColorStop(0, gold < .5 ? "#CFE6EE" : "#F2D9A8"); sky.addColorStop(1, "#F6EEDC"); ctx.fillStyle = sky; ctx.fillRect(0, 0, W, H);+ sun(ctx, 1500 - camX * .05, lerp(180, 260, gold), 90, { rayColor: gold > .5 ? "#E08A3A" : "#D9A035" });+ lightBands(ctx, W, H, t, { alpha: .35 + .2 * gold });+ ctx.drawImage(S.A.hills, -camX * .35, 0);+ ctx.save(); ctx.translate(960, GA - 160); ctx.scale(1 + dive * 2.4, 1 + dive * 2.4); ctx.translate(-960 - (dive ? (MOUND - camX - 960) * dive * .95 : 0), -(GA - 160) + (dive ? 0 : 0));+ ctx.translate(-camX, 0);+ ctx.drawImage(S.A.mid, 0, 0);+ // the fallen leaf: squashed into perspective, with the blue cut-line and the bite that follows it+ const cutP = ss(8.35, 9.65, t), piece = t > 9.65;+ at(ctx, LEAF_AT[0], LEAF_AT[1], 1, 0, () => { ctx.save(); ctx.scale(1, .5); leaf(ctx, 660, { cut: piece ? CUTC : null });+ if (t > 7.95 && !piece) { ctx.save(); ctx.setLineDash([14, 10]); ctx.beginPath(); ctx.arc(CUTC[0], CUTC[1], CUTC[2], 0, Math.PI * 2 * ss(7.95, 8.3, t)); stroke(ctx, 3.4, BLUE); ctx.restore();+ if (cutP > 0) { ctx.beginPath(); ctx.arc(CUTC[0], CUTC[1], CUTC[2], -Math.PI * .5, -Math.PI * .5 + Math.PI * 2 * cutP); stroke(ctx, 5); } }+ ctx.restore(); });+ // leaf bits flying while chewing+ if (h.chew) { const r = rng(Math.floor(t * 12)); for (let i = 0; i < 3; i++) at(ctx, 1080 + r() * 80, GA - 60 - r() * 90, 1, r() * 3, () => { ellipse(ctx, 0, 0, 7, 4); fill(ctx, "#7CC05A"); stroke(ctx, 1.4); }); }+ // the column of leaf-carriers ahead and behind+ if (t > 10.2) for (let k = -2; k <= 4; k++) { if (k === 0) continue; const x = h.x + k * 520 + Math.sin(k) * 60, back = k === -2 || k === 3;+ if (x > MOUND - 300 && !back) continue;+ ant(ctx, back ? h.x + 200 + k * 380 - (t - 10.2) * 380 : x, GA, .95, { flip: back, gait: t * 11 + k, ant: Math.sin(t * 5 + k) * .5, carry: back ? undefined : (c) => at(c, 30, -70, .85 + (k % 2) * .15, -1.25 + k * .06, () => leafPiece(c, 80)) }); }+ // the hero+ const lift = ss(9.65, 10.1, t);+ const climbY = h.climb ? -150 * ss(0, 1, (h.x - (MOUND - 260)) / 200) : 0, sink = ss(15.25, 15.6, t);+ ctx.save(); if (sink > 0) { ctx.beginPath(); ctx.rect(-99999, -99999, 999999, 99999 + GA - 162 + 4); ctx.clip(); }+ ant(ctx, h.x, GA + climbY + sink * 120, 1.1, { gait: h.walk ? t * (h.leaf ? 10 : 12) : undefined, ant: Math.sin(t * 5) * .5 + (h.chew ? .4 : 0), headDip: h.chew ? 10 + Math.sin(t * 30) * 5 : 0, jaw: h.chew ? .5 + .5 * Math.sin(t * 30) : 0,+ rot: h.climb ? -.35 * (1 - sink) : 0, pivot: [0, 0],+ carry: lift > 0 ? (c) => at(c, lerp(40, 30, lift), lerp(10, -70, lift), 1, lerp(0, -1.25, lift), () => leafPiece(c, 80)) : undefined });+ ctx.restore();+ if (t > 9.65 && t < 10.05) burst(ctx, 1100, GA - 230, 60, 100, 9, 3.4, INK, Math.PI * 1.1, Math.PI * .8);+ ctx.restore();+ // foreground grass, fast parallax, soft and dark+ const r = rng(21); ctx.save(); ctx.globalAlpha = .85;+ for (let i = 0; i < (t < 10.2 ? 9 : 26); i++) { const x = ((i * 460 + r() * 200 - camX * 1.35) % (W + 600) + W + 600) % (W + 600) - 300, hh = 180 + r() * 220;+ for (let k = 0; k < 5; k++) { const bx = x + k * 14, lean = (r() - .5) * 60; smooth(ctx, [[bx, H + 20], [bx + lean * .3, H - hh * .6], [bx + lean, H - hh]], false); stroke(ctx, 9, "#2F5A28"); } }+ ctx.restore();+ if (dive > 0) { ctx.save(); ctx.globalAlpha = ss(.55, 1, dive); ctx.fillStyle = "#1E120A"; ctx.fillRect(0, 0, W, H); ctx.restore(); }+}++// ================================================================ 5. COLONY (world B)+const WB = 3800, HB = 2800, GB = 420, ENT = 1900;+const CH = {+ fungus: { x: 1350, y: 1050, rx: 270, ry: 135 }, nursery: { x: 2480, y: 1010, rx: 230, ry: 115 }, queen: { x: 1900, y: 1660, rx: 320, ry: 150 },+ food: { x: 1060, y: 1640, rx: 200, ry: 100 }, cocoons: { x: 2700, y: 1600, rx: 220, ry: 105 }, dig: { x: 2240, y: 2210, rx: 180, ry: 90 }, rest: { x: 1420, y: 2250, rx: 170, ry: 85 },+};+const TUN = [+ [[ENT, GB - 10], [1860, 560], [1940, 720], [1900, 880]], // 0 shaft+ [[1900, 880], [1700, 950], [1560, 1010], [1440, 1080]], // 1 hub → fungus+ [[1900, 880], [2140, 930], [2290, 990], [2380, 1040]], // 2 hub → nursery+ [[1900, 880], [1860, 1160], [1940, 1420], [1900, 1600]], // 3 hub → queen+ [[1620, 1680], [1400, 1680], [1280, 1660], [1140, 1660]], // 4 queen → food+ [[2180, 1690], [2400, 1650], [2520, 1630], [2600, 1620]], // 5 queen → cocoons+ [[2000, 1800], [2100, 1990], [2180, 2130], [2200, 2200]], // 6 queen → dig+ [[1780, 1800], [1600, 2010], [1500, 2170], [1460, 2240]], // 7 queen → rest+];+function buildWorldB() {+ const { canvas, paths } = nestCanvas({ W: WB, H: HB, ground: GB, chambers: Object.values(CH), tunnels: TUN, seed: 11 });+ const x = canvas.getContext("2d");+ for (const [rx, len, sd] of [[700, 520, 3], [3100, 600, 5], [3350, 380, 9], [420, 460, 13]]) roots(x, rx, GB, len, sd, 7);+ // an earthworm in its own pocket+ ellipse(x, 560, 1320, 120, 60); fill(x, "#5A3A22"); const wp = []; for (let i = 0; i <= 20; i++) wp.push([480 + i * 8, 1320 + Math.sin(i * .6) * 22]);+ smooth(x, wp, false); stroke(x, 26); smooth(x, wp, false); stroke(x, 20, "#D98A8A"); for (let i = 2; i < 20; i += 2) line(x, [[wp[i][0], wp[i][1] - 9], [wp[i][0], wp[i][1] + 9]], 1.2, "rgba(120,50,50,.6)");+ // stores and brood that don't move+ const r = rng(4); for (let i = 0; i < 16; i++) at(x, CH.food.x - 120 + (i % 6) * 46 + r() * 10, CH.food.y + 60 - Math.floor(i / 6) * 22, 1.2, r() * .6 - .3, () => seedGrain(x, 1));+ for (let i = 0; i < 7; i++) at(x, CH.cocoons.x - 150 + i * 50, CH.cocoons.y + 50, 1.3, (r() - .5) * .3, () => cocoon(x, 1));+ return { canvas, paths };+}+function sky(ctx, t, x0, w, top, h) { // the surface strip over the nest: day → dusk → night+ const n = ss(23.6, 26.2, t), g = ctx.createLinearGradient(0, top, 0, top + h);+ g.addColorStop(0, n < .5 ? lerpC("#CFE6EE", "#E8A86A", n * 2) : lerpC("#E8A86A", "#1C2458", n * 2 - 1)); g.addColorStop(1, n < .5 ? lerpC("#F6EEDC", "#F2C890", n * 2) : lerpC("#F2C890", "#34306A", n * 2 - 1));+ ctx.fillStyle = g; ctx.fillRect(x0, top, w, h);+ if (n > .6) { const r = rng(5); ctx.save(); ctx.globalAlpha = ss(.6, 1, n); for (let i = 0; i < 60; i++) { const px = x0 + r() * w, py = top + r() * (h - 60); r() > .85 ? star4(ctx, px, py, 9) : (ctx.fillStyle = "#EDEBFF", ctx.beginPath(), ctx.arc(px, py, 1.8, 0, 7), ctx.fill()); } moon(ctx, x0 + w * .75, top + 110, 44); ctx.restore(); }+ else sun(ctx, x0 + w * .72, top + 120 + n * 200, 64, { rays: 12 });+}+function lerpC(a, b, k) { const p = (s) => [1, 3, 5].map((i) => parseInt(s.slice(i, i + 2), 16)); const A = p(a), B = p(b); return `rgb(${A.map((v, i) => Math.round(lerp(v, B[i], clamp(k)))).join(",")})`; }+// camera for the colony: [t, cx, cy, Z]+const CAM = [[15.9, ENT, GB + 60, 2.1], [16.4, ENT, 600, 1.35], [19.6, 1460, 1060, 1.3], [20.2, 1460, 1060, 1.3], [21.1, 2480, 1030, 1.45], [22.4, 2480, 1030, 1.45], [23.2, 1900, 1650, 1.3], [24.1, 1900, 1650, 1.3], [26.3, 1900, 1200, .51], [26.6, 1900, 1200, .51]];+function camAt(t) { for (let i = 0; i < CAM.length - 1; i++) { const [t0, x0, y0, z0] = CAM[i], [t1, x1, y1, z1] = CAM[i + 1]; if (t < t1) { const k = eIO((t - t0) / (t1 - t0)); return [lerp(x0, x1, k), lerp(y0, y1, k), lerp(z0, z1, k)]; } } const l = CAM[CAM.length - 1]; return [l[1], l[2], l[3]]; }+const HERO_B = pathOf([[ENT, GB - 10], [1860, 560], [1940, 720], [1900, 880], [1700, 950], [1560, 1010], [1440, 1080], [1400, 1110]]);+function walker(ctx, p, u, s, t, o = {}) { // an ant walking along a tunnel path at fraction u, facing its travel+ const [x, y, a] = p.at(clamp(u)), back = o.back, ang = back ? a + Math.PI : a, left = Math.cos(ang) < 0;+ ant(ctx, x, y + 14, s, { flip: left, rot: left ? ang - Math.PI : ang, pivot: [0, 0], gait: t * 12 + (o.ph || 0), ant: Math.sin(t * 6 + (o.ph || 0)) * .5, carry: o.carry });+}+function colony(ctx, t, S) {+ const [cx, cy, Z] = camAt(t);+ ctx.fillStyle = "#3E2616"; ctx.fillRect(0, 0, W, H);+ ctx.save(); ctx.translate(960, 540); ctx.scale(Z, Z); ctx.translate(-cx, -cy);+ sky(ctx, t, 0, WB, 0, GB); lightBands(ctx, WB, GB, t, { alpha: .3 * (1 - ss(23.6, 25, t)) });+ ctx.drawImage(S.B.canvas, 0, 0);+ grass(ctx, GB, 0, WB, 26, 7); ellipse(ctx, ENT, GB - 6, 60, 16); fill(ctx, "#1E120A"); stroke(ctx, 3);+ // fungus garden grows when the leaf goes in+ const leafIn = ss(19.6, 20.0, t), grow = .72 + .28 * ss(19.9, 20.8, t);+ at(ctx, CH.fungus.x, CH.fungus.y + CH.fungus.ry * .55, 1, 0, () => fungus(ctx, 440, 150, grow, 4));+ if (t > 19.95) at(ctx, CH.fungus.x - 40, CH.fungus.y + 5, .9, -.3, () => leafPiece(ctx, 70));+ if (t > 19.95 && t < 20.9) { const k = (t - 19.95) / .95, r = rng(2); for (let i = 0; i < 10; i++) { const a = r() * Math.PI * 2, d = 60 + k * 140; star4(ctx, CH.fungus.x + Math.cos(a) * d, CH.fungus.y - 30 + Math.sin(a) * d * .5, 10 * (1 - k), "#FFF6C8"); } }+ // nursery: eggs, wriggling larvae, a nurse+ const N = CH.nursery; for (let i = 0; i < 9; i++) at(ctx, N.x - 160 + (i % 5) * 26 + (i > 4 ? 13 : 0), N.y + 70 - (i > 4 ? 22 : 0), 1.3, 0, () => egg(ctx, 1));+ for (let i = 0; i < 4; i++) at(ctx, N.x + 10 + i * 50, N.y + 62, 1.25, (i % 2 ? -.3 : .2), () => larva(ctx, 1, Math.sin(t * 5 + i)));+ ant(ctx, N.x - 10, N.y + 100, .55, { flip: true, headDip: 10 + Math.sin(t * 3) * 6, ant: Math.sin(t * 6) * .6, jaw: .3 + .3 * Math.sin(t * 7) });+ // queen: laying, attended+ const Q = CH.queen, layK = ss(23.3, 23.7, t);+ ant(ctx, Q.x + 60, Q.y + 118, .82, { gaster: 1.8, ant: Math.sin(t * 2) * .3, blink: (t % 3.6) < .12 });+ for (let i = 0; i < 5; i++) at(ctx, Q.x - 250 + i * 26, Q.y + 118 - 10, 1.2, 0, () => egg(ctx, 1));+ if (layK > 0) at(ctx, lerp(Q.x - 130, Q.x - 120, layK), Q.y + 108, 1.2 * eBack(layK), 0, () => egg(ctx, 1));+ if (t > 23.65 && t < 24.0) burst(ctx, Q.x - 120, Q.y + 90, 30, 55, 8, 2.6, "#FFF6C8");+ ant(ctx, Q.x + 250, Q.y + 118, .5, { flip: true, headDip: 6, ant: Math.sin(t * 5) * .7 }); ant(ctx, Q.x - 60, Q.y + 70, .45, { ant: Math.sin(t * 5 + 2) * .7, headDip: 8 });+ // the digger, the sleepers+ const D = CH.dig; ant(ctx, D.x + 60, D.y + 80, .5, { headDip: 14, gait: t * 20, ant: .6, jaw: .5 + .5 * Math.sin(t * 20) }); { const r = rng(Math.floor(t * 8)); for (let i = 0; i < 3; i++) { ellipse(ctx, D.x + 130 + r() * 50, D.y + 20 - r() * 60, 6, 5); fill(ctx, "#8C5E3D"); stroke(ctx, 1.4); } }+ const R = CH.rest; ant(ctx, R.x - 50, R.y + 75, .45, { blink: true, headDip: 10, ant: -.8 }); ant(ctx, R.x + 70, R.y + 75, .45, { flip: true, blink: true, headDip: 10, ant: -.8 });+ // traffic in the tunnels+ S.B.paths.forEach((p, i) => { if (i === 0 && t < 20) return; for (let k = 0; k < 2; k++) { const sp = .11 + (i % 3) * .03, u = (t * sp + k * .5 + i * .17) % 1, back = k === 1; walker(ctx, p, back ? 1 - u : u, .4, t, { back, ph: i + k }); } });+ // the hero: down the shaft with the leaf, into the garden+ const hu = clamp((t - 16.0) / 3.6);+ if (t < 20.0) { const [x, y, a] = HERO_B.at(eIO(hu)), left = Math.cos(a) < 0, done = hu >= 1;+ ant(ctx, x, y + 14, .55, { flip: left, rot: done ? 0 : (left ? a - Math.PI : a), pivot: [0, 0], gait: done ? undefined : t * 12, ant: Math.sin(t * 5) * .5,+ carry: leafIn < 1 ? (c) => at(c, 30, -70, 1 - leafIn, -1.25, () => leafPiece(c, 80)) : undefined }); }+ else ant(ctx, 1450, 1112, .55, { flip: true, ant: Math.sin(t * 5) * .6, headDip: 6 });+ ctx.restore();+ // the magnifier on the nursery: a larva being fed, drawn big in its own circle+ const mg = ss(21.2, 21.5, t) * (1 - ss(22.7, 23.0, t));+ if (mg > 0) { const mx = 1460, my = 330, R2 = 190 * eBack(mg);+ ctx.save(); ctx.beginPath(); ctx.arc(mx, my, R2, 0, Math.PI * 2); ctx.fillStyle = "#E9C08E"; ctx.fill(); ctx.clip();+ const cg = ctx.createRadialGradient(mx, my - 60, 20, mx, my, R2); cg.addColorStop(0, "#F6D8AA"); cg.addColorStop(1, "#B98C62"); ctx.fillStyle = cg; ctx.fillRect(mx - R2, my - R2, R2 * 2, R2 * 2);+ at(ctx, mx - 30, my + 40, 3.2, .1, () => larva(ctx, 1, Math.sin(t * 5))); ant(ctx, mx + 170, my + 150, 1.0, { flip: true, headDip: 16, jaw: .5 + .5 * Math.sin(t * 8), ant: .7 });+ at(ctx, mx + 20, my - 10, 1.6, 0, () => drop(ctx, .8, "#F7E6A8")); ctx.restore();+ ctx.beginPath(); ctx.arc(mx, my, R2, 0, Math.PI * 2); stroke(ctx, 8, "#EDE6D8"); ctx.beginPath(); ctx.arc(mx, my, R2 + 5, 0, Math.PI * 2); stroke(ctx, 3);+ const [ccx, ccy, cz] = camAt(t), sx = 960 + (N.x + 40 - ccx) * cz, sy = 540 + (N.y + 60 - ccy) * cz; line(ctx, [[mx + R2 * .7, my + R2 * .7], [sx, sy]], 2.4, "rgba(237,230,216,.9)"); }+ // the dive lands: fade up from the dark of the hole+ if (t < 16.25) { ctx.save(); ctx.globalAlpha = 1 - ss(15.9, 16.25, t); ctx.fillStyle = "#1E120A"; ctx.fillRect(0, 0, W, H); ctx.restore(); }+ if (t > 26.3) { ctx.save(); ctx.globalAlpha = ss(26.3, 26.6, t); ctx.fillStyle = "#F3EEDD"; ctx.fillRect(0, 0, W, H); ctx.restore(); }+}++// ================================================================ 6. END CARD+function endCard(ctx, t, S) {+ ctx.drawImage(S.paper, 0, 0); lightBands(ctx, W, H, t, { alpha: .5 });+ typed(ctx, "Every frame is code.", 960, 330, 26.75, 27.4, t, { font: "112px IBold", align: "center" });+ const k1 = popS(t, 27.55, .35, 1.6); if (k1 > 0) at(ctx, 960, 470, k1, 0, () => { ctx.font = "84px IBold"; ctx.textAlign = "center"; ctx.fillStyle = BLUE; ctx.fillText("claude-animation", 0, 0); ctx.textAlign = "left"; });+ const k2 = popS(t, 27.85, .3, 1.6); if (k2 > 0) at(ctx, 960, 560, k2, 0, () => { ctx.font = "44px ISemi"; ctx.textAlign = "center"; ctx.fillStyle = "rgba(30,22,18,.75)"; ctx.fillText(`rendered in ${RENDER_SECONDS} seconds · every sound synthesised · open source`, 0, 0); ctx.textAlign = "left"; });+ codeChip(ctx, "github.com/buildwithhanif/claude-animation-skill", 960, 690, 28.3, 29.4, t, 34, "center");+ const GY = 960; line(ctx, [[0, GY], [W, GY]], 3); grass(ctx, GY, 0, W, 20, 4);+ ant(ctx, lerp(-300, 2200, clamp((t - 26.7) / 5.2)), GY, .95, { gait: t * 10, ant: Math.sin(t * 5) * .5, carry: (c) => at(c, 30, -70, 1, -1.25, () => leafPiece(c, 80)) });+ ctx.save(); ctx.font = "30px ISemi"; ctx.fillStyle = "rgba(30,22,18,.55)"; ctx.textAlign = "right"; ctx.fillText("@hanifproduktif", 1880, 1050); ctx.restore();+}++// ================================================================ sound cues from this timeline+function cues() {+ const Q = [], add = (sfx, t, vol = .45, o = {}) => Q.push({ sfx, t: +(t - .03).toFixed(3), vol, ...o });+ for (let i = 0; i < 13; i++) add("click", .12 + i * (.58 / 13), .22, { pitch: 1 + (i % 3) * .08 });+ for (let i = 0; i < 18; i++) add("click", .6 + i * (.9 / 18), .14, { pitch: .9 });+ add("click", .8, .5, { pitch: .6 }); add("click", 1.45, .4, { pitch: .7 });+ add("whoosh", 2.1, .55, { dur: .45 }); add("thump", 2.2, .5);+ for (let i = 0; i < 6; i++) add("tick", 2.3 + i * .12, .3, { pitch: 1 + i * .06 });+ SWEEP.forEach((s, i) => { add("whip", s, .35, { dur: .4 }); add("pop", s + SW * .5, .45, { pitch: 1 + i * .12 }); });+ add("sparkle", 5.45, .5); for (let t = 6.25; t < 7; t += .09) add("step", t, .2, { pan: .3 });+ add("whoosh", 6.95, .45);+ for (let t = 7.0; t < 7.9; t += .09) add("step", t, .16, { pan: -.3 });+ add("tick", 7.95, .35); add("drip", 8.1, .25);+ for (let t = 8.35; t < 9.65; t += .075) add("click", t, .22, { pitch: .55 + (Math.floor(t * 40) % 3) * .08 });+ add("scratch", 9.6, .45); add("pop", 9.68, .5); add("sparkle", 9.75, .35);+ for (let t = 10.2; t < 15.3; t += .1) add("step", t, .14, { pan: Math.sin(t) * .3 });+ add("riser", 14.0, .3, { dur: 1.4 }); add("whoosh", 15.35, .6, { dur: .6 }); add("thump", 15.9, .45);+ for (let t = 16.1; t < 19.6; t += .11) add("step", t, .12);+ add("pop", 19.62, .45); add("sparkle", 19.95, .5); add("chime", 20.1, .3);+ add("whoosh", 20.25, .35); add("pop", 21.2, .45); add("drip", 21.6, .3); add("drip", 22.1, .25);+ add("whoosh", 22.45, .3); add("pop", 23.5, .5, { pitch: 1.2 }); add("sparkle", 23.65, .35);+ add("riser", 24.2, .3, { dur: 1.8 }); add("chime", 25.8, .45); add("sparkle", 26.0, .3);+ add("whoosh", 26.5, .4);+ for (let i = 0; i < 20; i++) add("click", 26.75 + i * .032, .16);+ add("pop", 27.55, .45); add("pop", 27.85, .35); for (let i = 0; i < 24; i++) add("click", 28.3 + i * .045, .13);+ add("chime", 30.6, .5);+ return Q;+}+if (process.argv[2] === "cues") { const q = cues(); fs.writeFileSync(path.join(HERE, "cues.json"), JSON.stringify(q)); console.log("wrote cues.json", q.length, "cues"); process.exit(0); }++run({+ name: "ant-colony", W, H, fps: FPS, dur: DUR, out: path.join(HERE, "out"),+ setup() { return { paper: paper(W, H), A: buildWorldA(), B: buildWorldB() }; },+ frame(ctx, t, i, S) {+ if (t < CUT.process) hook(ctx, t, S); else if (t < CUT.leaf) process_(ctx, t, S); else if (t < CUT.colony) leafAndTrail(ctx, t, S); else if (t < CUT.end) colony(ctx, t, S); else endCard(ctx, t, S);+ },+});diff --git a/examples/ant-colony/make.sh b/examples/ant-colony/make.shnew file mode 100755index 0000000..b73b215--- /dev/null+++ b/examples/ant-colony/make.sh@@ -0,0 +1,12 @@+#!/bin/bash+# make.sh — render the colony film, measure the render, then music + synthesised SFX -> out/ant-colony-final.mp4+set -e+cd "$(dirname "$0")"+SK=../../plugins/claude-animation/skills/claude-animation+node film.mjs verify+node film.mjs render+N=$(node -e 'console.log(Math.round(require("./out/ant-colony.render.json").seconds))')+RENDER_SECONDS=$N node film.mjs render # the end card states the real render time+node film.mjs cues+node $SK/scripts/music.mjs out/bed.wav --dur 29.8 --bpm 104 --quiet 13.1-13.8 --end 28.4+node $SK/scripts/sound.mjs cues.json out/ant-colony.mp4 out/ant-colony-final.mp4 --bed out/bed.wav --bed-vol .5 --bed-at 2.2 --lufs -14diff --git a/plugins/claude-animation/.claude-plugin/plugin.json b/plugins/claude-animation/.claude-plugin/plugin.jsonnew file mode 100644index 0000000..efe796d--- /dev/null+++ b/plugins/claude-animation/.claude-plugin/plugin.json@@ -0,0 +1,11 @@+{+ "name": "claude-animation",+ "displayName": "Claude Animation",+ "description": "Hand-drawn 2D animation written as code. Textured-editorial and brush-watercolour looks, a detailed poseable ant, an ant colony kit, a render harness with sheet/strip/verify, and synthesised sound.",+ "version": "1.0.0",+ "author": { "name": "Hanif", "url": "https://github.com/buildwithhanif" },+ "homepage": "https://github.com/buildwithhanif/claude-animation-skill",+ "repository": "https://github.com/buildwithhanif/claude-animation-skill",+ "license": "MIT",+ "keywords": ["animation", "2d", "hand-drawn", "canvas", "javascript", "ffmpeg"]+}diff --git a/plugins/claude-animation/skills/claude-animation/SKILL.md b/plugins/claude-animation/skills/claude-animation/SKILL.mdnew file mode 100644index 0000000..85e1f95--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/SKILL.md@@ -0,0 +1,87 @@+---+name: claude-animation+description: Make short hand-drawn 2D animations entirely in JavaScript — storybook / textured-editorial illustration (paper grain, hatching, blue construction guides, glossy insect characters, nest cross-sections) and brush-ink + watercolour explainers — rendered frame-exact with node canvas and ffmpeg, with synthesised sound. Use for "bikin animasi", "animate this story", "hand-drawn animation", "storybook animation", "JS animation", "line drawing animation", "animasi semut", kids' story or science explainer animations. Not for UI micro-interactions, slide decks, or talking-head video editing.+---++# claude-animation++**Frame-exact, hand-drawn-looking 2D animation written as code.** A film is a pure function+`frame(ctx, t)`; the library draws the look (brush, pencil, watercolour, grain, hatching), the rigs act+(a detailed ant, a bean-bodied cast), and the harness renders, previews and checks it.++Every rule below is something that went wrong on a real film — a 59 s brush-ink + watercolour history+recap and a set of storybook insect films — and took a render to find.++## Read first++| I need to… | Go to |+|---|---|+| Make an original animation from a brief | `references/workflow.md` → `templates/beat-sheet.md` → `templates/film-template.mjs` |+| **Make it more detailed** (materials, textures, characters) | `references/detail.md` — the detail bible. Read it before drawing any surface |+| Draw / pose / walk the ant, or build a new creature rig | `references/characters.md`, `lib/rigs/ant.mjs` |+| A colony: leaves, brood, fungus, roots, a nest cross-section with walkable tunnels | `lib/colony.mjs` |+| People (bean body, stick limbs, watercolour) | `lib/rigs/bean.mjs` |+| Timing, acting, cuts, camera, transitions | `references/motion.md` |+| Pick or match a look (editorial-texture, brush-watercolour, line-doodle, 3D type) | `references/styles.md` |+| Sound: SFX from the picture's timeline, a synthesised bed, loudness | `references/sound.md`, `scripts/sound.mjs`, `scripts/music.mjs` |+| Something broke | `references/traps.md` |+| What other animation skills do, and what we took | `references/prior-art.md` |++## The library (`lib/`)++| file | gives you |+|---|---|+| `core.mjs` | easing (`eOut eIn eIO eBack eElastic eBounce eExpo popS`), `ss` windows, `hash rng noise1`, `catmull pathOf ik`, canvas helpers (`at line poly smooth ellipse stroke fill taper`), texture (`hatch fibre grainOver burst speedLines`) |+| `pen.mjs` | `Pen`: tapered brush `stroke`, `pencil` (3 broken passes), `ring`, `box` (overshooting corners), `wash` (blooming watercolour), `text` (writes itself), reveal-in-order, **stable named seeds**, opt-in boil |+| `textures.mjs` | `paper fibrePaper lightBands sun moon star4 grass soil nightSky fleshCells filmFinish` |+| `nature.mjs` | `sprout melonLeaf tendril vine blossom bee drop` |+| `rigs/ant.mjs` | `ant(ctx, x, groundY, s, pose)` — the detailed ant (`pose.look` = ink / fill / tex layers for build-up reveals); `antGuides()` blue construction lines; `seed()` |+| `colony.mjs` | `leaf leafPiece egg larva cocoon seedGrain fungus roots nestCanvas` (chambers + tunnels baked into soil, returns `pathOf` walkers) |+| `rigs/bean.mjs` | `person bust bubble flagCloth hat SKIN` |+| `film.mjs` | `run({...})` → `render / sheet / strip / verify`; `exposure(t, track, fps)` for ones / twos / holds |++Install once per machine: `cd <skill dir> && npm install` (only dependency: `@napi-rs/canvas`). ffmpeg on PATH.++## The loop++```+brief ─▶ style bible + beat sheet ─▶ film.mjs (copy the template) ─▶ sheet ─▶ fix ─▶ strip the fast bits+ ─▶ verify ─▶ render ─▶ cues.json ─▶ sound.mjs ─▶ look at the master's contact sheet ─▶ deliver+```+++## Hard rules++1. **Beats before code.** Fill `templates/beat-sheet.md`: every beat has an end state the viewer could+ point at, a camera, an exposure and a sound cue. Designing inside the code makes slides.+2. **Every surface gets three layers: base → texture → edge.** A flat fill is unfinished. The detail bible+ lists the texture for each material (fruit = packed cells + seeds with highlights, soil = hatch + strata ++ pebbles, chitin = gradient + form hatch + specular streak + rim light + setae…).+3. **Characters are rigs with anatomy, not blobs.** Use `lib/rigs/ant.mjs` for insects; its local origin is+ the ground under the waist, so `ant(ctx, x, groundY, …)` always stands on the ground. Never add a+ per-call "ground" offset (that exact knob produced stilt legs for two passes).+4. **Boil is a decision, not a default.** The textured-editorial look holds still shots perfectly still;+ the brush-watercolour look boils at 10 fps. Write the choice in the style bible.+5. **Stable seeds.** Marks are seeded from a name (`pen.begin("ant/body")`), never from the frame index, so+ a held drawing keeps its marks and a re-render is identical. `node film.mjs verify` must pass.+6. **Look at pixels, every pass.** `sheet` before `render`, `strip` around every contact or fast action,+ and a contact sheet of the encoded master before you call it done. A render that exits 0 proves nothing.+7. **Sound comes from the picture's timeline**, ~0.03 s before each contact. No continuous pencil-scratch+ bed (tested, rejected: it fights everything). Loudnorm the mix.+8. **Show the world, not a slide.** A setting needs layers (sky, far, mid, ground, foreground passing+ the camera), and a place needs inhabitants doing things. The camera moves through it.++## Quick start++```bash+SK=~/.claude/skills/claude-animation # wherever this skill lives+mkdir my-film && cd my-film && cp $SK/templates/film-template.mjs film.mjs+CLAUDE_ANIMATION_LIB=$SK/lib node film.mjs sheet 0,1,2,3,4 # look+CLAUDE_ANIMATION_LIB=$SK/lib node film.mjs render # out/template.mp4+node $SK/scripts/music.mjs bed.wav --dur 5 --end 4.4+node $SK/scripts/sound.mjs cues.json out/template.mp4 out/final.mp4 --bed bed.wav+```++Worked film in the repo: `examples/ant-colony/` — 32 s, 16:9: a sketch → ink → colour → polish build-up,+a leafcutter cutting and carrying a leaf through a meadow, a dive into a nest cross-section (fungus garden,+nursery, queen, stores, tunnels full of traffic), 240 sound cues from the timeline; renders in ~27 s.diff --git a/plugins/claude-animation/skills/claude-animation/lib/colony.mjs b/plugins/claude-animation/skills/claude-animation/lib/colony.mjsnew file mode 100644index 0000000..0c15fa4--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/colony.mjs@@ -0,0 +1,87 @@+// colony.mjs — an ant colony in cross-section, and what a leafcutter carries into it.+// Everything draws at the current transform (place with at()). All in the textured-editorial style:+// base → texture → edge on every surface (references/detail.md).+import { clamp, lerp, rad, rng, hash, ellipse, stroke, fill, line, poly, smooth, hatch, at, pathOf, INK, createCanvas, grainCanvas } from "./core.mjs";++// ---------------------------------------------------------------- leaves+// a broad leaf lying flat, seen from the side-above: serrated edge, midrib, side veins, hatch+export function leaf(ctx, len = 600, { color = "#6DB352", cut = null } = {}) {+ const P = []; for (let i = 0; i <= 80; i++) { const u = i / 80, a = u * Math.PI * 2, x = Math.cos(a) * len / 2, w = Math.sin(a) * len * .2 * (1 - .25 * Math.cos(a));+ const serr = (i % 4 < 2 ? 1 : .94); P.push([x, w * serr]); }+ ctx.save(); poly(ctx, P);+ if (cut) { ctx.clip(); ctx.beginPath(); ctx.rect(-len, -len, len * 2, len * 2); ctx.arc(cut[0], cut[1], cut[2], 0, Math.PI * 2, true); ctx.clip(); poly(ctx, P); }+ const g = ctx.createLinearGradient(0, -len * .2, 0, len * .2); g.addColorStop(0, "#8CCB6A"); g.addColorStop(1, "#4E9A42"); fill(ctx, g);+ hatch(ctx, () => poly(ctx, P), rad(35), 6, "#3E8A3A", 1, .4, [-len / 2, -len * .25, len / 2, len * .25]);+ line(ctx, [[-len / 2 + 10, 0], [len / 2 - 8, 0]], 4, "#3D7A34"); for (let i = 1; i < 8; i++) { const x = -len / 2 + i * len / 8; line(ctx, [[x, 0], [x + len * .07, -len * .13]], 1.8, "#CFE8B4"); line(ctx, [[x, 0], [x + len * .07, len * .13]], 1.8, "#CFE8B4"); }+ poly(ctx, P); stroke(ctx, 3);+ if (cut) { ctx.beginPath(); ctx.arc(cut[0], cut[1], cut[2], 0, Math.PI * 2); stroke(ctx, 3); }+ ctx.restore();+}+// the half-moon piece a leafcutter carries; `bite` 0..1 nibbles its straight edge+export function leafPiece(ctx, r = 70) {+ const P = []; for (let i = 0; i <= 30; i++) { const a = Math.PI + i / 30 * Math.PI; P.push([Math.cos(a) * r, Math.sin(a) * r * .9]); }+ for (let i = 0; i <= 10; i++) P.push([r - i * r * .2, (i % 2 ? 6 : 0)]);+ const g = ctx.createLinearGradient(0, -r, 0, 0); g.addColorStop(0, "#9AD47A"); g.addColorStop(1, "#58A74A"); poly(ctx, P); fill(ctx, g);+ hatch(ctx, () => poly(ctx, P), rad(35), 5, "#3E8A3A", 1, .45, [-r, -r, r, 4]);+ line(ctx, [[0, 0], [0, -r * .85]], 2.6, "#3D7A34"); line(ctx, [[0, -r * .3], [-r * .45, -r * .6]], 1.4, "#CFE8B4"); line(ctx, [[0, -r * .3], [r * .45, -r * .6]], 1.4, "#CFE8B4");+ poly(ctx, P); stroke(ctx, 2.8);+}++// ---------------------------------------------------------------- brood+export function egg(ctx, s = 1) { ctx.save(); ctx.scale(s, s); ellipse(ctx, 0, 0, 9, 13); const g = ctx.createRadialGradient(-3, -5, 1, 0, 0, 14); g.addColorStop(0, "#FFFFFF"); g.addColorStop(1, "#E6E0D0"); fill(ctx, g); stroke(ctx, 1.8); ellipse(ctx, -3, -5, 2.4, 3.4); fill(ctx, "#fff"); ctx.restore(); }+// a C-shaped grub; wiggle 0..1 animates it+export function larva(ctx, s = 1, wiggle = 0) {+ ctx.save(); ctx.scale(s, s); const P = [], Q = []; for (let i = 0; i <= 12; i++) { const a = Math.PI * (.2 + i / 12 * 1.4) + wiggle * .15 * Math.sin(i), r = 22 + wiggle * 2; P.push([Math.cos(a) * r, Math.sin(a) * r]); Q.push([Math.cos(a) * (r - 13 + i * .4), Math.sin(a) * (r - 13 + i * .4)]); }+ const S = [...P, ...Q.reverse()]; poly(ctx, S); const g = ctx.createLinearGradient(-20, -20, 20, 20); g.addColorStop(0, "#FFFDF6"); g.addColorStop(1, "#E3DAC4"); fill(ctx, g);+ for (let i = 1; i < 12; i++) { const a = Math.PI * (.2 + i / 12 * 1.4); line(ctx, [[Math.cos(a) * 9.5, Math.sin(a) * 9.5], [Math.cos(a) * 22, Math.sin(a) * 22]], 1, "rgba(120,100,70,.55)"); }+ poly(ctx, S); stroke(ctx, 2); const h = P[P.length - 1]; ellipse(ctx, h[0], h[1], 5, 5); fill(ctx, "#C8A878"); stroke(ctx, 1.4); ctx.restore();+}+export function cocoon(ctx, s = 1) { ctx.save(); ctx.scale(s, s); ellipse(ctx, 0, 0, 14, 26); const g = ctx.createLinearGradient(-14, 0, 14, 0); g.addColorStop(0, "#E8D2A6"); g.addColorStop(1, "#B8966A"); fill(ctx, g);+ for (let i = -2; i <= 2; i++) line(ctx, [[-12, i * 9], [12, i * 9 + 3]], 1, "rgba(110,80,40,.5)"); ellipse(ctx, 0, 0, 14, 26); stroke(ctx, 2); ellipse(ctx, -5, -10, 3, 7); fill(ctx, "rgba(255,255,255,.6)"); ctx.restore(); }+export function seedGrain(ctx, s = 1, r = 0) { at(ctx, 0, 0, s, r, () => { ellipse(ctx, 0, 0, 16, 9); fill(ctx, "#C9A45E"); line(ctx, [[-10, -2], [8, -4]], 1.6, "rgba(255,255,255,.6)"); ellipse(ctx, 0, 0, 16, 9); stroke(ctx, 1.8); }); }++// ---------------------------------------------------------------- fungus garden: a spongy white mass that grows+export function fungus(ctx, w, h, grow = 1, seed = 4) {+ const r = rng(seed), n = Math.round(46 * clamp(grow)); ctx.save();+ for (let i = 0; i < n; i++) { const x = (r() - .5) * w, y = -Math.abs(r()) * h * Math.sqrt(1 - Math.pow(2 * x / w, 2)), rr = 16 + r() * 22;+ ellipse(ctx, x, y, rr, rr * .8); const g = ctx.createRadialGradient(x - rr * .3, y - rr * .3, 1, x, y, rr); g.addColorStop(0, "#FFFFFF"); g.addColorStop(1, "#DCD6C8"); fill(ctx, g); stroke(ctx, 1.4, "#8C8472");+ for (let k = 0; k < 3; k++) { ellipse(ctx, x + (r() - .5) * rr, y + (r() - .5) * rr * .6, 1.6, 1.6); fill(ctx, "#A89E86"); } }+ ctx.restore();+}++// ---------------------------------------------------------------- roots hanging from the surface+export function roots(ctx, x, y, len, seed = 1, w = 7) {+ const r = rng(seed); const branch = (x0, y0, L, a, ww, d) => { if (d > 3 || L < 30) return; const pts = [[x0, y0]]; let px = x0, py = y0, ang = a;+ for (let i = 0; i < 8; i++) { ang += (r() - .5) * .35; px += Math.cos(ang) * L / 8; py += Math.sin(ang) * L / 8; pts.push([px, py]); }+ smooth(ctx, pts, false); stroke(ctx, ww + 2.4); smooth(ctx, pts, false); stroke(ctx, ww, "#C9A77A");+ for (let i = 2; i < pts.length; i += 2) for (let k = 0; k < 3; k++) { const [hx, hy] = pts[i], ha = r() * Math.PI * 2; line(ctx, [[hx, hy], [hx + Math.cos(ha) * 10, hy + Math.sin(ha) * 10]], .9, "rgba(220,200,160,.8)"); }+ for (let i = 3; i < pts.length - 1; i += 3) branch(pts[i][0], pts[i][1], L * .5, ang + (r() > .5 ? .7 : -.7), ww * .6, d + 1); };+ branch(x, y, len, Math.PI / 2, w, 0);+}++// ---------------------------------------------------------------- the nest: chambers and tunnels baked into a soil canvas+// spec: { W, H, ground, chambers: [{ id, x, y, rx, ry }], tunnels: [[[x,y],...], ...], seed }+// returns { canvas, paths } — paths are pathOf() samplers for walking ants along each tunnel+export function nestCanvas(spec) {+ const { W, H, ground, chambers, tunnels, seed = 7 } = spec, c = createCanvas(W, H), x = c.getContext("2d"), r = rng(seed);+ // soil: base gradient deeper = darker, grain, hatch, strata, pebbles, specks+ const g = x.createLinearGradient(0, ground, 0, H); g.addColorStop(0, "#7A5234"); g.addColorStop(1, "#3E2616"); x.fillStyle = g; x.fillRect(0, ground, W, H - ground);+ x.globalCompositeOperation = "multiply"; x.globalAlpha = .5; x.fillStyle = x.createPattern(grainCanvas(256, 80, 13), "repeat"); x.fillRect(0, ground, W, H - ground); x.globalCompositeOperation = "source-over"; x.globalAlpha = 1;+ hatch(x, () => { x.beginPath(); x.rect(0, ground, W, H - ground); }, rad(-30), 8, "#2A180C", 1, .25, [0, ground, W, H]);+ x.strokeStyle = "rgba(210,170,120,.25)"; x.lineWidth = 2; for (let yy = ground + 220; yy < H; yy += 260 + r() * 120) { x.beginPath(); for (let px = 0; px <= W; px += 40) { const py = yy + Math.sin(px * .004 + yy) * 18 + Math.sin(px * .017) * 6; px ? x.lineTo(px, py) : x.moveTo(px, py); } x.stroke(); }+ for (let i = 0; i < W * (H - ground) / 9000; i++) { const px = r() * W, py = ground + 30 + r() * (H - ground - 30), s = r();+ if (s > .92) { ellipse(x, px, py, 14 + r() * 20, 10 + r() * 12, r() * 3); fill(x, s > .97 ? "#8C7E70" : "#A08262"); stroke(x, 2, "#2A180C"); }+ else { x.fillStyle = s > .6 ? "rgba(230,200,160,.45)" : "rgba(30,15,8,.5)"; x.beginPath(); x.arc(px, py, 1 + s * 2.5, 0, 7); x.fill(); } }+ // tunnels first (so chambers sit on top), then chambers: warm lit interiors with a darker rim and a floor+ const T = tunnels.map((p) => pathOf(p));+ for (const t of T) { const pts = t.points; smooth(x, pts, false); stroke(x, 58, "#2A180C"); smooth(x, pts, false); stroke(x, 50, "#B98C62"); smooth(x, pts, false); stroke(x, 26, "rgba(236,200,150,.35)"); }+ for (const ch of chambers) { const { x: cx, y: cy, rx, ry } = ch;+ ellipse(x, cx, cy, rx + 6, ry + 6); fill(x, "#2A180C");+ ellipse(x, cx, cy, rx, ry); const cg = x.createRadialGradient(cx, cy - ry * .3, rx * .1, cx, cy, rx * 1.05); cg.addColorStop(0, "#F0CC98"); cg.addColorStop(.7, "#C9976A"); cg.addColorStop(1, "#8E6342"); fill(x, cg);+ hatch(x, () => ellipse(x, cx, cy, rx, ry), rad(20), 7, "#8E6342", 1, .3, [cx - rx, cy - ry, cx + rx, cy + ry]);+ x.save(); ellipse(x, cx, cy, rx, ry); x.clip(); x.fillStyle = "rgba(120,80,45,.55)"; x.fillRect(cx - rx, cy + ry * .55, rx * 2, ry); x.restore(); // floor+ ellipse(x, cx, cy, rx, ry); stroke(x, 3.4); }+ // the surface line+ x.fillStyle = "#6E4A2C"; x.fillRect(0, ground - 2, W, 8); line(x, [[0, ground], [W, ground]], 3.4);+ return { canvas: c, paths: T };+}diff --git a/plugins/claude-animation/skills/claude-animation/lib/core.mjs b/plugins/claude-animation/skills/claude-animation/lib/core.mjsnew file mode 100644index 0000000..b317cff--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/core.mjs@@ -0,0 +1,116 @@+// core.mjs — maths, easing, noise, path helpers and the two textures everything uses (grain, hatch).+// Pure functions of their inputs: no Math.random, no Date. Same frame in, same pixels out.+import { createCanvas, Path2D } from "@napi-rs/canvas";+export { createCanvas, Path2D };++// ------------------------------------------------------------------ numbers+export const clamp = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x));+export const lerp = (a, b, k) => a + (b - a) * k;+export const rad = (d) => d * Math.PI / 180;+export const ss = (a, b, x) => { const k = clamp((x - a) / (b - a)); return k * k * (3 - 2 * k); }; // smoothstep window+export const hash = (n) => { const x = Math.sin(n * 127.1 + 311.7) * 43758.5453; return x - Math.floor(x); };+export const rng = (seed) => { let s = Math.max(1, Math.floor(seed)) % 2147483647; return () => (s = (s * 16807) % 2147483647) / 2147483647; };+export const noise1 = (x) => { const i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f); return (hash(i) * (1 - u) + hash(i + 1) * u) * 2 - 1; };++// ------------------------------------------------------------------ easing (k in 0..1)+export const eOut = (k) => 1 - Math.pow(1 - clamp(k), 3);+export const eIn = (k) => Math.pow(clamp(k), 3);+export const eIO = (k) => { k = clamp(k); return k < .5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2; };+export const eExpo = (k) => (k = clamp(k), k === 1 ? 1 : 1 - Math.pow(2, -10 * k));+export const eBack = (k, s = 1.8) => { k = clamp(k) - 1; return 1 + (s + 1) * k * k * k + s * k * k; }; // overshoot, settles at 1+export const eElastic = (k) => { k = clamp(k); return k === 0 || k === 1 ? k : Math.pow(2, -10 * k) * Math.sin((k * 10 - .75) * (2 * Math.PI / 3)) + 1; };+export const eBounce = (k) => { k = clamp(k); const n = 7.5625, d = 2.75;+ if (k < 1 / d) return n * k * k; if (k < 2 / d) return n * (k -= 1.5 / d) * k + .75;+ if (k < 2.5 / d) return n * (k -= 2.25 / d) * k + .9375; return n * (k -= 2.625 / d) * k + .984375; };+// a pop-in scale that overshoots: 0 before t0, ~1.1 at the peak, 1 after `d` seconds+export const popS = (t, t0, d = .38, s = 2.2) => t < t0 ? 0 : eBack((t - t0) / d, s);++// ------------------------------------------------------------------ geometry+export const mid = (a, b) => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];+export const centroid = (P) => [P.reduce((s, p) => s + p[0], 0) / P.length, P.reduce((s, p) => s + p[1], 0) / P.length];+export const ellPts = (cx, cy, rx, ry, n = 24, a0 = 0) => Array.from({ length: n }, (_, i) => { const a = a0 + i / n * Math.PI * 2; return [cx + Math.cos(a) * rx, cy + Math.sin(a) * ry]; });+export const rrect = (x, y, w, h, r) => { const p = [], k = [[x + w - r, y + r, -90], [x + w - r, y + h - r, 0], [x + r, y + h - r, 90], [x + r, y + r, 180]];+ for (const [cx, cy, a0] of k) for (let i = 0; i <= 4; i++) { const a = rad(a0 + i * 22.5); p.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]); } return p; };+export function catmull(P, closed = false, step = 7) { // dense points through control points+ const out = [], n = P.length, g = (i) => closed ? P[(i + n) % n] : P[clamp(i, 0, n - 1)];+ for (let i = 0; i < (closed ? n : n - 1); i++) {+ const p0 = g(i - 1), p1 = g(i), p2 = g(i + 1), p3 = g(i + 2), m = Math.max(2, Math.ceil(Math.hypot(p2[0] - p1[0], p2[1] - p1[1]) / step));+ for (let s = 0; s < m; s++) { const t = s / m, t2 = t * t, t3 = t2 * t;+ out.push([0, 1].map((c) => .5 * (2 * p1[c] + (-p0[c] + p2[c]) * t + (2 * p0[c] - 5 * p1[c] + 4 * p2[c] - p3[c]) * t2 + (-p0[c] + 3 * p1[c] - 3 * p2[c] + p3[c]) * t3))); }+ }+ out.push(closed ? [...P[0]] : [...P[n - 1]]); return out;+}+export function densify(P, step = 7) { const out = [];+ for (let i = 0; i < P.length - 1; i++) { const [x0, y0] = P[i], [x1, y1] = P[i + 1], m = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0) / step)); for (let s = 0; s < m; s++) out.push([lerp(x0, x1, s / m), lerp(y0, y1, s / m)]); }+ out.push([...P[P.length - 1]]); return out; }+// arc-length sampler: path(pts).at(u) -> [x, y, angle], .slice(u) -> points up to u+export function pathOf(pts) {+ const D = catmull(pts, false, 5), L = [0]; for (let i = 1; i < D.length; i++) L.push(L[i - 1] + Math.hypot(D[i][0] - D[i - 1][0], D[i][1] - D[i - 1][1]));+ const T = L[L.length - 1];+ const idx = (u) => { const lim = clamp(u) * T; let i = 1; while (i < D.length - 1 && L[i] < lim) i++; return [i, (lim - L[i - 1]) / ((L[i] - L[i - 1]) || 1)]; };+ return { length: T, points: D,+ at(u) { const [i, k] = idx(u), a = D[i - 1], b = D[i]; return [lerp(a[0], b[0], k), lerp(a[1], b[1], k), Math.atan2(b[1] - a[1], b[0] - a[0])]; },+ slice(u) { const [i, k] = idx(u), out = D.slice(0, i); const a = D[i - 1], b = D[i]; out.push([lerp(a[0], b[0], k), lerp(a[1], b[1], k)]); return out; } };+}+// 2-bone IK: joint position for a limb from `a` to `c` with segment lengths l1, l2; bendUp picks the side+// pref: which way the joint should point — true = up, or a direction vector [dx, dy] (e.g. [-.6, -.8] = back and up)+export function ik(a, c, l1, l2, pref = true) {+ const dx = c[0] - a[0], dy = c[1] - a[1], d = clamp(Math.hypot(dx, dy), Math.abs(l1 - l2) + .01, l1 + l2 - .01);+ const base = Math.atan2(dy, dx), off = Math.acos(clamp((l1 * l1 + d * d - l2 * l2) / (2 * l1 * d), -1, 1));+ const cand = [base + off, base - off].map((ang) => [a[0] + Math.cos(ang) * l1, a[1] + Math.sin(ang) * l1]);+ const v = pref === true ? [0, -1] : pref === false ? [0, 1] : pref, score = (p) => (p[0] - a[0]) * v[0] + (p[1] - a[1]) * v[1];+ return score(cand[0]) >= score(cand[1]) ? cand[0] : cand[1];+}++// ------------------------------------------------------------------ canvas helpers+export const INK = "#1E1612";+export function poly(ctx, pts, close = true) { ctx.beginPath(); pts.forEach(([x, y], i) => i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)); if (close) ctx.closePath(); }+export function smooth(ctx, pts, close = true) { // quadratic through midpoints: soft organic outlines+ const n = pts.length, g = (i) => close ? pts[(i + n) % n] : pts[clamp(i, 0, n - 1)];+ ctx.beginPath(); ctx.moveTo(...(close ? mid(g(-1), g(0)) : g(0)));+ for (let i = 0; i < (close ? n : n - 1); i++) { const a = g(i), b = g(i + 1), m = mid(a, b); ctx.quadraticCurveTo(a[0], a[1], m[0], m[1]); }+ if (!close) ctx.lineTo(...g(n - 1)); else ctx.closePath();+}+export function ellipse(ctx, x, y, rx, ry, rot = 0) { ctx.beginPath(); ctx.ellipse(x, y, Math.max(.01, rx), Math.max(.01, ry), rot, 0, Math.PI * 2); }+export function stroke(ctx, w = 3, c = INK) { ctx.lineWidth = w; ctx.strokeStyle = c; ctx.lineJoin = "round"; ctx.lineCap = "round"; ctx.stroke(); }+export function fill(ctx, c) { ctx.fillStyle = c; ctx.fill(); }+export function line(ctx, pts, w = 2, c = INK, dash = null) { ctx.save(); if (dash) ctx.setLineDash(dash); poly(ctx, pts, false); stroke(ctx, w, c); ctx.restore(); }+export function at(ctx, x, y, s, r, fn) { ctx.save(); ctx.translate(x, y); if (r) ctx.rotate(r); if (s !== 1) ctx.scale(s, s); fn(); ctx.restore(); }+// tapered stroke (thick in the middle, thin at the ends) — for limbs, stems, antennae+export function taper(ctx, pts, w0, w1, c = INK) { for (let i = 0; i < pts.length - 1; i++) line(ctx, [pts[i], pts[i + 1]], lerp(w0, w1, i / Math.max(1, pts.length - 2)), c); }++// ------------------------------------------------------------------ texture+export function grainCanvas(sz = 256, amt = 60, seed = 3) {+ const c = createCanvas(sz, sz), x = c.getContext("2d"), d = x.createImageData(sz, sz), r = rng(seed);+ for (let i = 0; i < sz * sz; i++) { const v = 255 - Math.floor(Math.pow(r(), 2.2) * amt); d.data[i * 4] = v; d.data[i * 4 + 1] = v; d.data[i * 4 + 2] = v; d.data[i * 4 + 3] = 255; }+ x.putImageData(d, 0, 0); return c;+}+const _grain = {};+// multiply printed-paper grain over whatever `clipFn` outlines+export function grainOver(ctx, clipFn, a = .5, amt = 60) {+ const key = amt; _grain[key] ??= ctx.createPattern(grainCanvas(256, amt, 3 + amt), "repeat");+ ctx.save(); clipFn(); ctx.clip(); ctx.globalCompositeOperation = "multiply"; ctx.globalAlpha = a; ctx.fillStyle = _grain[key]; ctx.fillRect(-4000, -4000, 8000, 8000); ctx.restore();+}+// parallel hatch lines inside `clipFn`, at angle `ang`, every `gap` px, inside bounding box `box`+export function hatch(ctx, clipFn, ang, gap, c, w = 1, a = .35, box = [-600, -600, 2600, 2600]) {+ ctx.save(); clipFn(); ctx.clip(); ctx.strokeStyle = c; ctx.lineWidth = w; ctx.globalAlpha *= a;+ const [x0, y0, x1, y1] = box, cx = (x0 + x1) / 2, cy = (y0 + y1) / 2, R = Math.hypot(x1 - x0, y1 - y0);+ ctx.translate(cx, cy); ctx.rotate(ang); ctx.beginPath(); for (let d = -R; d < R; d += gap) { ctx.moveTo(-R, d); ctx.lineTo(R, d); } ctx.stroke(); ctx.restore();+}+// short random strokes along an angle: pencil / crayon fibre, used on suns, felt, fur+export function fibre(ctx, clipFn, box, n, ang, len, cols, w = 1.2, a = .6, seed = 9) {+ const r = rng(seed); ctx.save(); clipFn(); ctx.clip(); ctx.lineCap = "round"; ctx.lineWidth = w; const [x0, y0, x1, y1] = box;+ for (let i = 0; i < n; i++) { const x = lerp(x0, x1, r()), y = lerp(y0, y1, r()), l = len * (.5 + r()), aa = ang + (r() - .5) * .5;+ ctx.globalAlpha = a * (.5 + r() * .5); ctx.strokeStyle = cols[i % cols.length]; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + Math.cos(aa) * l, y + Math.sin(aa) * l); ctx.stroke(); }+ ctx.restore();+}+// radial burst / impact lines around a point+export function burst(ctx, x, y, r0, r1, n = 10, w = 3, c = INK, a0 = 0, span = Math.PI * 2) {+ for (let i = 0; i < n; i++) { const a = a0 + (span >= Math.PI * 2 ? i / n : i / Math.max(1, n - 1)) * span; line(ctx, [[x + Math.cos(a) * r0, y + Math.sin(a) * r0], [x + Math.cos(a) * r1, y + Math.sin(a) * r1]], w, c); }+}+// speed lines trailing behind a moving thing (dir = travel angle)+export function speedLines(ctx, x, y, dir, n = 3, len = 50, gap = 12, w = 2.4, c = INK) {+ const bx = -Math.cos(dir), by = -Math.sin(dir), nx = -by, ny = bx;+ for (let i = 0; i < n; i++) { const o = (i - (n - 1) / 2) * gap, sx = x + bx * 30 + nx * o, sy = y + by * 30 + ny * o; line(ctx, [[sx, sy], [sx + bx * len * (1 - i * .15), sy + by * len * (1 - i * .15)]], w, c); }+}+export function lerpColor(a, b, k) { const p = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)); const A = p(a), B = p(b); return `rgb(${A.map((v, i) => Math.round(lerp(v, B[i], clamp(k)))).join(",")})`; }diff --git a/plugins/claude-animation/skills/claude-animation/lib/film.mjs b/plugins/claude-animation/skills/claude-animation/lib/film.mjsnew file mode 100644index 0000000..92e1435--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/film.mjs@@ -0,0 +1,84 @@+// film.mjs — the harness. A film is a pure function frame(ctx, t, i) -> pixels; this file renders it,+// previews it and checks it. Same command line for every film:+//+// node film.mjs render stage -> encode -> publish out/<name>.mp4 (+ render.json)+// node film.mjs sheet 0,1.2,3.5 one tile per time -> out/sheet.png+// node film.mjs strip 5.2 12 12 consecutive frames from 5.2s (fast actions, contacts)+// node film.mjs verify same frame rendered in and out of order must be identical+//+// import { run, exposure } from "./lib/film.mjs";+// run({ name: "wm", W: 1080, H: 1080, fps: 24, dur: 10.5, setup(ctx) {...}, frame(ctx, t, i) {...} });+import { createCanvas } from "./core.mjs";+import { spawn } from "node:child_process";+import fs from "node:fs";+import path from "node:path";+import crypto from "node:crypto";++// Exposure: which moment the DRAWINGS show at time t. On ones = every frame, on twos = each drawing+// held two frames (the classic hand-drawn cadence), hold = frozen. Camera and root motion can stay on+// ones while the drawing steps on twos: pass exposure(t) only to the drawing code.+// const drawT = exposure(t, [{ at: 0, on: 2 }, { at: 4.5, on: 1 }, { at: 8, hold: true }], 24);+export function exposure(t, track, fps) {+ let cur = track[0]; for (const e of track) if (t >= e.at) cur = e;+ if (cur.hold) return cur.at;+ const n = cur.on || 1, f = Math.floor((t - cur.at) * fps + 1e-6); return cur.at + Math.floor(f / n) * n / fps;+}++function args() { const [, , mode = "render", a, b] = process.argv; return { mode, a, b }; }++export async function run(F) {+ const { mode, a, b } = args();+ const W = F.W, H = F.H, fps = F.fps || 24, N = Math.round(F.dur * fps), out = path.resolve(F.out || "out");+ fs.mkdirSync(out, { recursive: true });+ const c = createCanvas(W, H), ctx = c.getContext("2d");+ const state = F.setup ? await F.setup(ctx) : {};+ const draw = (t, i) => { ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = 1; ctx.globalCompositeOperation = "source-over";+ if (!F.alpha) { ctx.fillStyle = F.background || "#F3EEDD"; ctx.fillRect(0, 0, W, H); } else ctx.clearRect(0, 0, W, H);+ F.frame(ctx, t, i, state); ctx.restore(); };+ // motion blur by temporal supersampling, only where a film asks for it (fast flights)+ const acc = F.blur ? new Float64Array(W * H * 4) : null;+ const pixels = (i) => {+ const t = i / fps, S = F.blur ? F.blur(t) || 1 : 1;+ if (S === 1) { draw(t, i); return ctx.getImageData(0, 0, W, H).data; }+ acc.fill(0);+ for (let k = 0; k < S; k++) { draw(t + (k / S - .5) / fps * .9, i); const d = ctx.getImageData(0, 0, W, H).data;+ for (let j = 0; j < d.length; j += 4) { const al = d[j + 3]; if (!al) continue; acc[j] += d[j] * al; acc[j + 1] += d[j + 1] * al; acc[j + 2] += d[j + 2] * al; acc[j + 3] += al; } }+ const o = new Uint8ClampedArray(acc.length);+ for (let j = 0; j < acc.length; j += 4) { const al = acc[j + 3]; if (!al) continue; o[j] = acc[j] / al; o[j + 1] = acc[j + 1] / al; o[j + 2] = acc[j + 2] / al; o[j + 3] = al / S; }+ return o;+ };+ const tile = (times, file, sc = F.sheetScale || .3, cols = Math.min(times.length, 6), under = null) => {+ const rows = Math.ceil(times.length / cols), S = createCanvas(Math.round(W * sc * cols), Math.round(H * sc * rows * (under ? 2 : 1))), sx = S.getContext("2d");+ return { S, sx, put(k, img, row = 0) { const col = k % cols, r = Math.floor(k / cols) * (under ? 2 : 1) + row; sx.drawImage(img, col * W * sc, r * H * sc, W * sc, H * sc); },+ label(k, s) { const col = k % cols, r = Math.floor(k / cols) * (under ? 2 : 1); sx.fillStyle = "rgba(0,0,0,.65)"; sx.fillRect(col * W * sc, r * H * sc, 86, 26); sx.fillStyle = "#fff"; sx.font = "18px sans-serif"; sx.fillText(s, col * W * sc + 6, r * H * sc + 19); },+ save() { fs.writeFileSync(file, S.toBuffer("image/png")); console.log("wrote", file); } };+ };+ const frameCanvas = (i) => { const d = pixels(i), cc = createCanvas(W, H), x = cc.getContext("2d"), im = x.createImageData(W, H); im.data.set(d); x.putImageData(im, 0, 0); return cc; };++ if (mode === "sheet") { const ts = a.split(",").map(Number), T = tile(ts, path.join(out, "sheet.png")); ts.forEach((t, k) => { T.put(k, frameCanvas(Math.round(t * fps))); T.label(k, t.toFixed(2) + "s"); }); T.save(); return; }+ if (mode === "strip") { const t0 = Number(a), n = Number(b || 12), i0 = Math.round(t0 * fps), ts = Array.from({ length: n }, (_, k) => (i0 + k) / fps), T = tile(ts, path.join(out, "strip.png"), .22, Math.min(n, 6));+ ts.forEach((t, k) => { T.put(k, frameCanvas(i0 + k)); T.label(k, "f" + (i0 + k)); }); T.save(); return; }+ if (mode === "verify") {+ const pick = [0, Math.floor(N / 3), Math.floor(N / 2), N - 1, Math.floor(N / 5)], h = (i) => crypto.createHash("md5").update(pixels(i)).digest("hex");+ const fwd = pick.map(h), back = [...pick].reverse().map(h).reverse(), again = pick.map(h);+ const bad = pick.filter((_, k) => fwd[k] !== back[k] || fwd[k] !== again[k]);+ if (bad.length) { console.error("NOT deterministic at frames", bad.join(", "), "- something depends on render order (state kept between frames, Math.random, Date)"); process.exit(1); }+ console.log("ok: frames", pick.join(", "), "identical in and out of order"); return; }++ // render: stage, encode, then publish; a failed encode never replaces a good file+ const stage = path.join(out, ".staging"); fs.mkdirSync(stage, { recursive: true });+ const name = F.name || "film", t0 = Date.now();+ const base = ["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "rgba", "-s", `${W}x${H}`, "-r", String(fps), "-i", "-"];+ const outs = F.alpha === "matte"+ ? ["-filter_complex", "[0]split[a][b];[a]format=rgb24,format=yuv420p[c];[b]alphaextract,format=yuv420p[m]", "-map", "[c]", "-c:v", "libx264", "-crf", "14", path.join(stage, name + "-rgb.mp4"), "-map", "[m]", "-c:v", "libx264", "-crf", "11", path.join(stage, name + "-matte.mp4")]+ : F.alpha === "prores" ? ["-c:v", "prores_ks", "-profile:v", "4444", "-pix_fmt", "yuva444p10le", path.join(stage, name + ".mov")]+ : ["-c:v", "libx264", "-crf", String(F.crf ?? 15), "-preset", "medium", "-pix_fmt", "yuv420p", path.join(stage, name + ".mp4")];+ const ff = spawn("ffmpeg", [...base, ...outs], { stdio: ["pipe", "inherit", "inherit"] });+ for (let i = 0; i < N; i++) { const d = pixels(i); await new Promise((r) => ff.stdin.write(Buffer.from(d.buffer, d.byteOffset, d.byteLength)) ? r() : ff.stdin.once("drain", r));+ if (i % (fps * 5) === 0) process.stdout.write(` ${(i / fps).toFixed(1)}s\n`); }+ ff.stdin.end(); const code = await new Promise((r) => ff.on("close", r));+ if (code !== 0) { console.error("encode failed; previous outputs left untouched"); process.exit(1); }+ const made = fs.readdirSync(stage); for (const f of made) fs.renameSync(path.join(stage, f), path.join(out, f));+ fs.writeFileSync(path.join(out, name + ".render.json"), JSON.stringify({ name, W, H, fps, dur: F.dur, frames: N, seconds: (Date.now() - t0) / 1000, files: made }, null, 1));+ console.log(`rendered ${N} frames in ${((Date.now() - t0) / 1000).toFixed(0)}s -> ${made.join(", ")}`);+}diff --git a/plugins/claude-animation/skills/claude-animation/lib/nature.mjs b/plugins/claude-animation/skills/claude-animation/lib/nature.mjsnew file mode 100644index 0000000..0cd3831--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/nature.mjs@@ -0,0 +1,56 @@+// nature.mjs — plants and small creatures in the textured-editorial style.+// Every function draws at the current transform; place with at(ctx, x, y, s, rot, () => ...).+import { lerp, clamp, rad, eBack, ellipse, stroke, fill, line, at, poly, smooth, hatch, INK } from "./core.mjs";++// a sprout: stem + two cotyledons with midribs; droop 0..1 wilts them, shine 0..1 adds dew highlights+export function sprout(ctx, { droop = 0, shine = 0, sway = 0, h = 158 } = {}) {+ const top = [sway * 8 + droop * 18, -h + droop * 20];+ smooth(ctx, [[0, 4], [-2, -h * .5], top], false); stroke(ctx, 16); smooth(ctx, [[0, 4], [-2, -h * .5], top], false); stroke(ctx, 11, "#7CC95A");+ line(ctx, [[-3, -10], [-4, -h * .6]], 2.4, "rgba(220,255,200,.55)");+ const leaf = (sg) => at(ctx, top[0], top[1], 1, sg * rad(18 + droop * 55) + (sg < 0 ? Math.PI : 0) + sway * .08, () => {+ ellipse(ctx, 70, 0, 70, 38); fill(ctx, "#94D46C"); hatch(ctx, () => ellipse(ctx, 70, 0, 70, 38), rad(30), 5, "#6DB04D", 1, .5, [0, -40, 140, 40]); ellipse(ctx, 70, 0, 70, 38); stroke(ctx, 3);+ line(ctx, [[6, 0], [128, 0]], 2, "#4F8C39"); for (let i = 1; i < 4; i++) { line(ctx, [[i * 30, 0], [i * 30 + 16, -18 + i]], 1.2, "#4F8C39"); line(ctx, [[i * 30, 0], [i * 30 + 16, 18 - i]], 1.2, "#4F8C39"); }+ if (shine > 0) { ctx.save(); ctx.globalAlpha *= shine; ellipse(ctx, 60, -12, 9, 9); fill(ctx, "#fff"); ellipse(ctx, 84, -4, 5, 5); fill(ctx, "#fff"); ctx.restore(); } });+ leaf(-1); leaf(1);+}+// a watermelon (cucurbit) leaf: five deep pointed lobes with serrated edges and pale veins+export function melonLeaf(ctx, s = 1) {+ ctx.save(); ctx.scale(s, s); const pts = [];+ for (let i = 0; i <= 90; i++) { const a = i / 90 * Math.PI * 2, main = Math.pow(Math.abs(Math.cos(a * 2.5)), 1.3), sub = .16 * Math.abs(Math.sin(a * 15)) * (.4 + main);+ pts.push([Math.cos(a) * 64 * (.3 + .7 * main + sub), Math.sin(a) * 60 * (.3 + .7 * main + sub)]); }+ poly(ctx, pts); fill(ctx, "#5EAA4E"); hatch(ctx, () => poly(ctx, pts), rad(40), 5, "#3E8A3A", 1, .5, [-70, -70, 70, 70]); poly(ctx, pts); stroke(ctx, 2.6);+ for (let i = 0; i < 5; i++) { const a = i / 5 * Math.PI * 2; line(ctx, [[0, 0], [Math.cos(a) * 54, Math.sin(a) * 50]], 1.6, "#CFE8B4"); }+ ctx.restore();+}+// a tendril that rises and ends in a small curl-loop; k 0..1 grows it+export function tendril(ctx, k = 1, s = 1) {+ const n = Math.max(2, Math.round(24 * k)), pts = [];+ for (let i = 0; i <= n; i++) { const q = i / 24; if (q < .6) pts.push([Math.sin(q * 5) * 8, -q * 110]); else { const a = (q - .6) / .4 * Math.PI * 1.8; pts.push([Math.sin(3) * 8 + 16 - Math.cos(a) * 16, -66 - Math.sin(a) * 16]); } }+ ctx.save(); ctx.scale(s, s); smooth(ctx, pts, false); stroke(ctx, 6.5); smooth(ctx, pts, false); stroke(ctx, 4, "#6CC05A");+ if (k > .95) { ellipse(ctx, pts[n][0], pts[n][1], 9, 9); stroke(ctx, 6.5); ellipse(ctx, pts[n][0], pts[n][1], 9, 9); stroke(ctx, 3.5, "#9BE07C"); } ctx.restore();+}+// a vine along points (already sliced to its grown length): outline, body, highlight, little hairs+export function vine(ctx, pts, w = 18) {+ smooth(ctx, pts, false); stroke(ctx, w + 6); smooth(ctx, pts, false); stroke(ctx, w, "#4E9E47");+ ctx.save(); ctx.translate(-3, -3); smooth(ctx, pts, false); stroke(ctx, w * .28, "rgba(190,235,160,.6)"); ctx.restore();+ for (let i = 3; i < pts.length; i += 5) { const [x, y] = pts[i]; line(ctx, [[x, y - w * .65], [x + 4, y - w * 1.1]], 1.2); }+}+// a five-petal flower (yellow cucurbit blossom); open 0..1+export function blossom(ctx, open = 1, color = "#F5CF3A") {+ const k = eBack(clamp(open)); ctx.save(); ctx.scale(k, k);+ for (let i = 0; i < 5; i++) at(ctx, 0, 0, 1, i / 5 * Math.PI * 2, () => { ellipse(ctx, 0, -52, 36, 48); fill(ctx, color); stroke(ctx, 2.6); line(ctx, [[0, -14], [0, -84]], 1.4, "#D9A92A"); line(ctx, [[0, -40], [-12, -70]], 1, "#D9A92A"); line(ctx, [[0, -40], [12, -70]], 1, "#D9A92A"); });+ ellipse(ctx, 0, 0, 20, 20); fill(ctx, "#B87A2A"); stroke(ctx, 2); for (let i = 0; i < 10; i++) { const a = i / 10 * Math.PI * 2; ellipse(ctx, Math.cos(a) * 11, Math.sin(a) * 11, 2.2, 2.2); fill(ctx, "#7A4A18"); }+ ctx.restore();+}+// a bee: striped body, fuzz, wing blur that flaps with t+export function bee(ctx, t, s = 1) {+ ctx.save(); ctx.scale(s, s);+ ctx.save(); ctx.globalAlpha *= .7; ellipse(ctx, -6, -34, 20, 14, -.4 + Math.sin(t * 60) * .3); fill(ctx, "#E9F4FA"); stroke(ctx, 1.6); ellipse(ctx, 8, -30, 16, 11, .3 + Math.sin(t * 60 + 1) * .3); fill(ctx, "#E9F4FA"); stroke(ctx, 1.4); ctx.restore();+ ellipse(ctx, 0, 0, 44, 28); fill(ctx, "#F2C230"); ctx.save(); ellipse(ctx, 0, 0, 44, 28); ctx.clip(); for (const x of [-20, 2, 24]) { ctx.fillStyle = INK; ctx.fillRect(x, -30, 11, 60); } ctx.restore();+ ellipse(ctx, 0, 0, 44, 28); stroke(ctx, 2.6); for (let i = 0; i < 14; i++) { const a = Math.PI * 1.1 + i / 13 * Math.PI * .8; line(ctx, [[Math.cos(a) * 44, Math.sin(a) * 28], [Math.cos(a) * 50, Math.sin(a) * 33]], 1); }+ line(ctx, [[42, 4], [52, 6]], 2.2); ellipse(ctx, -44, -2, 14, 14); fill(ctx, INK); ellipse(ctx, -48, -6, 3, 3); fill(ctx, "#fff");+ line(ctx, [[-50, -12], [-60, -30]], 1.6); line(ctx, [[-44, -14], [-48, -32]], 1.6);+ ctx.restore();+}+// a water drop (sweat, dew, rain)+export function drop(ctx, s = 1, color = "#9CCBEA") { ctx.save(); ctx.scale(s, s); ctx.beginPath(); ctx.moveTo(0, -16); ctx.quadraticCurveTo(10, 0, 0, 6); ctx.quadraticCurveTo(-10, 0, 0, -16); fill(ctx, color); stroke(ctx, 2); ellipse(ctx, -3, -2, 2, 3); fill(ctx, "#fff"); ctx.restore(); }diff --git a/plugins/claude-animation/skills/claude-animation/lib/pen.mjs b/plugins/claude-animation/skills/claude-animation/lib/pen.mjsnew file mode 100644index 0000000..97aa678--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/pen.mjs@@ -0,0 +1,108 @@+// pen.mjs — the hand: brush ink, pencil, watercolour, lettering. Every mark has a STABLE seed taken+// from a name, never from the frame, so a held drawing keeps its marks. Boil (the redrawn-every-few-+// frames wobble) is opt-in per drawing: pen.begin(name, reveal, { boil: 10 }) — decide it on purpose.+//+// const pen = new Pen(ctx);+// pen.begin("hero/body", reveal); // reveal 0..1 draws the marks on in order+// pen.stroke(points, { w: 5 }); // tapered brush line, drawn on by a round nib+// pen.wash(points, "#7DB26A"); // watercolour that blooms from a point+// pen.pencil(points, { w: 1.6 }); // 3 thin broken passes, gaps where pressure is low+// pen.box(x, y, w, h); // corners drawn edge by edge with overshoot+import { clamp, lerp, hash, noise1, catmull, densify, centroid, eOut, eBack, grainCanvas, INK, Path2D } from "./core.mjs";++const idHash = (s) => { let h = 2166136261; for (const c of String(s)) h = Math.imul(h ^ c.charCodeAt(0), 16777619); return (h >>> 0) % 100000; };++export class Pen {+ constructor(ctx) { this.ctx = ctx; this.grain = ctx.createPattern(grainCanvas(256, 70, 11), "repeat"); this.rv = 1; this.Wt = 1; this.c = 0; this.seed = 1; this.boilIx = 0; this.act = 0; this.weights = new Map(); }+ // start a named drawing. reveal: 0..1 progress of drawing it on. opts.boil: redraws per second (0 = still)+ begin(name, reveal = 1, opts = {}) {+ this.name = name; this.seed = idHash(name); this.rv = clamp(reveal); this.c = 0;+ this.Wt = this.weights.get(name) || 1; this.boilIx = opts.boil ? Math.floor((opts.t ?? 0) * opts.boil) : 0; this.jitAmp = opts.jitter ?? 1;+ return this;+ }+ // call after drawing the full drawing once (reveal 1) so reveal knows how many marks there are+ end() { if (this.rv >= 1) this.weights.set(this.name, Math.max(this.c, .5)); }+ next(wt = 1) {+ const OV = 1.6, c = this.c; this.c += wt; if (this.rv >= 1) return 1;+ const r = clamp((this.rv * (this.Wt + OV) - c) / (OV * wt)); if (r > 0 && r < 1) this.act += Math.min(wt, 1.5); return r;+ }+ J(i, amp) { return (hash(this.seed * 91.7 + this.boilIx * 13.37 + i * 7.13) - .5) * 2 * amp * this.jitAmp; }++ // tapered, pressure-wobbled brush line+ stroke(pts, o = {}) {+ const r = this.next(o.wt ?? 1); if (r <= 0 || pts.length < 2) return;+ const { w = 5, color = INK, taper = .75, jit = 1.4, closed = false, alpha = 1, smooth = true, cap = true } = o;+ const k0 = this.c * 31 + this.seed;+ let P = pts.map(([x, y], i) => [x + this.J(k0 + i * 2, jit), y + this.J(k0 + i * 2 + 1, jit)]);+ if (closed) P = [...P, P[0]];+ const D = smooth && P.length > 2 ? catmull(P, false) : densify(P);+ const cum = [0]; for (let i = 1; i < D.length; i++) cum.push(cum[i - 1] + Math.hypot(D[i][0] - D[i - 1][0], D[i][1] - D[i - 1][1]));+ const L = cum[cum.length - 1] || 1, Lr = r * L;+ const wAt = (s) => { const u = s / L, e = (u < .14 ? u / .14 : 1) * (u > .84 ? (1 - u) / .16 : 1); return w * (1 - taper + taper * e) * (1 + .14 * noise1(s * .025 + k0)); };+ const Lp = [], Rp = []; let tip = null, tw = w;+ for (let i = 0; i < D.length; i++) {+ let [x, y] = D[i], s = cum[i];+ if (s > Lr) { if (i === 0) break; const k = (Lr - cum[i - 1]) / ((s - cum[i - 1]) || 1); x = lerp(D[i - 1][0], x, k); y = lerp(D[i - 1][1], y, k); s = Lr; }+ const a = D[Math.max(0, i - 1)], b = D[Math.min(D.length - 1, i + 1)]; let nx = -(b[1] - a[1]), ny = b[0] - a[0]; const nl = Math.hypot(nx, ny) || 1; nx /= nl; ny /= nl;+ const ww = wAt(s) / 2; Lp.push([x + nx * ww, y + ny * ww]); Rp.push([x - nx * ww, y - ny * ww]); tip = [x, y]; tw = ww; if (s >= Lr) break;+ }+ if (!tip) return;+ const ctx = this.ctx; ctx.save(); ctx.globalAlpha *= alpha; ctx.fillStyle = color;+ ctx.beginPath(); ctx.moveTo(Lp[0][0], Lp[0][1]); for (const q of Lp) ctx.lineTo(q[0], q[1]); for (let i = Rp.length - 1; i >= 0; i--) ctx.lineTo(Rp[i][0], Rp[i][1]); ctx.closePath(); ctx.fill();+ if (cap) { ctx.beginPath(); ctx.arc(tip[0], tip[1], Math.max(tw, r < 1 ? w * .45 : 0), 0, Math.PI * 2); ctx.fill(); } // the nib+ ctx.restore();+ }+ // graphite: three thin offset passes, broken where "pressure" (noise) is low. No solid ribbon under it.+ pencil(pts, o = {}) {+ const { w = 1.5, color = "#3A3430", passes = 3, alpha = .8 } = o; const r = this.next(o.wt ?? 1); if (r <= 0) return;+ const D = catmull(pts, false, 3), n = Math.max(2, Math.floor(D.length * r)), ctx = this.ctx; ctx.save(); ctx.strokeStyle = color; ctx.lineCap = "round";+ for (let p = 0; p < passes; p++) { const off = (p - 1) * w * .6; ctx.lineWidth = w * (p === 1 ? 1 : .6); ctx.beginPath(); let down = false;+ for (let i = 0; i < n; i++) { const pres = noise1(i * .09 + p * 7.3 + this.seed); if (pres < -.55) { down = false; continue; }+ ctx.globalAlpha = alpha * (.55 + .45 * (pres + 1) / 2); const x = D[i][0] + this.J(i * 3 + p, .6) + off * .3, y = D[i][1] + this.J(i * 3 + p + 1, .6) + off;+ down ? ctx.lineTo(x, y) : ctx.moveTo(x, y); down = true; }+ ctx.stroke(); }+ ctx.restore();+ }+ // a hand-drawn ellipse: starts at a random angle, overshoots its own start+ ring(cx, cy, rx, ry, o = {}) {+ const a0 = o.a0 ?? (-2.3 + hash(this.seed + this.c) * .8), n = Math.max(12, Math.round((rx + ry) / 7)), over = o.over ?? 1.07, pts = [];+ for (let i = 0; i <= n; i++) { const a = a0 + i / n * Math.PI * 2 * over, q = 1 + .025 * Math.sin(a * 3 + this.seed); pts.push([cx + Math.cos(a) * rx * q, cy + Math.sin(a) * ry * q]); }+ this.stroke(pts, { taper: .5, ...o });+ }+ // a box drawn edge by edge, each edge overshooting the corner a little — reads as a human pencil box+ box(x, y, w, h, o = {}) {+ const ov = o.over ?? 8, C = [[x, y], [x + w, y], [x + w, y + h], [x, y + h]];+ for (let i = 0; i < 4; i++) { const a = C[i], b = C[(i + 1) % 4], dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1;+ this.stroke([[a[0] - dx / l * ov * hash(this.seed + i), a[1] - dy / l * ov * hash(this.seed + i)], [b[0] + dx / l * ov * hash(this.seed + i + 9), b[1] + dy / l * ov * hash(this.seed + i + 9)]], { smooth: false, taper: .5, ...o, wt: (o.wt ?? 1) / 4 }); }+ }+ // watercolour: blooms outward from (ox, oy), three offset translucent passes multiplied, pooled edge, paper grain+ wash(pts, color, o = {}) {+ const r = this.next(o.wt ?? .8); if (r <= 0) return;+ const { alpha = .8, ox, oy, solid = false, over = false } = o;+ const sharp = o.sharp ?? (pts.length <= 6 && !o.round), ctx = this.ctx;+ const p = new Path2D(); const D = sharp ? pts : catmull(pts, true); D.forEach(([x, y], i) => i ? p.lineTo(x, y) : p.moveTo(x, y)); p.closePath();+ ctx.save();+ if (r < 1) { const [cx, cy] = ox != null ? [ox, oy] : centroid(pts); let R = 0; for (const q of pts) R = Math.max(R, Math.hypot(q[0] - cx, q[1] - cy)); R *= 1.12 * eOut(r);+ const b = new Path2D(); for (let i = 0; i <= 28; i++) { const a = i / 28 * Math.PI * 2, rr = R * (1 + .16 * noise1(a * 2.2 + this.seed + this.c)); i ? b.lineTo(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr) : b.moveTo(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr); }+ b.closePath(); ctx.clip(b); }+ ctx.globalCompositeOperation = over ? "source-over" : "multiply"; ctx.fillStyle = color;+ if (solid) { ctx.globalAlpha *= alpha; ctx.fill(p); }+ else { const a0 = ctx.globalAlpha, base = this.seed * 7 + this.c * 13;+ for (let k = 0; k < 3; k++) { ctx.save(); ctx.translate((hash(base + k * 3) - .5) * 7, (hash(base + k * 5 + 1) - .5) * 7); ctx.globalAlpha = a0 * alpha * .45; ctx.fill(p); ctx.restore(); }+ ctx.globalAlpha = a0 * alpha * .35; ctx.strokeStyle = color; ctx.lineWidth = 3; ctx.stroke(p);+ ctx.globalAlpha = a0 * .55; ctx.save(); ctx.clip(p); ctx.fillStyle = this.grain; ctx.fillRect(-4000, -4000, 8000, 8000); ctx.restore(); }+ ctx.restore();+ }+ // lettering that writes itself left to right+ text(str, x, y, o = {}) {+ const r = this.next(o.wt ?? 2); if (r <= 0) return;+ const { size = 44, font = "sans-serif", color = INK, align = "center", rot = 0, alpha = 1 } = o, ctx = this.ctx; ctx.save(); ctx.font = `${size}px "${font}"`;+ const w = ctx.measureText(str).width, x0 = align === "center" ? x - w / 2 : align === "right" ? x - w : x;+ ctx.translate(x0 + this.J(this.c * 3, .9), y + this.J(this.c * 3 + 1, .9)); ctx.rotate(rot + this.J(this.c * 3 + 2, .006));+ if (r < 1) { ctx.beginPath(); ctx.rect(-10, -size * 1.3, (w + 20) * r, size * 2); ctx.clip(); }+ ctx.globalAlpha *= alpha; ctx.fillStyle = color; ctx.fillText(str, 0, 0); ctx.restore();+ }+ dot(x, y, rr, color = INK, wt = .3) { const r = this.next(wt); if (r <= 0) return; const c = this.ctx; c.fillStyle = color; c.beginPath(); c.arc(x + this.J(this.c, .6), y + this.J(this.c + 1, .6), rr * eBack(r), 0, Math.PI * 2); c.fill(); }+ poly(pts, o) { this.stroke(pts, { closed: true, smooth: false, taper: .35, ...o }); }+ blob(pts, o) { this.stroke(pts, { closed: true, taper: .4, ...o }); }+}diff --git a/plugins/claude-animation/skills/claude-animation/lib/rigs/ant.mjs b/plugins/claude-animation/skills/claude-animation/lib/rigs/ant.mjsnew file mode 100644index 0000000..a9c489d--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/rigs/ant.mjs@@ -0,0 +1,197 @@+// ant.mjs — a detailed, poseable ant in the textured-editorial style (glossy chitin, hatching,+// setae, compound eye with two highlights, elbowed beaded antennae, toothed mandibles, 3-segment legs+// with tarsi and claws, a real tripod gait).+//+// LOCAL SPACE (read this before placing it): facing +x, origin = the point ON THE GROUND under the+// petiole (waist). Feet land on y = 0. So `ant(ctx, x, groundY, s, pose)` always stands on groundY —+// there is no "ground" knob to get out of sync (that knob once gave the ant stilt legs).+// Body length ≈ 300 * s px, standing height ≈ 150 * s px.+//+// pose: {+// flip face -x instead of +x+// rot body pitch in radians, about `pivot` (default: the rear feet) — climb, stand up, fall+// pivot [x, y] local pivot for rot+// gait phase (radians); advance it by ~speed*t*9. undefined = standing still+// stride step length (default 26)+// rear 0..1: stand up on the hind legs (front + mid legs lift, body pitches back)+// headDip px the head drops (sniff, dig)+// ant antenna sway -1..1+// jaw mandible open 0..1+// carry fn(ctx) drawn at the mandibles (small object), or+// overhead fn(ctx) drawn above the head, held by the raised front legs+// sweat 0..1 a drop on the head+// blink true = eye closed line+// dust 0..1 little dust puffs at the feet+// gaster abdomen scale (queen ≈ 1.7): bigger, paler bands+// look { ink, fill, tex } 0..1 each: draw only some layers (build-up reveals)+// }+import { clamp, lerp, rad, ellipse, stroke as _stroke, fill as _fill, line as _line, at, hatch as _hatch, INK } from "../core.mjs";++const C = { hi: "#A2653F", mid: "#5A301D", lo: "#26130B", leg: "#2B1810", legFar: "#4A2C1E", rim: "rgba(214,150,108,.55)", spec: "rgba(255,244,232,.72)" };++// LAYERS. pose.look = { ink, fill, tex } (each 0..1) draws the ant as a build-up: ink = outlines, eye,+// antennae, tarsi; fill = flat body colour; tex = gradient, hatching, gloss, rim light, setae, shadow.+// Default all 1. Every draw call below goes through these wrappers, classed by its colour.+let LK = { ink: 1, fill: 1, tex: 1 };+const TEXC = new Set([C.spec, C.rim, "#fff", "shadow"]);+const kind = (c) => c === INK || c === "#0E0806" ? "ink" : (typeof c === "string" && (c.startsWith("rgba") || TEXC.has(c))) ? "tex" : "fill";+function withA(ctx, a, fn) { if (a <= 0) return; if (a >= 1) return fn(); ctx.save(); ctx.globalAlpha *= a; fn(); ctx.restore(); }+const stroke = (ctx, w, c = INK) => withA(ctx, LK[kind(c)], () => _stroke(ctx, w, c));+const line = (ctx, pts, w, c = INK) => withA(ctx, LK[kind(c)], () => _line(ctx, pts, w, c));+const fill = (ctx, c) => withA(ctx, LK[kind(c)], () => _fill(ctx, c));+const hatch = (ctx, ...a) => withA(ctx, LK.tex, () => _hatch(ctx, ...a));++// hips on the mesosoma underside (x, y) and neutral foot positions, near side. Far side is offset.+const LEGS = [+ // each leg is an inverted V: a short femur out to the knee, a long tibia down to the tarsus+ { hip: [64, -60], knee: [104, -80], foot: [140, 0], tar: 20, dir: 1 }, // front: knee forward and up+ { hip: [42, -58], knee: [52, -86], foot: [60, 0], tar: 18, dir: 1 }, // mid: knee up+ { hip: [22, -56], knee: [-24, -84], foot: [-72, 0], tar: 22, dir: -1 }, // hind: knee back and up, tibia crosses the gaster+];+// tripod gait: legs move in two alternating sets of three+const TRIPOD = [[0, 0], [1, 1], [0, 0]]; // [nearSet, farSet] for front, mid, hind -> near front+hind with far mid++function chitin(ctx, cx, cy, r, pathFn) {+ const g = ctx.createRadialGradient(cx - r * .35, cy - r * .45, r * .08, cx, cy, r * 1.15);+ g.addColorStop(0, C.hi); g.addColorStop(.5, C.mid); g.addColorStop(1, C.lo); pathFn();+ withA(ctx, LK.fill * (1 - LK.tex), () => _fill(ctx, C.mid)); // flat colour stage+ withA(ctx, LK.fill * LK.tex, () => _fill(ctx, g)); // modelled chitin+}+function setae(ctx, cx, cy, rx, ry, rot, a0, a1, n, len, w = 1.1) {+ for (let i = 0; i < n; i++) { const a = a0 + (a1 - a0) * i / Math.max(1, n - 1), c = Math.cos(a), s = Math.sin(a);+ const x = cx + (c * rx * Math.cos(rot) - s * ry * Math.sin(rot)), y = cy + (c * rx * Math.sin(rot) + s * ry * Math.cos(rot));+ const nx = Math.cos(a + rot), ny = Math.sin(a + rot); withA(ctx, LK.tex, () => _line(ctx, [[x, y], [x + nx * len, y + ny * len + 1]], w, INK)); }+}++function leg(ctx, L, footOff, lift, far, rear, i) {+ const hip = [L.hip[0] + (far ? 8 : 0), L.hip[1] + (far ? -4 : 0)];+ let fx = L.foot[0] + footOff + (far ? 12 : 0), fy = -lift;+ if (rear > 0 && i < 2) { fx = lerp(fx, L.hip[0] + 30 + i * 10, rear); fy = lerp(fy, L.hip[1] - 50 + i * 30, rear); } // arms up+ const ankle = [fx - L.dir * L.tar * .7, fy - L.tar * .55];+ const knee = [L.knee[0] + (far ? 8 : 0) + footOff * .5 + (rear > 0 && i < 2 ? (fx - L.foot[0]) * .5 : 0), L.knee[1] + (far ? -4 : 0) - lift * .5 + (rear > 0 && i < 2 ? fy * .5 : 0)];+ const col = far ? C.legFar : C.leg, k = far ? .8 : 1;+ ctx.save(); ctx.globalAlpha *= far ? .9 : 1;+ ellipse(ctx, hip[0], hip[1] + 2, 7 * k, 5.5 * k); fill(ctx, col); stroke(ctx, 1.4); // coxa+ // femur: thick, tapering; tibia: thinner; both drawn as outline + fill so the joint reads+ for (const [a, b, w0] of [[hip, knee, 5.6], [knee, ankle, 3.8]]) {+ line(ctx, [a, b], w0 * k + 2.6, INK); line(ctx, [a, b], w0 * k, col);+ line(ctx, [[lerp(a[0], b[0], .15), lerp(a[1], b[1], .15) - 1.5], [lerp(a[0], b[0], .8), lerp(a[1], b[1], .8) - 1.5]], 1.4, "rgba(230,170,130,.45)"); // leg gloss+ }+ ellipse(ctx, knee[0], knee[1], 3.6 * k, 3.6 * k); fill(ctx, col); stroke(ctx, 1.3); // knee+ // tarsus: 3 small beads to the claw+ const tip = [fx + L.dir * L.tar * .25, fy];+ for (let j = 0; j < 3; j++) { const u0 = j / 3, u1 = (j + 1) / 3; line(ctx, [[lerp(ankle[0], tip[0], u0), lerp(ankle[1], tip[1], u0)], [lerp(ankle[0], tip[0], u1 - .07), lerp(ankle[1], tip[1], u1 - .07)]], 2.3 * k, INK); }+ line(ctx, [tip, [tip[0] + L.dir * 6, tip[1] - 3]], 1.6, INK); line(ctx, [tip, [tip[0] + L.dir * 6, tip[1] + 2]], 1.6, INK); // claw+ ctx.restore();+}++export function ant(ctx, x, y, s = 1, pose = {}) {+ const { flip = false, rot = 0, pivot: pv, gait, stride = 26, rear = 0, headDip = 0, jaw = 0, carry, overhead, sweat = 0, blink = false, dust = 0 } = pose;+ const antA = pose.ant ?? 0, pivot = pv ?? (pose.rear ? [-84, -26] : [-70, 0]);+ LK = { ink: 1, fill: 1, tex: 1, ...(pose.look || {}) };+ const walking = gait !== undefined, ph = gait ?? 0;+ const bob = walking ? -Math.abs(Math.sin(ph)) * 3 : 0;+ ctx.save(); ctx.translate(x, y); ctx.scale(s * (flip ? -1 : 1), s);+ if (rot || rear) { ctx.translate(pivot[0], pivot[1]); ctx.rotate(rot - rear * rad(34)); ctx.translate(-pivot[0], -pivot[1]); }+ ctx.translate(0, bob);++ // contact shadow on the ground+ if (!rot && !rear) withA(ctx, LK.tex * .22, () => { ellipse(ctx, 10, 2, 150, 8); _fill(ctx, "#2A1A10"); });++ const footOff = (i, far) => { if (!walking) return 0; const set = TRIPOD[i][far ? 1 : 0], p = ph + (set ? Math.PI : 0); return Math.sin(p) * stride * .5; };+ const liftOf = (i, far) => { if (!walking) return 0; const set = TRIPOD[i][far ? 1 : 0], p = ph + (set ? Math.PI : 0); return Math.max(0, Math.cos(p)) * 12; };+ // far-side legs first+ LEGS.forEach((L, i) => leg(ctx, L, footOff(i, true), liftOf(i, true), true, rear, i));++ // ---------------- gaster (abdomen): segmented, glossy, hairy+ const gs = pose.gaster || 1, GRX = 66 * gs, GRY = 50 * gs, GX = -84 - (gs - 1) * 62, GY = -74 - (gs - 1) * 22, GR = rad(-12);+ chitin(ctx, GX, GY, GRX, () => ellipse(ctx, GX, GY, GRX, GRY, GR));+ ctx.save(); ellipse(ctx, GX, GY, GRX, GRY, GR); ctx.clip();+ for (let k = 1; k <= 3; k++) { ctx.beginPath(); ctx.ellipse(GX + GRX * (.9 - k * .38), GY, 14, GRY * 1.05, GR, -1.35, 1.35); stroke(ctx, 1.8, "rgba(20,8,4,.6)"); } // tergite bands+ hatch(ctx, () => ellipse(ctx, GX, GY + 10, GRX, GRY * .7, GR), rad(-60), 5, "#1A0B06", 1, .35, [GX - 70, GY - 50, GX + 70, GY + 50]); // form shading+ ctx.beginPath(); ctx.ellipse(GX, GY, GRX - 3, GRY - 3, GR, .2, 2.4); stroke(ctx, 3, C.rim); // bounce rim light+ ctx.restore();+ ellipse(ctx, GX, GY, GRX, GRY, GR); stroke(ctx, 3.4);+ at(ctx, GX - 16, GY - 30, 1, rad(-22), () => { ellipse(ctx, 0, 0, 24, 7); fill(ctx, C.spec); ellipse(ctx, 22, 5, 4, 3); fill(ctx, C.spec); }); // specular streak + dot+ setae(ctx, GX, GY, GRX, GRY, GR, Math.PI * .55, Math.PI * 1.35, 16, 7);++ // ---------------- petiole: the narrow waist with one node+ line(ctx, [[-22, -70], [0, -68]], 9, INK); line(ctx, [[-22, -70], [0, -68]], 6, C.mid);+ chitin(ctx, -8, -80, 12, () => { ctx.beginPath(); ctx.moveTo(-18, -70); ctx.quadraticCurveTo(-10, -96, 2, -72); ctx.closePath(); });+ ctx.beginPath(); ctx.moveTo(-18, -70); ctx.quadraticCurveTo(-10, -96, 2, -72); stroke(ctx, 2.4);++ // ---------------- mesosoma (thorax): pronotum hump, mesonotum, propodeum with a tiny spine+ const meso = () => { ctx.beginPath(); ctx.moveTo(0, -66); ctx.bezierCurveTo(4, -86, 22, -84, 30, -80); ctx.bezierCurveTo(38, -92, 58, -100, 76, -88);+ ctx.bezierCurveTo(86, -80, 84, -64, 72, -58); ctx.bezierCurveTo(48, -52, 18, -54, 0, -66); ctx.closePath(); };+ chitin(ctx, 44, -76, 40, meso);+ ctx.save(); meso(); ctx.clip(); hatch(ctx, () => ellipse(ctx, 44, -60, 50, 12), rad(-50), 4.5, "#1A0B06", 1, .35, [0, -100, 90, -50]); ctx.restore();+ meso(); stroke(ctx, 2.8);+ line(ctx, [[30, -80], [34, -60]], 1.4, "rgba(20,8,4,.55)"); // segment suture+ line(ctx, [[46, -94], [66, -95]], 2, C.spec); // gloss+ line(ctx, [[4, -80], [-2, -88]], 2, INK); // propodeal spine++ // near-side legs over the body+ LEGS.forEach((L, i) => leg(ctx, L, footOff(i, false), liftOf(i, false), false, rear, i));++ // ---------------- head+ ctx.save(); ctx.translate(96, -96 + headDip); ctx.rotate(rad(headDip * .5));+ const head = () => { ctx.beginPath(); ctx.moveTo(-18, 2); ctx.bezierCurveTo(-20, -24, 12, -34, 30, -20); ctx.bezierCurveTo(42, -10, 40, 14, 26, 20); ctx.bezierCurveTo(8, 26, -14, 20, -18, 2); ctx.closePath(); };+ chitin(ctx, 8, -6, 32, head);+ ctx.save(); head(); ctx.clip(); hatch(ctx, () => ellipse(ctx, 10, 10, 30, 14), rad(-40), 4, "#1A0B06", 1, .3, [-20, -30, 40, 30]); ctx.restore();+ head(); stroke(ctx, 3);+ // mandibles (open with `jaw`), with teeth+ for (const [sg, far] of [[1, true], [1, false]]) at(ctx, 34, 10, 1, rad(far ? 10 + jaw * 26 : -8 - jaw * 18), () => {+ ctx.beginPath(); ctx.moveTo(0, -4); ctx.quadraticCurveTo(18, -6, 22, 6); ctx.lineTo(16, 4); ctx.lineTo(14, 8); ctx.lineTo(9, 4); ctx.lineTo(6, 7); ctx.quadraticCurveTo(2, 4, 0, 4); ctx.closePath();+ fill(ctx, far ? C.legFar : "#3A2014"); stroke(ctx, 1.8); });+ line(ctx, [[22, -4], [30, 4]], 1.4, "rgba(20,8,4,.6)"); // clypeus+ // compound eye: dark, a faceted sheen, two highlights+ if (blink) line(ctx, [[10, -12], [24, -10]], 2.6);+ else { ellipse(ctx, 17, -11, 9, 8, rad(-15)); fill(ctx, "#0E0806"); ctx.save(); ellipse(ctx, 17, -11, 9, 8, rad(-15)); ctx.clip(); hatch(ctx, () => ellipse(ctx, 17, -11, 9, 8), rad(45), 2.2, "#4A3A34", .8, .5, [6, -20, 28, -2]); ctx.restore();+ ellipse(ctx, 14, -14, 3.2, 2.6); fill(ctx, "#fff"); ellipse(ctx, 20, -8, 1.4, 1.4); fill(ctx, "#fff"); }+ // antennae: long scape to the elbow, then a beaded funiculus ending in a club+ const antenna = (far) => { const sw = antA * (far ? .7 : 1), base = far ? [6, -26] : [12, -24];+ const elbow = [base[0] + 10 + sw * 8, base[1] - 50], tipA = rad(-58 + sw * 22 + (far ? -8 : 0));+ line(ctx, [base, elbow], far ? 3 : 3.6, far ? C.legFar : INK);+ let p = elbow; for (let j = 0; j < 10; j++) { const l = 6.2, a = tipA + j * .03 * (1 + sw); const q = [p[0] + Math.cos(a) * l, p[1] + Math.sin(a) * l];+ line(ctx, [p, q], (far ? 2.2 : 2.8) + j * .12, far ? C.legFar : INK); ellipse(ctx, q[0], q[1], (1.6 + j * .12) * (far ? .8 : 1), (1.6 + j * .12) * (far ? .8 : 1)); fill(ctx, far ? C.legFar : INK); p = q; }+ ellipse(ctx, p[0], p[1], far ? 3 : 3.6, far ? 3 : 3.6); fill(ctx, far ? C.legFar : INK); };+ ctx.save(); ctx.globalCompositeOperation = "destination-over"; antenna(true); ctx.restore(); antenna(false);+ setae(ctx, 8, -6, 30, 22, 0, Math.PI * 1.1, Math.PI * 1.5, 5, 4, .9);+ // sweat drop+ if (sweat > 0) { const dy = -54 - sweat * 8; ctx.save(); ctx.globalAlpha *= clamp(sweat * 3); ctx.beginPath(); ctx.moveTo(34, dy - 14); ctx.quadraticCurveTo(43, dy, 34, dy + 5); ctx.quadraticCurveTo(25, dy, 34, dy - 14); fill(ctx, "#9CCBEA"); stroke(ctx, 2); ellipse(ctx, 31, dy - 2, 2, 3); fill(ctx, "#fff"); ctx.restore(); }+ if (carry) at(ctx, 52, 12, 1, 0, () => carry(ctx));+ ctx.restore();+ if (overhead) at(ctx, 90, -196, 1, 0, () => overhead(ctx));+ if (dust > 0) { ctx.save(); ctx.globalAlpha *= dust; for (const fx of [-60, 40, 128]) { ellipse(ctx, fx - 8, -3, 7, 4); fill(ctx, "rgba(150,120,90,.5)"); ellipse(ctx, fx + 6, -5, 5, 3); fill(ctx, "rgba(150,120,90,.4)"); } ctx.restore(); }+ ctx.restore();+}++// a watermelon seed, glossy, tip to the right; ~72 x 52 px at s = 1+export function seed(ctx, s = 1, pale = false) {+ ctx.save(); ctx.scale(s, s); ctx.beginPath(); ctx.moveTo(-34, 6); ctx.bezierCurveTo(-30, -26, 18, -30, 38, -2); ctx.bezierCurveTo(24, 22, -26, 28, -34, 6); ctx.closePath();+ if (pale) fill(ctx, "#EFE6CF"); else { const g = ctx.createLinearGradient(0, -28, 0, 24); g.addColorStop(0, "#3E2C24"); g.addColorStop(1, "#110A07"); fill(ctx, g); }+ stroke(ctx, 2.6); line(ctx, [[-18, -8], [2, -16], [22, -12]], 2.4, pale ? "rgba(160,140,110,.6)" : "rgba(255,255,255,.55)"); ctx.restore();+}++// Construction guides for the ant, in blue: the shapes and lines an illustrator blocks in before inking.+// p 0..1 draws them on in order. Same arguments as ant() so the two line up exactly.+export function antGuides(ctx, x, y, s = 1, p = 1, { color = "#5E80CC", flip = false, w = 2 } = {}) {+ const items = [+ ["line", [[-190, 0], [200, 0]]], // ground+ ["ell", -84, -74, 66, 50, rad(-12)], ["ell", -8, -80, 12, 12, 0], ["ell", 42, -76, 44, 20, rad(-8)], ["ell", 100, -100, 34, 29, rad(-10)],+ ["line", [[-170, -60], [150, -112]]], // body axis+ ...LEGS.flatMap((L) => [["line", [L.hip, L.knee]], ["line", [L.knee, L.foot]], ["ell", L.knee[0], L.knee[1], 4, 4, 0]]),+ ["line", [[108, -122], [118, -170], [150, -205]]], // antenna+ ["cross", -84, -74], ["cross", 42, -76], ["cross", 100, -100],+ ];+ const n = items.length, k = clamp(p) * n;+ ctx.save(); ctx.translate(x, y); ctx.scale(s * (flip ? -1 : 1), s); ctx.strokeStyle = color; ctx.lineWidth = w / s; ctx.lineCap = "round";+ items.forEach((it, i) => { const u = clamp(k - i); if (u <= 0) return; ctx.beginPath();+ if (it[0] === "line") { const P = it[1]; let tot = 0; for (let j = 1; j < P.length; j++) tot += Math.hypot(P[j][0] - P[j - 1][0], P[j][1] - P[j - 1][1]); let lim = tot * u;+ ctx.moveTo(...P[0]); for (let j = 1; j < P.length && lim > 0; j++) { const l = Math.hypot(P[j][0] - P[j - 1][0], P[j][1] - P[j - 1][1]), q = Math.min(1, lim / l); ctx.lineTo(lerp(P[j - 1][0], P[j][0], q), lerp(P[j - 1][1], P[j][1], q)); lim -= l; } }+ else if (it[0] === "ell") { const [, cx, cy, rx, ry, r] = it, n = Math.max(2, Math.round(48 * u)), cr = Math.cos(r), sr = Math.sin(r);+ for (let j = 0; j <= n; j++) { const a = -Math.PI / 2 + j / 48 * Math.PI * 2, ex = Math.cos(a) * rx, ey = Math.sin(a) * ry, px = cx + ex * cr - ey * sr, py = cy + ex * sr + ey * cr; j ? ctx.lineTo(px, py) : ctx.moveTo(px, py); } }+ else { ctx.moveTo(it[1] - 7 * u, it[2]); ctx.lineTo(it[1] + 7 * u, it[2]); ctx.moveTo(it[1], it[2] - 7 * u); ctx.lineTo(it[1], it[2] + 7 * u); }+ ctx.stroke(); });+ ctx.restore();+}diff --git a/plugins/claude-animation/skills/claude-animation/lib/rigs/bean.mjs b/plugins/claude-animation/skills/claude-animation/lib/rigs/bean.mjsnew file mode 100644index 0000000..b05bd37--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/rigs/bean.mjs@@ -0,0 +1,109 @@+// bean.mjs — the brush-ink + watercolour cast: a bean-bodied person with stick limbs, a head-and-+// shoulders bust, a speech bubble and a waving flag. Drawn with a Pen (lib/pen.mjs), so they draw+// themselves on and boil like everything else in that style.+// pen.begin("hero", reveal); person(pen, x, groundY, scale, { hat: "peci", shirt: "#F2C230", walk: t * 9 }, t);+// options: skin, shirt, hair, hat (peci|pith|helmet|turban|fez|cap), glasses (sun|round), arms [l, r]+// (degrees from straight down, outward positive), bend [l, r], face (smile|open|flat|sad), walk (phase),+// look (eye shift px), mustache, sash, medals, jacketLine, mask, flip, still, dip.+import { lerp, rad, ellPts, rrect } from "../core.mjs";+const INK = "#2A2420", RED = "#D0312D", WHITE = "#FBF7EE", GOLD = "#E3B64B", NAVY = "#3C4A6B", SAND = "#D8C7A0";+export const SKIN = ["#D9A273", "#C68A5A", "#E9C29C", "#A8704A", "#F0CDB0", "#8E5B3A"];++// bean body, stick limbs, washed head and clothes. Local space: feet at 0, 1 unit = 1 px at s=1.+export function person(p, x, y, s, o, t) {+ const ctx = p.ctx;+ let bob = o.still ? 0 : Math.sin(t * 4.2 + x * .013) * 2.2, lg = [0, 0];+ if (o.walk != null) { const ph = o.walk; lg = [Math.sin(ph) * 24, -Math.sin(ph) * 24]; bob = -Math.abs(Math.cos(ph)) * 7; }+ ctx.save(); ctx.translate(x, y + bob * s); ctx.scale(s * (o.flip ? -1 : 1), s);+ const hy = -212 + (o.dip || 0), sk = o.skin || SKIN[0];+ // head+ p.wash(ellPts(0, hy, 31, 30, 18), sk, { alpha: .75 });+ p.ring(0, hy, 32, 31, { w: 4.2 });+ if (o.hair) p.wash([[-31, hy - 4], [-28, hy - 24], [-10, hy - 33], [12, hy - 33], [29, hy - 22], [31, hy - 6], [18, hy - 18], [-6, hy - 20]], o.hair, { alpha: .9 });+ hat(p, o.hat, hy, o);+ // face+ const bl = ((t + x * .0137) % 3.3) < .12;+ const ex = o.look || 0;+ if (o.glasses === "sun") { p.wash(ellPts(-12 + ex, hy - 1, 11, 8, 12), INK, { alpha: .9 }); p.wash(ellPts(12 + ex, hy - 1, 11, 8, 12), INK, { alpha: .9 }); p.stroke([[-2 + ex, hy - 2], [2 + ex, hy - 2]], { w: 3 }); }+ else {+ if (bl) { p.stroke([[-16 + ex, hy - 1], [-8 + ex, hy - 1]], { w: 3 }); p.stroke([[8 + ex, hy - 1], [16 + ex, hy - 1]], { w: 3 }); }+ else if (o.face === "sad") { p.stroke([[-17 + ex, hy + 1], [-12 + ex, hy - 4], [-7 + ex, hy + 1]], { w: 3 }); p.stroke([[7 + ex, hy + 1], [12 + ex, hy - 4], [17 + ex, hy + 1]], { w: 3 }); }+ else { p.dot(-12 + ex, hy - 1, 3.8); p.dot(12 + ex, hy - 1, 3.8); }+ if (o.glasses === "round") { p.ring(-12 + ex, hy - 1, 10, 10, { w: 2.6 }); p.ring(12 + ex, hy - 1, 10, 10, { w: 2.6 }); }+ }+ if (o.mustache) p.stroke([[-16, hy + 10], [-6, hy + 6], [0, hy + 9], [6, hy + 6], [16, hy + 10]], { w: 4.5, taper: .9 });+ const face = o.face || "smile";+ if (o.mask) { p.wash(rrect(-22, hy + 3, 44, 24, 8), "#E7F1F4", { alpha: .95 }); p.poly(rrect(-22, hy + 3, 44, 24, 8), { w: 2.8 }); p.stroke([[-22, hy + 8], [-31, hy]], { w: 2.2 }); p.stroke([[22, hy + 8], [31, hy]], { w: 2.2 }); }+ else if (face === "open") { p.wash(ellPts(0, hy + 14, 7, 8, 10), "#7A2A22", { alpha: .9 }); p.ring(0, hy + 14, 7, 8, { w: 2.6 }); }+ else if (face === "flat") p.stroke([[-8, hy + 15], [8, hy + 15]], { w: 3 });+ else if (face === "sad") p.stroke([[-9, hy + 18], [0, hy + 12], [9, hy + 18]], { w: 3 });+ else p.stroke([[-10, hy + 11], [0, hy + 17], [10, hy + 11]], { w: 3.2 });+ if (!o.mask && face !== "sad") { p.wash(ellPts(-20, hy + 9, 6, 4, 8), "#E58B7B", { alpha: .45 }); p.wash(ellPts(20, hy + 9, 6, 4, 8), "#E58B7B", { alpha: .45 }); }+ // body+ const torso = [[-22, -176], [22, -176], [30, -120], [31, -82], [-31, -82], [-30, -120]];+ p.wash(torso, o.shirt || WHITE, { alpha: .85, round: true });+ if (o.sash) p.wash([[-22, -172], [-10, -176], [30, -96], [22, -86]], o.sash, { alpha: .9 });+ if (o.jacketLine) p.stroke([[0, -176], [0, -84]], { w: 2.4 });+ p.blob(torso, { w: 4 });+ if (o.medals) { p.dot(-12, -150, 4, GOLD); p.dot(-4, -150, 4, RED); }+ // arms+ const [la, ra] = o.arms || [18, 18], [lb, rb] = o.bend || [0, 0];+ arm(p, -22, -166, la, lb, -1, sk); arm(p, 22, -166, ra, rb, 1, sk);+ // legs+ for (const [hx, a, sg] of [[-13, lg[0], -1], [13, lg[1], 1]]) {+ const fx = hx + Math.sin(rad(a)) * 80, fy = -82 + Math.cos(rad(a)) * 80;+ p.stroke([[hx, -84], [fx, fy]], { w: 5.2, taper: .3 });+ p.stroke([[fx - (sg < 0 ? 12 : 0), fy], [fx + (sg > 0 ? 12 : 0), fy]], { w: 6, taper: .2 });+ }+ ctx.restore();+}+function arm(p, sx, sy, a, b, sg, sk) {+ const d = (ang) => [sg * Math.sin(rad(ang)), Math.cos(rad(ang))];+ const [ux, uy] = d(a), ex = sx + ux * 42, ey = sy + uy * 42, [fx, fy] = d(a + b), hx = ex + fx * 40, hy = ey + fy * 40;+ p.stroke([[sx, sy], [ex, ey], [hx, hy]], { w: 4.6, taper: .3, smooth: false });+ p.wash(ellPts(hx, hy, 7, 7, 8), sk, { alpha: .8, wt: .2 }); p.ring(hx, hy, 7, 7, { w: 2.4, wt: .2 });+}+export function hat(p, kind, hy, o) {+ if (kind === "peci") { const P = [[-30, hy - 17], [-27, hy - 45], [27, hy - 45], [30, hy - 17], [0, hy - 21]]; p.wash(P, INK, { alpha: .92 }); p.poly([[-30, hy - 17], [-27, hy - 45], [27, hy - 45], [30, hy - 17]], { w: 3.4 }); }+ if (kind === "pith") { const P = []; for (let i = 0; i <= 10; i++) { const a = Math.PI + i / 10 * Math.PI; P.push([Math.cos(a) * 36, hy - 14 + Math.sin(a) * 30]); }+ p.wash([...P, [48, hy - 12], [-48, hy - 12]], SAND, { alpha: .9 }); p.stroke(P, { w: 3.6 }); p.stroke([[-50, hy - 12], [50, hy - 12]], { w: 4 }); }+ if (kind === "helmet") { const P = []; for (let i = 0; i <= 10; i++) { const a = Math.PI + i / 10 * Math.PI; P.push([Math.cos(a) * 37, hy - 6 + Math.sin(a) * 36]); }+ p.wash(P, "#3BAA5C", { alpha: .9 }); p.stroke([...P, P[0]], { w: 3.6 }); p.stroke([[10, hy - 8], [40, hy - 2]], { w: 3 }); }+ if (kind === "turban") { p.wash(ellPts(0, hy - 30, 36, 20, 14), WHITE, { alpha: .9 }); p.ring(0, hy - 30, 36, 20, { w: 3.2 }); p.stroke([[-30, hy - 30], [0, hy - 42], [30, hy - 26]], { w: 2.4 }); }+ if (kind === "fez") { const P = [[-22, hy - 22], [-18, hy - 56], [18, hy - 56], [22, hy - 22]]; p.wash(P, RED, { alpha: .9 }); p.poly(P, { w: 3.2 }); p.stroke([[0, hy - 56], [10, hy - 40]], { w: 2.2 }); }+ if (kind === "cap") { p.wash([[-32, hy - 12], [-26, hy - 34], [0, hy - 42], [26, hy - 34], [32, hy - 12], [56, hy - 10]], o.capColor || NAVY, { alpha: .9 }); p.stroke([[-32, hy - 12], [-26, hy - 34], [0, hy - 42], [26, hy - 34], [32, hy - 12], [56, hy - 10]], { w: 3.2 }); }+}+// head and shoulders only (delegates, masked faces)+export function bust(p, x, y, s, o, t) {+ const ctx = p.ctx; ctx.save(); ctx.translate(x, y + Math.sin(t * 3.3 + x) * 1.5); ctx.scale(s, s);+ const sh = [[-50, 0], [-44, -40], [-18, -60], [18, -60], [44, -40], [50, 0]];+ p.wash(sh, o.shirt || WHITE, { alpha: .85 }); p.stroke(sh, { w: 4, taper: .3 });+ const hy = -100, sk = o.skin || SKIN[0];+ p.wash(ellPts(0, hy, 31, 30, 18), sk, { alpha: .75 }); p.ring(0, hy, 32, 31, { w: 4.2 });+ if (o.hair) p.wash([[-31, hy - 4], [-28, hy - 24], [-10, hy - 33], [12, hy - 33], [29, hy - 22], [31, hy - 6], [18, hy - 18], [-6, hy - 20]], o.hair, { alpha: .9 });+ hat(p, o.hat, hy, o);+ const bl = ((t + x * .0137) % 3.1) < .12;+ if (bl) { p.stroke([[-16, hy - 1], [-8, hy - 1]], { w: 3 }); p.stroke([[8, hy - 1], [16, hy - 1]], { w: 3 }); } else { p.dot(-12, hy - 1, 3.8); p.dot(12, hy - 1, 3.8); }+ if (o.glasses === "round") { p.ring(-12, hy - 1, 10, 10, { w: 2.6 }); p.ring(12, hy - 1, 10, 10, { w: 2.6 }); }+ if (o.mask) { p.wash(rrect(-22, hy + 3, 44, 24, 8), "#E7F1F4", { alpha: .95 }); p.poly(rrect(-22, hy + 3, 44, 24, 8), { w: 2.8 }); p.stroke([[-22, hy + 8], [-31, hy]], { w: 2.2 }); p.stroke([[22, hy + 8], [31, hy]], { w: 2.2 }); }+ else p.stroke([[-10, hy + 11], [0, hy + 17], [10, hy + 11]], { w: 3.2 });+ ctx.restore();+}+export function bubble(p, x, y, str, o = {}) {+ const ctx = p.ctx; ctx.save(); ctx.font = `${o.size || 40}px "Patrick Hand"`;+ const w = ctx.measureText(str).width + 44, h = (o.size || 40) * 1.5; ctx.restore();+ const tail = o.tail ?? -1, B = rrect(x - w / 2, y - h / 2, w, h, h / 2);+ const tl = [[x + tail * w * .18 - 12, y + h / 2 - 3], [x + tail * w * .32, y + h / 2 + 22], [x + tail * w * .18 + 12, y + h / 2 - 3]];+ p.wash(B, WHITE, { alpha: .95, solid: true, wt: .2 }); p.wash(tl, WHITE, { alpha: .95, solid: true, wt: .1 });+ p.blob(B, { w: 3.6, wt: .6 }); p.stroke(tl, { w: 3.2, smooth: false, wt: .3 });+ p.text(str, x, y + (o.size || 40) * .33, { size: o.size || 40, color: o.color || INK, wt: .8 });+}+export function flagCloth(p, x, y, fw, fh, t, amp = 7) { // waving red-white flag, hoisted at (x, y) top-left+ const n = 12, top = [], mid = [], bot = [];+ for (let i = 0; i <= n; i++) { const u = i / n, dx = u * fw, wv = Math.sin(u * 5.2 - t * 7.5) * amp * u, sq = Math.sin(u * 5.2 - t * 7.5 + .6) * 2 * u;+ top.push([x + dx - sq, y + wv]); mid.push([x + dx - sq, y + fh / 2 + wv]); bot.push([x + dx - sq, y + fh + wv]); }+ p.wash([...top, ...mid.slice().reverse()], RED, { alpha: .95, ox: x, oy: y + fh / 4 });+ p.wash([...mid, ...bot.slice().reverse()], WHITE, { alpha: .95, ox: x, oy: y + fh * .75, solid: true });+ p.stroke(top, { w: 3.2, taper: .3 }); p.stroke(bot, { w: 3.2, taper: .3 }); p.stroke([top[n], bot[n]], { w: 3, taper: .2, smooth: false });+}+diff --git a/plugins/claude-animation/skills/claude-animation/lib/textures.mjs b/plugins/claude-animation/skills/claude-animation/lib/textures.mjsnew file mode 100644index 0000000..481b6c6--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/lib/textures.mjs@@ -0,0 +1,89 @@+// textures.mjs — surfaces. Heavy ones are built ONCE (per scene) into an offscreen canvas and blitted+// every frame; only what moves is drawn per frame. Each material gets three layers:+// base colour -> texture (grain / hatch / cells / fibre) -> edge (outline, rim light, pooled edge)+import { createCanvas, rng, hash, lerp, rad, ellipse, stroke, fill, line, hatch, fibre, grainCanvas, INK } from "./core.mjs";++// warm paper with printed grain+export function paper(W, H, color = "#F3EEDD", grain = .35) {+ const c = createCanvas(W, H), x = c.getContext("2d"); x.fillStyle = color; x.fillRect(0, 0, W, H);+ x.globalCompositeOperation = "multiply"; x.globalAlpha = grain; x.fillStyle = x.createPattern(grainCanvas(256, 40, 7), "repeat"); x.fillRect(0, 0, W, H);+ return c;+}+// warm paper with fibres, blotches and a soft vignette (the brush-ink look)+export function fibrePaper(W, H, color = "#F3EBDA") {+ const c = createCanvas(W, H), x = c.getContext("2d"); x.fillStyle = color; x.fillRect(0, 0, W, H);+ x.globalAlpha = .05; x.strokeStyle = "#8A7456"; x.lineWidth = 1;+ for (let i = 0; i < W * H / 800; i++) { const px = hash(i * 3.1) * W, py = hash(i * 5.7) * H, a = hash(i * 7.3) * Math.PI, l = 6 + hash(i * 1.9) * 22;+ x.beginPath(); x.moveTo(px, py); x.quadraticCurveTo(px + Math.cos(a) * l * .5 + 3, py + Math.sin(a) * l * .5, px + Math.cos(a) * l, py + Math.sin(a) * l); x.stroke(); }+ x.globalAlpha = 1;+ for (let i = 0; i < 26; i++) { const px = hash(i * 11.1) * W, py = hash(i * 13.3) * H, r = 80 + hash(i * 2.2) * 260, g = x.createRadialGradient(px, py, 0, px, py, r);+ g.addColorStop(0, "rgba(150,120,80,0.035)"); g.addColorStop(1, "rgba(150,120,80,0)"); x.fillStyle = g; x.fillRect(px - r, py - r, 2 * r, 2 * r); }+ x.globalCompositeOperation = "multiply"; x.globalAlpha = .55; x.fillStyle = x.createPattern(grainCanvas(256, 26, 5), "repeat"); x.fillRect(0, 0, W, H);+ x.globalCompositeOperation = "source-over"; x.globalAlpha = 1;+ const v = x.createRadialGradient(W / 2, H * .46, H * .35, W / 2, H / 2, Math.max(W, H) * .75); v.addColorStop(0, "rgba(90,70,40,0)"); v.addColorStop(1, "rgba(90,70,40,0.16)"); x.fillStyle = v; x.fillRect(0, 0, W, H);+ return c;+}+// wide diagonal light bands drifting across the sky (textured-editorial signature)+export function lightBands(ctx, W, H, t, { alpha = .55, color = "#EEDDB4", angle = 40, width = 78, gap = 250, drift = 14 } = {}) {+ ctx.save(); ctx.globalAlpha *= alpha; ctx.fillStyle = color; ctx.translate(W / 2, H / 2); ctx.rotate(rad(angle));+ const R = Math.hypot(W, H), off = (t * drift) % gap; for (let d = -R; d < R; d += gap) ctx.fillRect(-R, d + off, R * 2, width); ctx.restore();+}+// a textured sun: warm gradient, two crossing fibre hatches, outline, rays+export function sun(ctx, x, y, r, { rays = 12, rayColor = "#D9A035", len = [1.25, 1.6], rayW = 3 } = {}) {+ ctx.save(); ellipse(ctx, x, y, r, r); const g = ctx.createRadialGradient(x - r * .3, y - r * .3, r * .1, x, y, r); g.addColorStop(0, "#F6C35A"); g.addColorStop(1, "#EFA43A"); fill(ctx, g);+ fibre(ctx, () => ellipse(ctx, x, y, r, r), [x - r, y - r, x + r, y + r], Math.round(r * 5), rad(-60), r * .22, ["#E07D22", "#D9661B", "#F8D27A"], Math.max(1, r / 45), .55, 5);+ ellipse(ctx, x, y, r, r); stroke(ctx, Math.max(1.5, r / 36));+ for (let i = 0; i < rays; i++) { const a = i / rays * Math.PI * 2 + .12; line(ctx, [[x + Math.cos(a) * r * len[0], y + Math.sin(a) * r * len[0]], [x + Math.cos(a) * r * len[1], y + Math.sin(a) * r * len[1]]], rayW, rayColor); }+ ctx.restore();+}+export function moon(ctx, x, y, r) { ellipse(ctx, x, y, r, r); fill(ctx, "#D9D9DE"); ctx.save(); ellipse(ctx, x, y, r, r); ctx.clip(); ellipse(ctx, x + r * .5, y - r * .25, r * .95, r); fill(ctx, "#A8A8B6"); ctx.restore(); ellipse(ctx, x, y, r, r); stroke(ctx, 2.2); }+export function star4(ctx, x, y, r, color = "#EDEBFF") { ctx.fillStyle = color; ctx.beginPath(); for (let i = 0; i < 8; i++) { const a = i / 8 * Math.PI * 2 - Math.PI / 2, rr = i % 2 ? r * .23 : r; i ? ctx.lineTo(x + Math.cos(a) * rr, y + Math.sin(a) * rr) : ctx.moveTo(x + Math.cos(a) * rr, y + Math.sin(a) * rr); } ctx.closePath(); ctx.fill(); }+// a row of grass blades along a ground line+export function grass(ctx, y, x0, x1, h = 18, seed = 3, cols = ["#6FA45A", "#8DB872"]) {+ const r = rng(seed); ctx.save(); ctx.lineCap = "round";+ for (let x = x0; x < x1; x += 6 + r() * 6) { const hh = h * (.4 + r() * .8), lean = (r() - .5) * 8; ctx.strokeStyle = cols[r() > .5 ? 0 : 1]; ctx.lineWidth = 1.4;+ ctx.beginPath(); ctx.moveTo(x, y); ctx.quadraticCurveTo(x + lean * .3, y - hh * .6, x + lean, y - hh); ctx.stroke(); }+ ctx.restore();+}+// soil cross-section: "dig" (warm, pebbles), "day" (lighter, blotches), "night" (dark, star-like specks)+export function soil(W, H, kind = "day") {+ const c = createCanvas(W, H), x = c.getContext("2d"), r = rng({ dig: 11, night: 21, day: 31 }[kind] || 7);+ x.fillStyle = { dig: "#8C5E3D", night: "#3A2519", day: "#9A6A45" }[kind]; x.fillRect(0, 0, W, H);+ x.globalCompositeOperation = "multiply"; x.globalAlpha = .5; x.fillStyle = x.createPattern(grainCanvas(256, 70, 5 + kind.length), "repeat"); x.fillRect(0, 0, W, H);+ x.globalCompositeOperation = "source-over"; x.globalAlpha = 1;+ if (kind !== "night") hatch(x, () => { x.beginPath(); x.rect(0, 0, W, H); }, rad(-32), 7, "#5E3C24", 1, .25, [0, 0, W, H]);+ x.strokeStyle = kind === "night" ? "rgba(200,170,140,.35)" : "rgba(70,40,20,.55)"; x.lineWidth = 1.6;+ for (const f of [.24, .44, .65]) { const yy = f * H; x.beginPath(); for (let i = 0; i <= 40; i++) { const px = i / 40 * W, py = yy + Math.sin(i * .7 + yy) * 7 + Math.sin(i * 1.9) * 3; i ? x.lineTo(px, py) : x.moveTo(px, py); } x.stroke(); }+ for (let i = 0; i < W * H / (kind === "night" ? 3000 : 4400); i++) { const px = r() * W, py = r() * H, s = r();+ if (kind === "night") { x.fillStyle = s > .7 ? "rgba(240,225,200,.8)" : "rgba(160,120,90,.6)"; x.beginPath(); x.arc(px, py, .8 + s * 1.8, 0, 7); x.fill();+ if (s > .93) { ellipse(x, px, py, 9 + 6 * s, 6 + 4 * s, s * 3); stroke(x, 1, "rgba(200,170,140,.5)"); } }+ else if (s > .88 && kind === "dig") { ellipse(x, px, py, 12 + 8 * r(), 9 + 5 * r(), r() * 3); fill(x, "#E7D2A6"); stroke(x, 1.6, "#3B2414"); }+ else { x.fillStyle = s > .5 ? "#6E4529" : "#7E5233"; ellipse(x, px, py, 3 + s * 9, 2.5 + s * 6, r() * 3); x.fill(); } }+ return c;+}+// a night sky strip: navy, fine hatch, dots and four-point stars+export function nightSky(W, H, seed = 9) {+ const c = createCanvas(W, H), x = c.getContext("2d"), r = rng(seed); x.fillStyle = "#1C2458"; x.fillRect(0, 0, W, H);+ hatch(x, () => { x.beginPath(); x.rect(0, 0, W, H); }, rad(-20), 4, "#2A3470", 1, .6, [0, 0, W, H]);+ for (let i = 0; i < W * H / 6000; i++) { const px = r() * W, py = r() * H, s = r(); if (s > .82) star4(x, px, py, 7); else { x.fillStyle = "#EDEBFF"; x.beginPath(); x.arc(px, py, 1 + s, 0, 7); x.fill(); } }+ return c;+}+// fruit flesh as packed juice cells (watermelon, citrus with other colours)+export function fleshCells(w, h, { base = "#D02A3B", cell = [200, 30, 50], line = "rgba(120,10,25,.55)", hi = "rgba(255,200,205,.6)", size = 17 } = {}) {+ const c = createCanvas(w, h), x = c.getContext("2d"), r = rng(17); x.fillStyle = base; x.fillRect(0, 0, w, h);+ for (let yy = size / 2; yy < h; yy += size) for (let xx = (yy / size % 2) * size / 2; xx < w; xx += size + 1) {+ const px = xx + (r() - .5) * 6, py = yy + (r() - .5) * 5, rr = size * .42 + r() * 3;+ x.fillStyle = `rgba(${cell[0] + r() * 40 | 0},${cell[1] + r() * 25 | 0},${cell[2] + r() * 20 | 0},.9)`; ellipse(x, px, py, rr, rr * .85, r() * 3); x.fill(); x.strokeStyle = line; x.lineWidth = 1.4; x.stroke();+ if (r() > .6) { x.fillStyle = hi; x.beginPath(); x.arc(px - 2, py - 2, 1.4, 0, 7); x.fill(); } }+ return c;+}+// film finish: a few precomputed grain tiles cycled per frame + tiny exposure flicker + vignette+export function filmFinish(W, H, { tiles = 4, grain = .12, flicker = .025, vignette = .18 } = {}) {+ const T = Array.from({ length: tiles }, (_, i) => grainCanvas(256, 90, 101 + i * 7));+ const v = createCanvas(W, H), vx = v.getContext("2d"), g = vx.createRadialGradient(W / 2, H / 2, Math.min(W, H) * .35, W / 2, H / 2, Math.hypot(W, H) * .55);+ g.addColorStop(0, "rgba(40,30,20,0)"); g.addColorStop(1, `rgba(40,30,20,${vignette})`); vx.fillStyle = g; vx.fillRect(0, 0, W, H);+ return (ctx, frame) => { ctx.save(); ctx.globalCompositeOperation = "multiply"; ctx.globalAlpha = grain; const tile = T[frame % tiles];+ const ox = Math.floor(hash(frame) * 256), oy = Math.floor(hash(frame + 5) * 256); ctx.translate(-ox, -oy); ctx.fillStyle = ctx.createPattern(tile, "repeat"); ctx.fillRect(0, 0, W + 256, H + 256); ctx.restore();+ ctx.drawImage(v, 0, 0);+ const f = (hash(frame * 1.3) - .5) * 2 * flicker; if (f) { ctx.save(); ctx.globalCompositeOperation = f > 0 ? "screen" : "multiply"; ctx.fillStyle = f > 0 ? `rgba(255,250,240,${f})` : `rgba(0,0,0,${-f})`; ctx.fillRect(0, 0, W, H); ctx.restore(); } };+}diff --git a/plugins/claude-animation/skills/claude-animation/package.json b/plugins/claude-animation/skills/claude-animation/package.jsonnew file mode 100644index 0000000..b2a8cff--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/package.json@@ -0,0 +1,8 @@+{+ "name": "claude-animation",+ "version": "1.0.0",+ "private": true,+ "type": "module",+ "description": "Hand-drawn 2D animation in JavaScript: brush, watercolour, textured editorial rigs, rendered frame-exact with node canvas + ffmpeg.",+ "dependencies": { "@napi-rs/canvas": "^0.1.65" }+}diff --git a/plugins/claude-animation/skills/claude-animation/references/characters.md b/plugins/claude-animation/skills/claude-animation/references/characters.mdnew file mode 100644index 0000000..25edc91--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/characters.md@@ -0,0 +1,85 @@+# Characters and rigs++## The ant (`lib/rigs/ant.mjs`)++```js+import { ant, seed } from "<lib>/rigs/ant.mjs";+ant(ctx, x, groundY, s, {+ flip, // face left+ gait: t * 9, // walking: phase advances ~9 rad/s at normal pace; omit to stand still+ stride: 26, // step length (local units)+ ant: Math.sin(t * 5) * .5, // antenna sway, -1..1+ headDip: 14, // sniff / dig (px, local)+ jaw: .6, // mandibles open+ rear: 1, // stand up on the hind legs (pivots on the bottom of the gaster)+ overhead: (c) => seed(c, 1.35), // held above the head by the raised front legs+ carry: (c) => seed(c, .9), // held in the mandibles+ rot, pivot, // pitch the whole body: climbing a vine, tumbling, falling+ sweat: 1, blink: true, dust: 1,+ look: { ink: 1, fill: 0, tex: 0 }, // draw only some layers: build-up reveals (guides → ink → colour → texture)+});+antGuides(ctx, x, groundY, s, p); // blue construction shapes + centre crosses, drawn on as p goes 0 → 1+```++**Local space**: facing +x, origin on the ground under the waist, feet on y = 0. Body ≈ 300 × s px long,+≈ 150 × s px tall. `groundY` is the ground line in canvas px — pass it, don't compute an offset.++**Anatomy it draws** (all of it on every frame; this is what "detailed" means):+gaster with 3 tergite bands, form hatch, rim light, specular streak + dot, 16 setae · petiole with a node ·+mesosoma with pronotum hump, suture line, gloss, propodeal spine · head with hatch, clypeus line, compound+eye (faceted sheen, two highlights), toothed mandibles (near + far) · elbowed antennae: long scape, 10-bead+funiculus, club · six legs: coxa, femur, knee, tibia, 3-bead tarsus, two claws; far legs lighter and thinner ·+contact shadow.++**Legs are inverted Vs, not IK.** Each leg has a fixed hip, a knee offset (front: forward-up, mid: up, hind:+back-up, crossing the gaster) and a foot on the ground; walking slides the foot and half-slides the knee.+A two-bone IK was tried first and picked knees that crossed the body; explicit knees read cleaner in side+view. `core.mjs` keeps `ik(a, c, l1, l2, pref)` with a preferred knee *direction* for other rigs.++**Gait**: tripod — near front + near hind + far mid move together, the other three on the opposite phase.+The body bobs 3 px at twice the step rate. At `gait` speed ~9 rad/s with stride 26 the feet don't skate at+≈ 45 px/s × s of travel; tune `stride` to the travel speed, not the other way around.++**Acting vocabulary**:++| beat | pose |+|---|---|+| tugging | no gait, `rot` −6° → −18° over the tug, `headDip` 8, antenna sway fast |+| triumph, holding the prize | `rear: 1`, `overhead: seed`, snap in 0.07 s with `eBack` |+| digging | big scale, `headDip` 14, gait fast (26 rad/s) but no travel, dirt clods |+| carrying | `carry` in the mandibles, lean −5°, walk |+| curious | `headDip` rising to 16, antenna reaching forward (`ant` .6 → 1) |+| hot / tired | `sweat`, body lowered, slower gait |+| cutting a leaf | stand still, `headDip` 10 ± 5 at 30 rad/s, `jaw` 0.5 ± 0.5, leaf bits flying, a blue dashed cut line drawn first |+| climbing a vine | `rot` = path tangent from `pathOf(pts).at(u)`, speed lines behind |+| falling | `rot` spinning, then impact lines under the feet on landing |++**Build-up reveal** (the showcase's 2–7 s): draw `antGuides` first, then sweep a vertical line across the+ant; left of the line draw the next `look`, right of it the previous one (two clipped draws per frame).+Stages: guides → `{ink:1}` → `{ink:1, fill:1}` → full. Each draw call in the rig is classed by colour into+ink / fill / tex, so any new detail added to the rig joins the right layer automatically.++## The bean cast (`lib/rigs/bean.mjs`, brush-ink + watercolour look)++`person(pen, x, groundY, s, opts, t)` draws with a `Pen`, so the figure draws itself on (`pen.begin(name,+reveal)`) and can boil. Head circle 31 px with a skin wash, a bean torso washed in the shirt colour, stick+limbs 4.6 px, hands as small washed circles. Options: `hat` (peci, pith, helmet, turban, fez, cap), `glasses`+(sun, round), `arms [l, r]` degrees from straight down, `bend`, `face` (smile, open, flat, sad), `walk`+phase, `look`, `mustache`, `sash`, `medals`, `mask`, `flip`. Blinks every 3.3 s on its own. `bust()` for+crowds and tables, `bubble()` for speech, `flagCloth()` for a waving flag.++## Building a new creature rig++1. **Study sheet first.** Pull 3–5 reference images or frames of the creature and list its parts, their+ proportions (in body lengths) and how each moves. Write it as a comment at the top of the rig file.+2. **One local space, stated in the header**: origin on the ground under the centre of mass, facing +x,+ y up negative. The caller passes the ground line; nothing else knows about offsets.+3. **Parts as separate shapes**, drawn back to front: far limbs → body segments → near limbs → head →+ face details. Each part gets base + texture + edge (detail bible).+4. **Pose parameters, not keyframes**: a handful of named numbers (`gait`, `rear`, `headDip`, `jaw`, `blink`…)+ that the film animates. Defaults = a neutral standing pose.+5. **Secondary motion for free**: antennae, tails, ears, hair follow a sine of `t` plus a lag from turns.+6. **Test sheet before use**: standing, 4 walk phases, each special pose, flipped, and a 2× zoom crop —+ exactly what `ant-test` did. Fix the zoom crop until you would be happy to see it full screen.+7. **Seed from the name** of the character if anything in it is random (fur, spots), so it never changes+ between frames.diff --git a/plugins/claude-animation/skills/claude-animation/references/detail.md b/plugins/claude-animation/skills/claude-animation/references/detail.mdnew file mode 100644index 0000000..17ad315--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/detail.md@@ -0,0 +1,105 @@+# The detail bible++Why this file exists: the first storybook ant film had the right scenes, timing and layout, and still+read as cheap. Every gap was *detail*: stilt legs instead of a low-slung ant, a smooth sun instead of a+fibrous one, clover leaves instead of lobed melon leaves, one flat fill where a good illustration has+three layers. None of it is hard. It just has to be asked for, surface by+surface, before drawing — this file is the asking.++## Rule 1: three layers on every surface++| layer | what it is | how (lib) |+|---|---|---|+| **base** | the local colour, often a gentle gradient (light top-left, dark bottom-right) | `createRadialGradient` / `createLinearGradient`, or `pen.wash` in the watercolour look |+| **texture** | the material's own pattern: grain, hatch, cells, fibre, bands, veins | `hatch`, `fibre`, `grainOver`, `fleshCells`, `soil`, custom |+| **edge** | outline + one edge effect: rim light, pooled pigment, highlight, setae | `stroke`, a light arc inside the outline, a white streak, short hairs |++If you can only afford two, drop nothing from the hero and simplify the background (see line weight by depth).++## Rule 2: line weight and detail fall off with depth++| depth | outline | texture | example |+|---|---|---|---|+| hero (the thing the beat is about) | 2.6–3.4 px, near-black `#1E1612` | full: gradient + texture + highlight + setae | the ant, the seed, the sprout |+| midground | 1.6–2.4 px | one texture | the melon slice when the ant is the subject, the vine |+| background | 1–1.4 px or none, 40–60 % opacity | grain only | Gedung Merdeka sketch, strata lines, distant hills |+| construction guides | 1.2–2 px, `#5E80CC` blue, dashed where "projected" | none | circles with `+` centres, arrows, axis rulers with ticks |++## Materials++**Paper** (every frame): warm cream `#F3EEDD` + multiplied grain (`paper()`); for brush-ink looks,+fibres + faint blotches + vignette (`fibrePaper()`). In the editorial look add **diagonal light bands**+(`lightBands()`: 40°, 78 px wide every 250 px, `#EEDDB4` at 55 %, drifting 14 px/s). The bands are the+single most recognisable element of that style — never leave them out of a sky.++**Sun**: gradient `#F6C35A → #EFA43A`, then *fibre* strokes in two oranges and one pale yellow at −60°+(`sun()`), 1.5–3 px outline, 12 thin rays in `#D9A035`. A smooth disc reads as clip-art. In heat, rays go+red `#E4553A`, long and thick.++**Sky at night**: navy `#1C2458` + fine −20° hatch in `#2A3470` + dots + a few four-point stars (`nightSky()`).+A day/night band strip: day = cream with thin warm horizontal lines + small sun; night = lavender `#6E6FA8`+with dense hatch + moon (`moon()`) + dots.++**Soil cross-section** (`soil(kind)`): base brown, multiplied grain, −32° hatch at 7 px, three wavy+strata lines, then scatter: dark blotches (`day`), cream pebbles with dark outlines (`dig`), pale specks and+little outlined ovals (`night`). A horizon line 2.5–3 px and grass blades (`grass()`) on top.++**Fruit flesh**: packed juice cells (`fleshCells()`: 17 px cells, each a slightly different red, darker+outline, 40 % get a tiny highlight). Seeds: glossy teardrops with a white stroke highlight (`seed()`), one+pale unripe seed among the dark ones. **Rind**: outer dark green with vertical darker hatch, a light green+band with finer hatch, a pale pink band, then the flesh. The cut face on top: a thin parallelogram in a+lighter red with its own hatch and green rind ends. Every outline is separate: outer 4 px, bands 1.5 px.++**Chitin (insects)**: radial gradient `#A2653F → #5A301D → #26130B` from upper-left; form hatch at −60°+clipped to the lower half; segment bands (tergites) as darker arcs; a **specular streak** (white 70 %,+long thin ellipse, upper front) plus a small dot; a warm **rim light** arc along the bottom edge (bounce+light); **setae** — short hairs around the rear rim. All of these are in `rigs/ant.mjs`.++**Leaves**: never plain ellipses unless it's a cotyledon. Cotyledons: ellipse + midrib + 3 pairs of side+veins + hatch (`sprout()`). True leaves of cucurbits (melon, squash): five deep pointed lobes with+serrated edges, pale veins radiating from the petiole (`melonLeaf()`). Hatch at 40°. Outline 2.6 px.++**Vines and stems**: dark outline stroke, body stroke `#4E9E47`, a thin pale highlight offset up-left, and+tiny hairs every few samples (`vine()`). Tendrils end in a small closed curl-loop, never a plain spiral+(`tendril()`).++**Water**: drops are a teardrop with a white highlight (`drop()`); waves are a curling crest with a pale lip,+foam claws along the crest, darker body, lighter face, white foam arcs at the base.++**Light**: warm light = radial gradient drawn *over* a darkened scene (the candle in 1965, the door to+democracy): darken the whole plate with a multiply radial, then add the glow source-over. Colour grading+after the fact can't give you a light source.++## Characters: the detail checklist++Before a character appears on screen, it has all of these (the ant rig is the reference implementation):++- **Anatomy in segments**, each its own shape, not one silhouette (ant: head, mesosoma, petiole node, gaster).+- **Joints read**: limbs as femur + tibia + tarsus with a visible knee dot, thicker near the body.+- **Near side vs far side**: far limbs drawn first, lighter and thinner; near limbs over the body.+- **Eyes with two highlights** (a big one upper-left, a small one lower-right). One highlight = dead eye.+- **Mouth parts / hands that can act**: mandibles with teeth that open (`jaw`), front legs that can lift+ and hold (`rear`, `overhead`).+- **Antennae / hair / tail as secondary motion**: they sway (`ant: sin(t)`), lag behind turns, react.+- **Contact shadow** under the character on the ground (a flat dark ellipse at ~20 %).+- **Setae / fuzz / texture on the body** (short hairs on the gaster rim, fuzz on a bee).+- **Scale relative to the set**, decided per shot: a hero close-up ~45 % of frame width, a working shot+ ~15–25 %, a world shot ~5–9 % (and then it needs company: other ants, traffic, props).++## Props and effects that sell the moment++- **Burst lines** for a pop or a realisation (`burst()`): 7–14 short strokes around the contact, one frame+ after it, gone in ~0.3 s.+- **Speed lines** behind anything fast (`speedLines()`), 2–4 strokes, tapering.+- **Impact lines** under a landing (a fan below the feet).+- **Dirt clods** flying from a dig: small outlined ovals in the soil colour, re-seeded every 2 frames.+- **Construction guides** as a style device (blue circles with `+` centres, dashed spirals, arrows, axis+ rulers with ticks) — they explain the geometry of growth. Fade them as the real thing takes over.+- **Tally marks** to count time passing; a **day/night strip** that flips every ~0.33 s with the sun/moon+ stepping across.++## Before you render: the detail pass++Open a sheet at 3–6 key frames and ask of every visible thing: does it have base, texture, edge? Is the+hero the most detailed thing on screen? Do eyes have two highlights? Are the far limbs lighter? Is there a+contact shadow? Is anything still a flat fill? Fix, re-sheet, then render.diff --git a/plugins/claude-animation/skills/claude-animation/references/motion.md b/plugins/claude-animation/skills/claude-animation/references/motion.mdnew file mode 100644index 0000000..dec0fd8--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/motion.md@@ -0,0 +1,54 @@+# Motion: timing, acting, camera++## Timing that reads well (24 fps storybook films)++| thing | value |+|---|---|+| shot length | 0.8 – 2.7 s; the montage flips its sky every 0.33 s |+| a "pop" (seed out, stamp, reveal) | the change happens in 1–2 frames (0.04–0.07 s), then a hold |+| overshoot on pop-ins | `eBack` s ≈ 1.8–2.2 over 0.3–0.4 s (`popS`) |+| burst lines | appear the frame after the contact, gone within ~0.3 s |+| zoom-out transition | 0.55 s `eIO`, with a slight roll that reverses, the subject shrinking to ~15 % |+| camera tilt following a climb | ~220 px over 0.3 s in, held, 0.25 s out |+| growth (root, shoot, vine) | 0.7–2 s per segment, `ss` windows, leaves pop as the tip passes them |++## Principles that made the difference++- **Snap, then hold.** A change that takes 0.07 s and then holds reads as intentional. A change that eases+ over 0.5 s reads as a slideshow transition. Use the ease on the *settle*, not on the change.+- **Anticipation**: a small move the opposite way first (the ant leans back before the tug; the seed+ sinks before it pops).+- **Overlap**: parts arrive at different times — body first, antennae 2–3 frames later.+- **One thing moves at a time on screen** unless they're a group; stagger groups by 0.05–0.14 s.+- **Loops never all in phase**: every repeated thing gets its own phase (`i * 1.1`), and a looping element+ starts mid-cycle so the first frame isn't empty.+- **Holds need life**: breathing (±2 %), a blink every ~3.3 s, antennae sway, the light bands drifting.++## Exposure (ones, twos, holds)++`exposure(t, track, fps)` returns the time the drawings should show. Acting on twos (12 drawings/s at+24 fps) gives the hand-drawn cadence; fast flights, zooms and anything the camera tracks go on ones or+they strobe; a read gets a hold. Camera moves stay on ones even when the drawing is on twos: pass+`exposure(t)` to the drawing code and the raw `t` to the camera transform.++## Boil++Boil = the linework redrawn with slightly different jitter a few times a second. It is a *style choice+with a meaning* (alive, nervous, hand-made), not a default. The+textured-editorial look holds its still shots perfectly still; the brush-ink look boils at ~10 fps.+In the Pen, boil is opt-in: `pen.begin(name, reveal, { boil: 10, t })`.++## Camera++- The camera is a transform on the whole scene layer (`ctx.translate/scale/rotate` around a pivot), set+ per shot: locked, slow push (+5–10 % over the shot), pan (±30 px at ≥ 105 % so edges never show), tilt+ to follow a climb, zoom-out as a transition.+- Keep UI-ish overlays (day/night strip, tally, mascots, captions) OUT of the camera transform.+- Cuts: hard cuts on the beat. Transitions only when they mean something (zoom-out = "the world is+ bigger than this", iris = "and that's the end", whip = "meanwhile").++## Effects vocabulary++burst lines (a pop, a realisation) · speed lines (fast travel) · impact lines (landing) · dirt clods (dig)+· a dashed arc (a thrown or flicked thing's path) · a water drop with a highlight · shine dots on a revived+plant · a sweat drop · construction guides (explaining geometry) · a tally + day/night strip (time passing)diff --git a/plugins/claude-animation/skills/claude-animation/references/prior-art.md b/plugins/claude-animation/skills/claude-animation/references/prior-art.mdnew file mode 100644index 0000000..c1e7d2f--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/prior-art.md@@ -0,0 +1,32 @@+# Prior art: what other animation skills do, and what this one took++Read on 23 Sep 2026. Ideas only; no code was copied (one repo has no licence at all).++| repo | what it is | licence |+|---|---|---|+| IshaanKalra2103/creative-skills | 12 skills; `hand-drawn-canvas-animation` is a synced copy of alesha-pro's | MIT |+| alesha-pro/tools | the origin of `hand-drawn-canvas-animation` (Canvas 2D in headless Chrome, cels, exposure sheets, materials, verify) + MiniMax H3 prompt skills | MIT |+| misbahsy/claude-horizon-animation | `horizon-reel` (JSON-driven canvas reel), `sketch-to-sim` (three.js + physics) | **none — all rights reserved** |+| Ali0092/Sketchy | ~40 animated hand-drawn scenes in Compose Canvas + a `sketchy-illustrations` skill | MIT |++## Taken (and where it lives here)++1. **Decide cadence and boil on purpose** (twos for acting, boil only where it means something) → rule 4 in SKILL.md.+2. **Exposure: ones / twos / holds per action**, drawing clock separate from camera clock → `film.mjs exposure()`.+3. **Stroke seeds from stable names, boil opt-in** → `Pen.begin(name, reveal, { boil })`.+4. **Strip preview around fast actions + seek-determinism check** → `film.mjs strip`, `verify`.+5. **Beat sheet with an end state per beat, key beat mid-shot, "a cut must add information", camera stated+ for every row, emotion as behaviour** (from the H3 prompt skills) → `templates/beat-sheet.md`.+6. **Project bible pasted verbatim** (paraphrase causes drift) → style bible in the beat sheet.+7. **Film finish from a few precomputed grain tiles** cycled with offsets + flicker + vignette → `filmFinish()`.+8. **Pencil as broken thin passes; boxes with overshooting corners** → `pen.pencil`, `pen.box`.+9. **Line weight by depth; contact shadows; parts as poseable pieces** (Sketchy) → detail bible, ant rig.+10. **Stage renders, publish only after a good encode, write a sidecar** → `film.mjs render` + `render.json`.+11. **SFX from the same event timeline as the picture** → `scripts/sound.mjs`.++## Not taken++- A single huge global-script engine with shared top-level names (a name clash hangs the render).+- Headless-Chrome rendering: node canvas is faster, has no browser to manage, and is deterministic.+- Hedged docs ("optional", "not mandatory") — rules here are rules.+- Soft UI-style motion (gentle waves, no springs) as an acting model: wrong for characters.diff --git a/plugins/claude-animation/skills/claude-animation/references/sound.md b/plugins/claude-animation/skills/claude-animation/references/sound.mdnew file mode 100644index 0000000..7760864--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/sound.md@@ -0,0 +1,23 @@+# Sound++- **Cues come from the picture's timeline.** Each beat in the beat sheet has a cue time = the contact+ frame − ~0.03 s. Sound that lands late reads as broken; slightly early reads as synced.+- **`scripts/sound.mjs`** synthesises every effect (pop, tick, thump, crack, whoosh, whip, riser, scratch,+ sparkle, drip, boing, buzz), mixes them on the cue times over an optional bed, runs a two-pass loudnorm+ (default −16 LUFS, −1.5 dBTP) and muxes onto the picture. No sample library, nothing to license.+- Per cue: `vol`, `dur`, `pan` (−1..1) and `pitch` (a multiplier: typing and pops vary 0.9–1.3 so repeats+ don't sound pasted). Newer sounds: `splash`, `click` (typing, mandibles), `step` (tiny footfalls — one per+ ~0.1 s of walking sells a small character), `fall` (descending whistle), `chime`.+- `--bed-at 2.0` starts the music late: a hook that plays on typing and clicks alone, then the bed lands+ with the first cut, hits harder than music from frame 0.+- **`scripts/music.mjs`** makes an original ukulele bed (C–G–Am–F, pentatonic bell, shaker, soft kick):+ `--dur`, `--bpm`, `--end` (a final strum + bell on the last beat), `--quiet a-b,c-d` (hold one soft chord+ under sad or serious beats).+- Mapping used in the colony film: click (typing, mandibles chewing), step (every ~0.1 s of walking),+ whip + pop (each build stage), scratch + pop (the leaf piece comes free), riser + whoosh (the dive),+ sparkle + chime (the fungus garden grows, the queen lays), drip (nursery), chime (the end card).+- **No continuous "pencil drawing" scratch.** It was built (loudness following the ink laid per frame)+ and rejected: it competes with everything. Draw-on is silent; contacts make sound.+- Bed level under narration ≈ −22 dB relative; with no narration, bed at ~0.5 and SFX 0.3–0.6.+- Check the final: `ffmpeg -i final.mp4 -af loudnorm=print_format=summary -f null -` → integrated near the+ target, true peak ≤ −1.diff --git a/plugins/claude-animation/skills/claude-animation/references/styles.md b/plugins/claude-animation/skills/claude-animation/references/styles.mdnew file mode 100644index 0000000..7a12f42--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/styles.md@@ -0,0 +1,49 @@+# Style presets++Pick one per film and write its recipe into the style bible. Mixing presets inside a film reads as a mistake.++## 1. Textured editorial (the storybook look)++Storybook science illustration: calm, precise, tactile.+- Paper `#F3EEDD` + grain; diagonal **light bands** in the sky; soft film finish (grain tiles, ±2.5 % flicker,+ vignette .18).+- Ink `#1E1612`, 2.6–3.4 px on heroes, round joins; no boil on still shots; acting on twos.+- Every material textured (detail bible): fibre sun, cell-packed fruit, hatched soil with pebbles, glossy+ chitin with setae, lobed leaves with pale veins.+- Blue **construction guides** `#5E80CC` (circles with `+` centres, dashed spirals, arrows, rulers) as a+ device for growth and geometry.+- Palette: cream, melon red `#D02A3B`, leaf greens `#5EAA4E #94D46C`, soil browns `#8C5E3D #9A6A45`,+ night navy `#1C2458`, sun orange `#EFA43A`, one yellow `#F5CF3A`.+- Square 1080×1080, 24 fps.++## 2. Brush ink + watercolour (the history recap v2 look)++Hand-lettered explainer: lively, warm, a little imperfect.+- `fibrePaper()`; ink lines are **tapered brush strokes** (`pen.stroke`, w 4–6) that **boil at 10 fps**;+ shapes are filled with **watercolour washes** that bloom from a point (`pen.wash`), multiplied, with a+ pooled edge and granulation; lettering writes itself (`pen.text`).+- Things draw themselves on (`pen.begin(name, reveal)`), then act; exits pop out or get whipped away by+ the camera.+- Cast: `rigs/bean.mjs` people, washed clothes, stick limbs, blinking.+- Dark chapters: darken the plate with a multiply radial and let one light source glow through it.+- Palette: cream, ink `#2A2420`, one accent red `#D0312D`, soft greens/blues/yellows as washes.++## 3. Line doodle (the history recap v1 look)++Minimal: black line on cream, one red accent, a tiny mascot. Uniform 5 px strokes drawn on by length,+fills fade in after; a subtle SVG-turbulence-like wobble. Fast to make; reads as "made quickly". Use the+brush look instead when quality matters.++## 4. 3D extruded type around live action++For celebrating a number over footage (the "1 MILLION VIEWS" ring): glyphs placed on a cylinder around the+subject, width = cos(angle), extrusion drawn as 1-px-spaced layers along the inward normal, front half on a+layer above a person matte, back half below it. Flat ring (vertical radius ≈ 11 % of horizontal), slow spin+(~0.34 rad/s), land on the headline facing camera and hold ~2 s before turning. Temporal supersampling+(6 samples) for motion blur while it flies in or out.++## Matching a new reference++Make a swatch sheet before the film: paper, ink line at three weights, each material's three layers, one+character pose, side by side with crops from the reference. Adjust until a crop of yours could sit in their+frame. Then write the numbers down as a new preset here.diff --git a/plugins/claude-animation/skills/claude-animation/references/traps.md b/plugins/claude-animation/skills/claude-animation/references/traps.mdnew file mode 100644index 0000000..ff8ce65--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/traps.md@@ -0,0 +1,16 @@+# Traps (each one cost a render or a pass)++| # | Trap | Fix |+|---|---|---|+| 1 | **A per-call `ground` offset on a rig** drifted from the placement math: legs grew into stilts, and after the default was fixed, three call sites still passed the old value. | Rig origin = the ground point. Callers pass `groundY`. No offset parameter exists. When a fix "doesn't take", grep for overrides at the call sites. |+| 2 | **Two-bone IK chose knees that crossed the body** (the "higher" solution is not the readable one). | Explicit knee offsets per leg (inverted V), or `ik(..., pref=[dx,dy])` with a preferred knee direction. |+| 3 | **Rotating a standing-up character about its waist** sank its abdomen into the surface. | Pivot on the contact point that stays put (bottom of the gaster, the heel). |+| 4 | **Short polygons smoothed into blobs** (a 4-point tower became a rounded cone). | `wash(..., { sharp: true })`; the Pen smooths only polygons with > 6 points unless `round: true`. |+| 5 | **Multiply washes on a dark shape** (a phone screen) went muddy. | `wash(..., { over: true })` for opaque paint on dark. |+| 6 | **A preview image read back from cache** showed the old version, and a fix looked like it failed. | Write each sheet to a new filename, or check the file's mtime. |+| 7 | **zsh eats `$var:l`** (`measured_thresh=$e:linear` → `$e` + `:l` modifier). | Brace every variable in shell: `${e}`. `sound.mjs` does the loudnorm in node to avoid it. |+| 8 | **ffmpeg without `drawtext`** (common in homebrew builds). | Draw labels with canvas/PIL into a PNG and `overlay` it. |+| 9 | **A page's CSP blocks posting canvas frames to localhost**; an in-app browser pane that isn't displayed can't screenshot. | Use the user's real browser; read the network requests for the `.m3u8` and pull the file with ffmpeg. |+| 11 | **State carried between frames** (a counter, a cached "last position") breaks seeking and parallel renders. One film cached where an ant let go of a vine; `verify` passed only because its sample frames happened not to cross that moment. | Recompute from `t` (recompute the hand-off point from `t`). Pick `verify` frames that straddle every hand-off, or just never cache. |+| 12 | **Loud first draft of the SFX mix** clipped against the bed. | `sound.mjs` soft-clips (tanh) and loudnorms; keep individual SFX 0.3–0.6. |+| 13 | **Frame 0 empty** because everything pops in. | Start with something already on screen (open mid-action). |diff --git a/plugins/claude-animation/skills/claude-animation/references/workflow.md b/plugins/claude-animation/skills/claude-animation/references/workflow.mdnew file mode 100644index 0000000..b7f344f--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/references/workflow.md@@ -0,0 +1,28 @@+# Workflow: an original animation from a brief++1. **Brief → one paragraph**: who it's for, the story in three beats (setup, turn, payoff), length,+ format (1080×1080 for feeds, 1080×1920 vertical, 1920×1080 for YouTube), style preset+ (`references/styles.md`). Under a minute, a beat every 1–3 s.+2. **Style bible** (bottom of `templates/beat-sheet.md`): paper, ink, ≤ 6 colours + ink, which surfaces get+ which texture, line weight by depth, boil yes/no, the cast with scales. Paste it verbatim at the top of+ `film.mjs` as a comment; it stops the look drifting between sessions.+3. **Beat sheet**: every beat's start, duration, what the viewer notices, action → end state, camera,+ exposure, sound cue. If there's narration, lock beats to word timestamps (the start time of the word+ that names the thing), not to a stopwatch.+4. **Build** from `templates/film-template.mjs`:+ - `setup()` builds everything static once (paper, soil, sky, fruit texture, film finish).+ - `frame(ctx, t, i, S)` is scenes as functions of local time: `if (t < CUT[0]) sceneA(ctx, t) …`.+ - Inside a scene, every element is `at(ctx, x, y, scale, rot, () => draw())` driven by windows+ (`ss(a, b, t)`, `popS(t, t0)`, `eBack`, `eOut`) — never by state carried between frames.+ - Draw order is depth order: sky → bands → far set → ground → props → characters → effects → guides → finish.+5. **Look**: `node film.mjs sheet …` at every beat's end state. Fix. `strip` around each fast action and+ contact (12 frames). `verify` once.+6. **Detail pass** (`references/detail.md`, last section). This is where "fine" becomes "good".+7. **Render** (`node film.mjs render`), then **sound**: write `cues.json` from the beat sheet's cue+ column, `music.mjs` for a bed if the piece wants one, `sound.mjs` to mix and loudnorm.+8. **Check the master**: `ffmpeg -i out/final.mp4 -vf "fps=2,scale=480:-2,tile=6x6" -frames:v 1 sheet.jpg`+ and read it scene by scene; check duration and loudness. Only then deliver.++Speed reference (M-series Mac): the 32 s 1920×1080 colony film renders 768 frames in ~27 s; a 59 s+1920×1080 brush-watercolour film with two layers renders in ~100 s. Iterating on sheets is instant, so+iterate on sheets.diff --git a/plugins/claude-animation/skills/claude-animation/scripts/music.mjs b/plugins/claude-animation/skills/claude-animation/scripts/music.mjsnew file mode 100644index 0000000..30a2a64--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/scripts/music.mjs@@ -0,0 +1,105 @@+// music.mjs — an original, playful bed synthesised in code (no samples, nothing to license):+// Karplus-Strong ukulele strums on C-G-Am-F, a pentatonic bell motif, shaker and a soft kick.+// node music.mjs out.wav --dur 10.6 --bpm 108 --quiet 18.3-21.2,36.9-40.3 --end 10.2+// --quiet windows hold one soft chord (use for sad or serious beats); --end lands a final strum + bell.+import fs from "node:fs";++const A = process.argv, opt = (k, d) => A.includes(k) ? A[A.indexOf(k) + 1] : d;+const SR = 44100, DUR = parseFloat(opt("--dur", "30")), N = Math.floor(SR * DUR), END = parseFloat(opt("--end", String(DUR - 1.2)));+const L = new Float32Array(N), R = new Float32Array(N);+const BPM = parseFloat(opt("--bpm", "108")), BEAT = 60 / BPM, BAR = BEAT * 4;+const hz = (m) => 440 * Math.pow(2, (m - 69) / 12);++// quiet windows (seconds): the music steps back for the dark chapters+const QUIET = (opt("--quiet", "") || "").split(",").filter(Boolean).map((w) => w.split("-").map(Number));+const quiet = (t) => QUIET.some(([a, b]) => t >= a && t < b);+const intro = (t) => t < BAR; // first bar: strum only++function add(buf, i, v) { if (i >= 0 && i < N) buf[i] += v; }++function pluck(t, midi, amp, pan = 0, decay = 0.9965) {+ const f = hz(midi), P = Math.max(2, Math.round(SR / f));+ const ring = new Float32Array(P);+ let seed = (midi * 9301 + Math.round(t * 1000)) % 233280;+ for (let k = 0; k < P; k++) { seed = (seed * 9301 + 49297) % 233280; ring[k] = seed / 233280 * 2 - 1; }+ const start = Math.round(t * SR), len = Math.round(SR * 1.6);+ let idx = 0;+ for (let n = 0; n < len; n++) {+ const a = ring[idx], b = ring[(idx + 1) % P];+ ring[idx] = decay * 0.5 * (a + b);+ const env = Math.min(1, n / 40);+ add(L, start + n, a * amp * env * (1 - pan) * 0.5);+ add(R, start + n, a * amp * env * (1 + pan) * 0.5);+ idx = (idx + 1) % P;+ }+}+function strum(t, chord, amp, up = false) {+ const notes = up ? [...chord].reverse() : chord;+ notes.forEach((m, k) => pluck(t + k * 0.013, m, amp * (0.85 + 0.15 * (k % 2)), (k - 1.5) * 0.15));+}+function bell(t, midi, amp, pan = 0) {+ const f = hz(midi), start = Math.round(t * SR), len = Math.round(SR * 1.4);+ for (let n = 0; n < len; n++) {+ const s = n / SR, e = Math.exp(-s * 3.2) * Math.min(1, n / 60);+ const v = (Math.sin(2 * Math.PI * f * s) + 0.35 * Math.sin(2 * Math.PI * f * 2.76 * s) * Math.exp(-s * 6)+ + 0.18 * Math.sin(2 * Math.PI * f * 5.4 * s) * Math.exp(-s * 9)) * e * amp;+ add(L, start + n, v * (1 - pan) * 0.5); add(R, start + n, v * (1 + pan) * 0.5);+ }+}+function shaker(t, amp) {+ const start = Math.round(t * SR), len = Math.round(SR * 0.07); let prev = 0, seed = start % 9973;+ for (let n = 0; n < len; n++) {+ seed = (seed * 16807) % 2147483647; const w = seed / 2147483647 * 2 - 1;+ const hp = w - prev; prev = w; const e = Math.sin(Math.PI * n / len) ** 2;+ add(L, start + n, hp * e * amp * 0.45); add(R, start + n, hp * e * amp * 0.55);+ }+}+function kick(t, amp) {+ const start = Math.round(t * SR), len = Math.round(SR * 0.28); let ph = 0;+ for (let n = 0; n < len; n++) {+ const s = n / SR, f = 50 + 70 * Math.exp(-s * 28); ph += 2 * Math.PI * f / SR;+ const v = Math.sin(ph) * Math.exp(-s * 11) * amp; add(L, start + n, v); add(R, start + n, v);+ }+}+function pad(t0, t1, chord, amp) {+ const a = Math.round(t0 * SR), b = Math.round(t1 * SR);+ for (let n = a; n < b && n < N; n++) {+ const s = n / SR, x = (n - a) / (b - a), env = Math.min(1, x * 6, (1 - x) * 6) * amp;+ let v = 0; for (const m of chord) v += Math.sin(2 * Math.PI * hz(m) * s) * (m < 60 ? 1 : 0.5);+ add(L, n, v * env * 0.3); add(R, n, v * env * 0.3);+ }+}++// ukulele-ish voicings (midi): C, G, Am, F+const CH = [[60, 64, 67, 72], [59, 62, 67, 71], [57, 60, 64, 69], [57, 60, 65, 69]];+const MOTIF = [[0, 84], [0.5, 81], [1, 79], [1.5, 81], [2, 76], [3, 79]]; // C6 A5 G5 A5 E5 G5, pentatonic+const PAT = [[0, 1.0, false], [1, 0.7, false], [1.5, 0.55, true], [2.5, 0.6, true], [3, 0.8, false], [3.5, 0.5, true]];++for (let bar = 0; bar * BAR < DUR - 1.2; bar++) {+ const t0 = bar * BAR, chord = CH[bar % 4];+ if (quiet(t0) || quiet(t0 + BAR - 0.01)) continue;+ for (const [b, v, up] of PAT) { const t = t0 + b * BEAT; if (!quiet(t) && t < END) strum(t, chord, 0.34 * v, up); }+ if (intro(t0)) continue;+ for (let e = 0; e < 8; e++) { const t = t0 + e * BEAT / 2; if (!quiet(t) && t < END) shaker(t, e % 2 ? 0.16 : 0.08); }+ for (const b of [0, 2]) { const t = t0 + b * BEAT; if (!quiet(t) && t < END) kick(t, 0.55); }+ if (bar % 2 === 1) for (const [b, m] of MOTIF) { const t = t0 + b * BEAT; if (!quiet(t) && t < END) bell(t, m, 0.16, 0.2); }+}+// the quiet chapters: one held chord, nothing else+QUIET.forEach(([a, b], i) => pad(a, b + .1, i % 2 ? [41, 53, 57, 60] : [45, 57, 60, 64], 0.1));+// the ending: one big strum and a bell on "Merdeka!" then let it ring+strum(END, [60, 64, 67, 72], 0.55); strum(END + 0.28, [60, 64, 67, 72], 0.4, true);+bell(END, 84, 0.24); bell(END + .28, 88, 0.2, -0.2); kick(END, 0.7);++// normalise to -1 dBFS peak, soft-clip safety, write 16-bit stereo WAV+let pk = 0; for (let n = 0; n < N; n++) pk = Math.max(pk, Math.abs(L[n]), Math.abs(R[n]));+const g = 0.89 / pk, buf = Buffer.alloc(44 + N * 4);+buf.write("RIFF", 0); buf.writeUInt32LE(36 + N * 4, 4); buf.write("WAVEfmt ", 8); buf.writeUInt32LE(16, 16);+buf.writeUInt16LE(1, 20); buf.writeUInt16LE(2, 22); buf.writeUInt32LE(SR, 24); buf.writeUInt32LE(SR * 4, 28);+buf.writeUInt16LE(4, 32); buf.writeUInt16LE(16, 34); buf.write("data", 36); buf.writeUInt32LE(N * 4, 40);+for (let n = 0; n < N; n++) {+ const fade = n > N - SR * 1.2 ? (N - n) / (SR * 1.2) : 1;+ buf.writeInt16LE(Math.round(Math.tanh(L[n] * g) * fade * 32767), 44 + n * 4);+ buf.writeInt16LE(Math.round(Math.tanh(R[n] * g) * fade * 32767), 46 + n * 4);+}+fs.writeFileSync(A[2] && !A[2].startsWith("--") ? A[2] : "music.wav", buf);+console.log("music", DUR, "s, peak gain", g.toFixed(2));diff --git a/plugins/claude-animation/skills/claude-animation/scripts/rig-sheet.mjs b/plugins/claude-animation/skills/claude-animation/scripts/rig-sheet.mjsnew file mode 100644index 0000000..aa3e360--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/scripts/rig-sheet.mjs@@ -0,0 +1,20 @@+// rig-sheet.mjs — the test sheet every rig must pass before it goes into a film:+// four walk phases, the special poses, flipped, plus a 2x crop of one pose.+// node rig-sheet.mjs out.png+import path from "node:path";+import { fileURLToPath } from "node:url";+import fs from "node:fs";+const LIB = path.join(path.dirname(fileURLToPath(import.meta.url)), "../lib");+const { createCanvas } = await import(path.join(LIB, "core.mjs"));+const { ant, seed } = await import(path.join(LIB, "rigs/ant.mjs"));+const out = process.argv[2] || "rig-sheet.png";+const c = createCanvas(1800, 1000), x = c.getContext("2d"); x.fillStyle = "#F3EEDD"; x.fillRect(0, 0, 1800, 1000);+const G1 = 420, G2 = 900; x.fillStyle = "#9A6A45"; x.fillRect(0, G1, 1800, 30); x.fillRect(0, G2, 1800, 100);+[0, 1.2, 2.4, 3.6].forEach((ph, i) => ant(x, 180 + i * 330, G1, 1, { gait: ph, ant: Math.sin(i) }));+ant(x, 260, G2, 1.25, { rear: 1, overhead: (cc) => seed(cc, 1.5) });+ant(x, 700, G2, 1.25, { headDip: 18, ant: .8, jaw: .6, sweat: 1 });+ant(x, 1180, G2, 1.25, { carry: (cc) => seed(cc, .9), gait: .8, dust: 1 });+ant(x, 1640, G2, 1.25, { flip: true, blink: true });+fs.writeFileSync(out, c.toBuffer("image/png"));+const z = createCanvas(900, 600), zx = z.getContext("2d"); zx.drawImage(c, 560, 620, 450, 300, 0, 0, 900, 600);+fs.writeFileSync(out.replace(/\.png$/, "-zoom.png"), z.toBuffer("image/png")); console.log("wrote", out);diff --git a/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs b/plugins/claude-animation/skills/claude-animation/scripts/sound.mjsnew file mode 100644index 0000000..00940f5--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs@@ -0,0 +1,69 @@+// sound.mjs — sound from the same event timeline as the picture. No sample library needed: every+// effect is synthesised, so the skill works anywhere and nothing needs a licence.+//+// node sound.mjs cues.json picture.mp4 out.mp4 [--bed bed.wav --bed-vol .5 --bed-at 2.0 --lufs -16]+//+// cues.json: [{ "sfx": "pop", "t": 0.94, "vol": .5 }, { "sfx": "whoosh", "t": 1.08, "dur": .5 }, ...]+// sfx: pop | whoosh | whip | tick | thump | crack | sparkle | buzz | scratch | drip | boing | riser |+// splash | click | step | fall | chime (optional per cue: vol, dur, pan -1..1, pitch multiplier)+// Place a cue ~0.03 s BEFORE its visual: sound that lands late reads as broken, early reads as synced.+// The mix gets a two-pass loudnorm (default -16 LUFS, -1.5 dBTP) and is muxed onto the picture.+import fs from "node:fs";+import { execFileSync } from "node:child_process";++const SR = 48000;+const R = (() => { let s = 9; return () => (s = (s * 16807) % 2147483647) / 2147483647 * 2 - 1; })();+function tone(dur, f) { const n = Math.round(dur * SR), o = new Float32Array(n); for (let i = 0; i < n; i++) o[i] = f(i / SR, i / n); return o; }+const env = (u, a = .01, r = .9) => Math.min(1, u / a) * Math.pow(1 - u, r * 4);+function bandNoise(dur, fLo, fHi, shape) { let lp = 0, hp = 0, prev = 0; return tone(dur, (t, u) => { const w = R(); const f = fLo + (fHi - fLo) * (shape ? shape(u) : u);+ const a = Math.min(1, 2 * Math.PI * f / SR); lp += a * (w - lp); hp = lp - prev; prev = lp; return hp * 3 * env(u, .05, .6); }); }+export const SFX = {+ pop: (d = .14) => tone(d, (t, u) => Math.sin(2 * Math.PI * (900 - 600 * u) * t) * env(u, .005, 1.2) * .8),+ tick: (d = .03) => tone(d, (t, u) => Math.sin(2 * Math.PI * 2600 * t) * (1 - u) * .6),+ thump: (d = .28) => { let ph = 0; return tone(d, (t, u) => { ph += 2 * Math.PI * (50 + 90 * Math.exp(-t * 30)) / SR; return Math.sin(ph) * Math.exp(-t * 12) * .9; }); },+ crack: (d = .18) => tone(d, (t, u) => R() * Math.exp(-t * 40) * .8 + Math.sin(2 * Math.PI * 180 * t) * Math.exp(-t * 25) * .4),+ whoosh: (d = .5) => bandNoise(d, 300, 2400, (u) => Math.sin(u * Math.PI)),+ whip: (d = .3) => bandNoise(d, 800, 5000, (u) => u),+ riser: (d = 1.2) => bandNoise(d, 200, 3000, (u) => u * u),+ scratch: (d = .25) => tone(d, (t, u) => R() * (.5 + .5 * Math.sin(t * 90)) * env(u, .02, .5) * .5),+ sparkle: (d = .9) => tone(d, (t, u) => [2093, 2637, 3136, 4186].reduce((s, f, k) => s + Math.sin(2 * Math.PI * f * t) * Math.exp(-(t - k * .08 > 0 ? t - k * .08 : 99) * 6) * (t > k * .08 ? 1 : 0), 0) * .22),+ drip: (d = .2) => tone(d, (t, u) => Math.sin(2 * Math.PI * (600 + 900 * u) * t) * env(u, .005, 1) * .6),+ boing: (d = .5) => tone(d, (t, u) => Math.sin(2 * Math.PI * (220 + 60 * Math.sin(t * 40) * (1 - u)) * t) * env(u, .01, .8) * .6),+ splash: (d = .45) => { const a = bandNoise(d, 900, 4200, (u) => 1 - u); return tone(d, (t, u) => a[Math.floor(u * (a.length - 1))] * 1.2 * Math.exp(-t * 7) + Math.sin(2 * Math.PI * (500 + 700 * Math.exp(-t * 20)) * t) * Math.exp(-t * 18) * .35); },+ click: (d = .05) => tone(d, (t, u) => (Math.sin(2 * Math.PI * 3400 * t) * .5 + R() * .5) * Math.exp(-t * 180) * .9),+ step: (d = .04) => tone(d, (t, u) => (Math.sin(2 * Math.PI * 900 * t) * .6 + R() * .3) * Math.exp(-t * 140) * .5),+ fall: (d = .45) => tone(d, (t, u) => Math.sin(2 * Math.PI * (1800 - 1300 * u) * t) * Math.min(1, u * 8) * (1 - u) * .35),+ chime: (d = 1.2) => tone(d, (t, u) => [1047, 1319, 1568, 2093].reduce((s, f, k) => s + (t > k * .07 ? Math.sin(2 * Math.PI * f * t) * Math.exp(-(t - k * .07) * 3.5) : 0), 0) * .2),+ buzz: (d = .6) => { let ph = 0; return tone(d, (t, u) => { ph += (215 + 18 * Math.sin(t * 38)) / SR; return (2 * (ph % 1) - 1) * .3 * Math.min(1, t / .08, (d - t) / .2) * (.7 + .3 * Math.sin(t * 90)); }); },+};+function readWav(file) { // 16-bit PCM wav -> mono float at its own rate (resampled nearest to SR)+ const b = fs.readFileSync(file); let o = 12, fmt, data; while (o < b.length) { const id = b.toString("ascii", o, o + 4), sz = b.readUInt32LE(o + 4); if (id === "fmt ") fmt = o + 8; if (id === "data") { data = [o + 8, sz]; break; } o += 8 + sz; }+ const ch = b.readUInt16LE(fmt + 2), sr = b.readUInt32LE(fmt + 4), n = data[1] / (2 * ch), out = new Float32Array(Math.round(n * SR / sr));+ for (let i = 0; i < out.length; i++) { const j = Math.min(n - 1, Math.floor(i * sr / SR)); let v = 0; for (let c = 0; c < ch; c++) v += b.readInt16LE(data[0] + (j * ch + c) * 2); out[i] = v / ch / 32768; }+ return out;+}+function writeWav(file, L, Rr) {+ const n = L.length, b = Buffer.alloc(44 + n * 4); b.write("RIFF", 0); b.writeUInt32LE(36 + n * 4, 4); b.write("WAVEfmt ", 8); b.writeUInt32LE(16, 16); b.writeUInt16LE(1, 20); b.writeUInt16LE(2, 22);+ b.writeUInt32LE(SR, 24); b.writeUInt32LE(SR * 4, 28); b.writeUInt16LE(4, 32); b.writeUInt16LE(16, 34); b.write("data", 36); b.writeUInt32LE(n * 4, 40);+ for (let i = 0; i < n; i++) { b.writeInt16LE(Math.round(Math.tanh(L[i]) * 32000), 44 + i * 4); b.writeInt16LE(Math.round(Math.tanh(Rr[i]) * 32000), 46 + i * 4); } fs.writeFileSync(file, b);+}+export function mix(cues, dur, bed, bedVol = .5, bedAt = 0) {+ const n = Math.round(dur * SR), L = new Float32Array(n), Rr = new Float32Array(n);+ if (bed) { const B = readWav(bed), o = Math.round(bedAt * SR); for (let i = 0; i + o < n && i < B.length; i++) { L[i + o] += B[i] * bedVol; Rr[i + o] += B[i] * bedVol; } }+ for (const c of cues) { let s = (SFX[c.sfx] || SFX.pop)(c.dur), v = c.vol ?? .5, pan = c.pan ?? 0, i0 = Math.round(c.t * SR);+ if (c.pitch && c.pitch !== 1) { const q = new Float32Array(Math.floor(s.length / c.pitch)); for (let i = 0; i < q.length; i++) q[i] = s[Math.floor(i * c.pitch)]; s = q; }+ for (let i = 0; i < s.length && i0 + i < n; i++) if (i0 + i >= 0) { L[i0 + i] += s[i] * v * (1 - pan) ; Rr[i0 + i] += s[i] * v * (1 + pan); } }+ return [L, Rr];+}+if (process.argv[1] && process.argv[1].endsWith("sound.mjs")) {+ const [, , cueFile, pic, out] = process.argv, a = process.argv, opt = (k, d) => a.includes(k) ? a[a.indexOf(k) + 1] : d;+ const dur = parseFloat(execFileSync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", pic]).toString());+ const [L, Rr] = mix(JSON.parse(fs.readFileSync(cueFile, "utf8")), dur, opt("--bed"), parseFloat(opt("--bed-vol", ".5")), parseFloat(opt("--bed-at", "0")));+ const tmp = out.replace(/\.mp4$/, "") + ".mix.wav"; writeWav(tmp, L, Rr);+ const I = opt("--lufs", "-16");+ let meas; try { meas = JSON.parse((execFileSync("sh", ["-c", `ffmpeg -hide_banner -nostats -i "${tmp}" -af loudnorm=I=${I}:TP=-1.5:print_format=json -f null - 2>&1`]).toString().match(/\{[^{]*input_i[\s\S]*?\}/) || ["{}"])[0]); } catch { meas = {}; }+ const ln = meas.input_i ? `loudnorm=I=${I}:TP=-1.5:LRA=11:measured_I=${meas.input_i}:measured_TP=${meas.input_tp}:measured_LRA=${meas.input_lra}:measured_thresh=${meas.input_thresh}:linear=true,aresample=48000` : `loudnorm=I=${I}:TP=-1.5`;+ execFileSync("ffmpeg", ["-v", "error", "-y", "-i", pic, "-i", tmp, "-af", ln, "-c:v", "copy", "-c:a", "aac", "-b:a", "192k", "-shortest", "-movflags", "+faststart", out]);+ fs.unlinkSync(tmp);+ console.log("wrote", out, meas.input_i ? `(mix was ${meas.input_i} LUFS)` : "");+}diff --git a/plugins/claude-animation/skills/claude-animation/templates/beat-sheet.md b/plugins/claude-animation/skills/claude-animation/templates/beat-sheet.mdnew file mode 100644index 0000000..070946c--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/templates/beat-sheet.md@@ -0,0 +1,26 @@+# Beat sheet — fill this BEFORE writing drawing code++One row per beat. A beat is one change the viewer could point at, followed by the hold that lets it land.+If a row has no "end state", it is not a beat yet.++| # | start | dur | the viewer notices | action → end state | camera | exposure | sound cue (t) |+|---|---|---|---|---|---|---|---|+| 1 | 0.00 | 0.95 | an ant tugging a seed out of a melon | lean, tug ×2 → the seed pops free | locked | twos | pop 0.93 |+| 2 | 0.95 | 0.90 | the melon is huge and the ant tiny | stands with the seed overhead → zoom-out, slice flies off | pull back + roll | ones (fast) | whoosh 1.08 |+| … | | | | | | | |++Rules for the table+- **The key beat of a shot sits in its middle**, not at the end where the cut eats it.+- **A cut must add information.** If the next shot shows the same thing bigger, move the camera instead.+- **State the camera for every row**, even "locked". For a locked shot, name what must NOT move.+- **Show feeling as behaviour**: "antenna droops, body sinks 6 px", not "the ant is sad".+- **Exposure per action**: twos for acting, ones for fast flights, zooms and anything the camera tracks, hold+ for a read. Decide it here, not in code.+- **Sound cue = the frame of the contact minus ~0.03 s.** Write it in this table; `cues.json` is generated+ from the same numbers.++Style bible (paste verbatim into every build session; paraphrasing it causes drift)+- Paper: … | Ink: … px, colour … | Palette: … (max 6 + ink) | Textures: which surfaces get grain / hatch / cells+- Line weight by depth: hero … px, midground … px, background … px or no outline+- Boil: none / only on … at … fps+- Cast: rig names + scale (e.g. `ant` s=1.3 on the melon, 1.9 in the dig close-up, .6 on the vine)diff --git a/plugins/claude-animation/skills/claude-animation/templates/film-template.mjs b/plugins/claude-animation/skills/claude-animation/templates/film-template.mjsnew file mode 100644index 0000000..5bce201--- /dev/null+++ b/plugins/claude-animation/skills/claude-animation/templates/film-template.mjs@@ -0,0 +1,38 @@+// film-template.mjs — copy to your project as film.mjs, set LIB, then edit the [EDIT] regions.+// node film.mjs sheet 0,1,2,3 -> look before you render+// node film.mjs strip 1.9 12 -> 12 consecutive frames around a fast action+// node film.mjs verify -> frames must not depend on render order+// node film.mjs render -> out/<name>.mp4+// This template: an ant walks in on a textured-editorial set, sniffs a sprout, a bee drifts past.+import path from "node:path";+import { fileURLToPath } from "node:url";+const HERE = path.dirname(fileURLToPath(import.meta.url));+const LIB = process.env.CLAUDE_ANIMATION_LIB || path.join(HERE, "../lib"); // [EDIT] path to the skill's lib/+const { clamp, lerp, ss, eOut, popS, at, line, burst, INK } = await import(path.join(LIB, "core.mjs"));+const { paper, lightBands, sun, grass, soil, filmFinish } = await import(path.join(LIB, "textures.mjs"));+const { sprout, bee } = await import(path.join(LIB, "nature.mjs"));+const { ant } = await import(path.join(LIB, "rigs/ant.mjs"));+const { run, exposure } = await import(path.join(LIB, "film.mjs"));++// [EDIT] format and length+const W = 1080, H = 1080, FPS = 24, DUR = 5;+const G = 790; // ground line++run({+ name: "template", W, H, fps: FPS, dur: DUR, out: path.join(process.cwd(), "out"),+ // heavy, static layers are built ONCE here+ setup() { return { paper: paper(W, H), soil: soil(W, H - G, "day"), finish: filmFinish(W, H, { grain: .1 }) }; },+ frame(ctx, t, i, S) {+ const d = exposure(t, [{ at: 0, on: 2 }], FPS); // drawings on twos; the camera could stay on ones+ ctx.drawImage(S.paper, 0, 0); lightBands(ctx, W, H, t);+ sun(ctx, 860, 60, 120);+ ctx.drawImage(S.soil, 0, G); line(ctx, [[0, G], [W, G]], 2.5); grass(ctx, G, 0, W, 20, 12);+ // [EDIT] the beats. Every beat: one change the viewer could point at, then a hold.+ at(ctx, 330, G, 1.2 * popS(d, .3, .4), 0, () => sprout(ctx, { sway: Math.sin(d * 3) }));+ const walk = 1 - eOut(clamp((d - .2) / 2.2)); // walk in, decelerate+ ant(ctx, lerp(1250, 640, 1 - walk), G, 1.1, { flip: true, gait: walk > .01 ? d * 9 : undefined, ant: Math.sin(d * 5) * .5, headDip: ss(2.6, 3.0, d) * 16 });+ if (d > 3.0 && d < 3.5) burst(ctx, 450, 640, 150, 185, 8, 3, INK, Math.PI * 1.05, Math.PI * .9);+ if (d > 3.4) at(ctx, lerp(1180, 820, eOut((d - 3.4) / 1.2)), 240 + Math.sin(d * 18) * 5, .9, 0, () => bee(ctx, t));+ S.finish(ctx, i); // grain tiles + flicker + vignette, last+ },+});