Skip to content

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

Add game-feel kit and a 30 s video-game example

buildwithhanif253842a02f43
diff --git a/README.md b/README.md
index 4a89449..edbf8d4 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,19 @@ roots, and `nestCanvas()` — chambers and tunnels baked into textured soil, ret
`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
+## The example films
+
+`examples/claude-game/` — 30 s, 16:9 video-game short: an orange block hero runs, jumps and flips across
+a textured platform level, punches, kicks and stomps bugs, then fights a boss. Hit-stop on every contact,
+screen shake, sparks, comic words, damage numbers, a combo counter, a boss HP bar, a charged special, K.O.,
+LEVEL CLEAR. Chiptune soundtrack and 132 sound effects, all synthesised.
+
+![combo on the boss](docs/game-combo.jpg)
+
+![the game short, one frame per second](docs/game-contact.jpg)
+
+### The colony
+
`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
@@ -84,15 +96,20 @@ plugins/claude-animation/skills/claude-animation/
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/fx.mjs hit-stop, screen shake, particles, rings, flashes, comic words, damage numbers, afterimages
+ lib/rigs/critter.mjs a blocky action hero (run, jump, flip, punch, kick, hurt, charge)
+ lib/rigs/bug.mjs a beetle enemy and boss
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/chiptune.mjs an original video-game soundtrack with timed sections
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
+examples/claude-game/ the 30 s video-game short
+examples/ant-colony/ the 32 s colony film
```
Ideas from other animation skills are credited in `references/prior-art.md`.
diff --git a/docs/game-combo.jpg b/docs/game-combo.jpg
new file mode 100644
index 0000000..cb5ab79
Binary files /dev/null and b/docs/game-combo.jpg differ
diff --git a/docs/game-contact.jpg b/docs/game-contact.jpg
new file mode 100644
index 0000000..3304a61
Binary files /dev/null and b/docs/game-contact.jpg differ
diff --git a/examples/claude-game/film.mjs b/examples/claude-game/film.mjs
new file mode 100644
index 0000000..7d954cf
--- /dev/null
+++ b/examples/claude-game/film.mjs
@@ -0,0 +1,327 @@
+// film.mjs — "CLAUDE vs THE BUGS": a 30 s, 16:9 video-game short made with the claude-animation skill.
+// node film.mjs sheet 1,4.8,7.8,12.9,19.5,23.3 | strip 7.6 12 | verify | cues | render
+//
+// STYLE BIBLE: textured storybook art (paper grain, hatching, gradients, ink outlines) + video-game grammar
+// (HUD, hit-stop, screen shake, sparks, comic words, damage numbers, combo counter, boss bar, K.O., LEVEL CLEAR).
+// Hero: an orange block critter (lib/rigs/critter.mjs). Enemies: bugs (lib/rigs/bug.mjs). Palette: warm cream,
+// hero orange #D97757, bug purples/greens, gold #FFD35A for impacts, red #E5484D for danger/hearts.
+//
+// All choreography is written in GAME time g. Hit-stop (lib/fx.mjs timeWarp) freezes g for a few frames on
+// every contact while effects keep running in real time t — that freeze is what makes hits feel heavy.
+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, speedLines, rrect, rng, rad, hash, createCanvas, INK } = await import(path.join(LIB, "core.mjs"));
+const { paper, lightBands, sun, grass, filmFinish } = await import(path.join(LIB, "textures.mjs"));
+const { blossom } = await import(path.join(LIB, "nature.mjs"));
+const { timeWarp, shake, burstParticles, landDust, ring, flashAlpha, comicText, floatText, afterimages, starburst, heart } = await import(path.join(LIB, "fx.mjs"));
+const { critter } = await import(path.join(LIB, "rigs/critter.mjs"));
+const { bug } = await import(path.join(LIB, "rigs/bug.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, "Montserrat/Montserrat-Black.ttf"), "MBlack"); 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 = 30, G = 880, WORLD = 5000;
+const ORANGE = "#D97757", GOLD = "#FFD35A", RED = "#E5484D";
+
+// ---------------------------------------------------------------- hit-stop
+const STOPS = [[7.72, .083], [8.42, .083], [9.45, .083], [12.82, .125], [19.2, .083], [19.45, .083], [19.7, .083], [19.95, .083], [20.25, .125], [23.15, .3]];
+const TW = timeWarp(STOPS), R = (g) => TW.real(g);
+const END_T = 27.2; // real time the end card starts
+
+// ---------------------------------------------------------------- the hero's choreography (game time)
+const SEG = [
+ { a: 0, b: .3, k: "hide" },
+ { a: .3, b: 1.0, k: "fall", p0: [420, -260], p1: [420, G] },
+ { a: 1.0, b: 2.5, k: "idle", p: [420, G] },
+ { a: 2.5, b: 3.4, k: "run", p0: [420, G], p1: [1180, G] },
+ { a: 3.4, b: 4.05, k: "jump", p0: [1180, G], p1: [1400, 700], h: 230 },
+ { a: 4.05, b: 4.55, k: "run", p0: [1400, 700], p1: [1560, 700] },
+ { a: 4.55, b: 5.35, k: "jump", p0: [1560, 700], p1: [1880, 560], h: 260, flip: true },
+ { a: 5.35, b: 5.85, k: "run", p0: [1880, 560], p1: [2080, 560] },
+ { a: 5.85, b: 6.6, k: "jump", p0: [2080, 560], p1: [2420, G], h: 120 },
+ { a: 6.6, b: 7.35, k: "idle", p: [2420, G], face: (g) => g > 6.85 ? "surprised" : "normal" },
+ { a: 7.35, b: 7.65, k: "dash", p0: [2420, G], p1: [2700, G] },
+ { a: 7.65, b: 8.35, k: "punch", p: [2700, G], hits: [7.72] },
+ { a: 8.35, b: 8.8, k: "kick", p: [2700, G], hits: [8.42] },
+ { a: 8.8, b: 9.45, k: "jump", p0: [2700, G], p1: [2960, G - 62], h: 300 },
+ { a: 9.45, b: 10.05, k: "jump", p0: [2960, G - 62], p1: [3080, G], h: 180 },
+ { a: 10.05, b: 11.3, k: "idle", p: [3080, G], face: () => "happy", arms: "up" },
+ { a: 11.3, b: 11.9, k: "knock", p0: [3080, G], p1: [2880, G], h: 90 },
+ { a: 11.9, b: 12.45, k: "idle", p: [2880, G], face: (g) => g < 12.15 ? "hurt" : "angry" },
+ { a: 12.45, b: 13.1, k: "punch", p: [2880, G], hits: [12.82] },
+ { a: 13.1, b: 16.82, k: "idle", p: [2880, G], face: (g) => g > 14.5 && g < 15.6 ? "surprised" : g > 15.6 ? "focus" : "normal", arms: (g) => g > 15.6 ? "guard" : "rest" },
+ { a: 16.82, b: 17.3, k: "jump", p0: [2880, G], p1: [2960, G], h: 200 },
+ { a: 17.3, b: 17.52, k: "idle", p: [2960, G], face: () => "focus", arms: "guard" },
+ { a: 17.52, b: 18.0, k: "jump", p0: [2960, G], p1: [3040, G], h: 200 },
+ { a: 18.0, b: 18.22, k: "idle", p: [3040, G], face: () => "focus", arms: "guard" },
+ { a: 18.22, b: 18.7, k: "jump", p0: [3040, G], p1: [3120, G], h: 200 },
+ { a: 18.7, b: 18.75, k: "idle", p: [3120, G], face: () => "angry" },
+ { a: 18.75, b: 19.1, k: "dash", p0: [3120, G], p1: [3520, G] },
+ { a: 19.1, b: 20.45, k: "combo", p: [3520, G], hits: [19.2, 19.45, 19.7, 19.95, 20.25] },
+ { a: 20.45, b: 20.6, k: "idle", p: [3520, G], face: () => "surprised" },
+ { a: 20.6, b: 21.2, k: "knock", p0: [3520, G], p1: [3200, G], h: 150 },
+ { a: 21.2, b: 22.6, k: "charge", p: [3200, G] },
+ { a: 22.6, b: 22.9, k: "jump", p0: [3200, G], p1: [3260, 690], h: 80, throw: true },
+ { a: 22.9, b: 23.25, k: "jump", p0: [3260, 690], p1: [3300, G], h: 30 },
+ { a: 23.25, b: 24.3, k: "idle", p: [3300, G], face: (g) => g > 23.95 ? "happy" : "focus" },
+ { a: 24.3, b: 24.7, k: "jump", p0: [3300, G], p1: [3300, G], h: 170, cheer: true },
+ { a: 24.7, b: 24.9, k: "idle", p: [3300, G], face: () => "happy", arms: "up" },
+ { a: 24.9, b: 25.3, k: "jump", p0: [3300, G], p1: [3300, G], h: 170, cheer: true, flip: true },
+ { a: 25.3, b: 99, k: "idle", p: [3300, G], face: () => "happy", arms: "up" },
+];
+const LANDS = SEG.filter((s) => ["fall", "jump", "knock"].includes(s.k) && s.p1[1] >= G - 70).map((s) => s.b);
+const JUMP_STARTS = SEG.filter((s) => s.k === "jump").map((s) => s.a);
+const segAt = (g) => SEG.find((s) => g >= s.a && g < s.b) || SEG[SEG.length - 1];
+const hitProfile = (g, h, up = .07, hold = .1, down = .2) => ss(h - up, h, g) * (1 - ss(h + hold, h + hold + down, g));
+function hero(g) {
+ const s = segAt(g), k = clamp((g - s.a) / (s.b - s.a)), o = { x: 0, y: G, pose: { t: g } };
+ const P = o.pose;
+ if (s.k === "hide") { o.hide = true; return o; }
+ if (s.k === "fall") { o.x = s.p0[0]; o.y = lerp(s.p0[1], s.p1[1], eIn(k)); P.sq = .78; P.air = true; P.face = "surprised"; }
+ else if (s.k === "idle" || s.k === "charge") { [o.x, o.y] = s.p; P.sq = 1 + .03 * Math.sin(g * 5); P.face = s.face ? s.face(g) : ((g % 3.1) < .1 ? "blink" : "normal"); P.arms = typeof s.arms === "function" ? s.arms(g) : s.arms;
+ if (s.k === "charge") { P.crouch = .6 * ss(0, .2, k); P.aura = ss(0, .8, k); P.face = "focus"; o.x += Math.sin(g * 70) * 2.5 * P.aura; } }
+ else if (s.k === "run") { o.x = lerp(s.p0[0], s.p1[0], k); o.y = s.p0[1]; P.gait = g * 18; P.sq = 1 + .05 * Math.sin(g * 36); }
+ else if (s.k === "jump" || s.k === "knock") { o.x = lerp(s.p0[0], s.p1[0], s.k === "knock" ? eOut(k) : k); o.y = lerp(s.p0[1], s.p1[1], k) - s.h * 4 * k * (1 - k); P.air = true;
+ P.sq = k < .35 ? .8 : k > .8 ? .9 : 1; if (s.flip) P.rot = -Math.PI * 2 * eIO(k); if (s.cheer) { P.arms = "up"; P.face = "happy"; }
+ if (s.k === "knock") { P.face = "hurt"; P.rot = -.5 * Math.sin(k * Math.PI); P.flash = 1 - ss(0, .25, k); }
+ if (s.throw) { P.arms = "up"; P.face = "angry"; } }
+ else if (s.k === "dash") { o.x = lerp(s.p0[0], s.p1[0], eOut(k)); o.y = s.p0[1]; P.sq = .72; P.rot = .12; P.face = "angry"; P.gait = g * 30; o.dash = true; }
+ else if (s.k === "punch" || s.k === "kick") { [o.x, o.y] = s.p; P.face = "angry"; const h = s.hits[0], pr = hitProfile(g, h);
+ if (s.k === "punch") { P.punch = pr; P.rot = .1 * pr; } else { P.kick = pr; P.rot = -.08 * pr; } P.sq = 1 - .08 * pr; }
+ else if (s.k === "combo") { [o.x, o.y] = s.p; P.face = "angry"; s.hits.forEach((h, i) => { const pr = hitProfile(g, h, .06, .06, .12); if (i === 4) { P.punch = Math.max(P.punch || 0, pr); o.y -= 50 * pr; P.rot = -.2 * pr; } else if (i % 2) P.punchBack = Math.max(P.punchBack || 0, pr); else P.punch = Math.max(P.punch || 0, pr); }); P.rot = (P.rot || 0) + .06 * Math.sin(g * 40); }
+ // landing squash and take-off anticipation
+ for (const L of LANDS) { const d = g - L; if (d >= 0 && d < .18) P.sq = lerp(1.35, 1, eOut(d / .18)); }
+ for (const J of JUMP_STARTS) { const d = J - g; if (d > 0 && d < .09) P.sq = 1.22; }
+ return o;
+}
+// invulnerability flicker after taking a hit
+const flicker = (g) => ((g > 11.3 && g < 12.45) || (g > 20.6 && g < 21.3)) && Math.floor(g * 16) % 2 === 0;
+
+// ---------------------------------------------------------------- enemies (game time)
+const BS = .8;
+function walkX(g, t0, x0) { return x0 - 250 * Math.max(0, g - t0); }
+function enemies(g) {
+ const L = [];
+ // bug 1: walks in, punched into the sky, poof
+ if (g >= 6.2 && g < 8.3) { if (g < 7.72) L.push({ x: walkX(g, 6.2, 3330), y: G, p: { gait: g * 14 } }); else { const k = (g - 7.72) / .6; L.push({ x: 2950 + 760 * k, y: G - 560 * k + 420 * k * k, p: { rot: g * 14, hurt: true, flash: flashAlpha(g, 7.72, .15) } }); } }
+ // bug 2: kicked low and fast
+ if (g >= 6.5 && g < 8.95) { if (g < 8.42) L.push({ x: walkX(g, 6.5, 3380), y: G, p: { gait: g * 14 } }); else { const k = (g - 8.42) / .55; L.push({ x: 2900 + 980 * k, y: G - 300 * 4 * k * (1 - k), p: { rot: -g * 12, hurt: true, flash: flashAlpha(g, 8.42, .15) } }); } }
+ // bug 3: stomped flat
+ if (g >= 6.8 && g < 9.95) { if (g < 9.45) L.push({ x: Math.max(2960, walkX(g, 6.8, 3620)), y: G, p: { gait: g * 14 } }); else L.push({ x: 2960, y: G, p: { squash: 1, hurt: true, flash: flashAlpha(g, 9.45, .15) }, stars: true }); }
+ // bug 4: drops on the hero's head, bounces off, creeps back, gets a big punch
+ if (g >= 10.9 && g < 13.4) { if (g < 11.3) L.push({ x: 3080, y: lerp(-200, G - 118, eIn((g - 10.9) / .4)), p: { angry: true } });
+ else if (g < 11.6) { const k = (g - 11.3) / .3; L.push({ x: lerp(3080, 3170, k), y: lerp(G - 118, G, k) - 120 * 4 * k * (1 - k), p: { angry: true, rot: k * 2 } }); }
+ else if (g < 12.82) L.push({ x: lerp(3170, 3130, clamp((g - 11.6) / 1.1)), y: G, p: { gait: g * 12, angry: true, jaw: .5 + .5 * Math.sin(g * 20) } });
+ else { const k = (g - 12.82) / .58; L.push({ x: 3130 + 1100 * k, y: G - 600 * k + 300 * k * k, p: { rot: g * 16, hurt: true, flash: flashAlpha(g, 12.82, .2) } }); } }
+ return L;
+}
+// the boss
+const BOSS_X = 3900;
+const BOSS_HITS = [19.2, 19.45, 19.7, 19.95, 20.25], BOSS_DMG = [12, 12, 12, 12, 14];
+function bossHP(g) { let hp = 100; BOSS_HITS.forEach((h, i) => { if (g >= h) hp -= BOSS_DMG[i]; }); if (g >= 23.15) hp = lerp(hp, 0, ss(23.15, 23.8, g)); return hp; }
+function boss(g) {
+ if (g < 14.6 || g >= 24.05) return null;
+ const o = { x: BOSS_X, y: G, p: { horns: true, angry: true, shell: "#3E6B4A", t: g } };
+ if (g < 15.0) o.y = lerp(-520, G, eIn((g - 14.6) / .4));
+ o.p.squash = g >= 15.0 && g < 15.2 ? .35 * (1 - (g - 15.0) / .2) : 0;
+ if (g > 15.4 && g < 16.0) o.p.jaw = ss(15.4, 15.55, g) * (1 - ss(15.85, 16.0, g));
+ for (const f of [16.2, 16.9, 17.6]) if (g > f - .15 && g < f + .15) o.p.jaw = Math.max(o.p.jaw || 0, 1 - Math.abs(g - f) / .15);
+ BOSS_HITS.forEach((h) => { const d = g - h; if (d >= 0 && d < .25) { o.x += 24 * (1 - d / .25); o.p.flash = Math.max(o.p.flash || 0, 1 - d / .12); } });
+ if (g > 20.4 && g < 20.8) { const k = Math.sin((g - 20.4) / .4 * Math.PI); o.x -= 120 * k; o.p.jaw = k; }
+ if (g >= 23.15) { o.p.flash = Math.max(o.p.flash || 0, .5 + .5 * Math.sin(g * 60)); o.p.hurt = true; o.x += Math.sin(g * 90) * 8; }
+ if (g >= 23.6) { const k = (g - 23.6) / .45; o.p.squash = k; }
+ return o;
+}
+const SHOTS = [16.2, 16.9, 17.6], SHOT_V = 930;
+const TOKENS = [2.85, 3.15, 3.72, 4.3, 4.95, 5.6];
+const KILLS = [[8.3, 500], [8.95, 500], [9.95, 500], [13.4, 500], [23.95, 5000]];
+function score(g) { let s = 0; TOKENS.forEach((c) => { if (g > c) s += 100 * eOut((g - c) / .35); }); KILLS.forEach(([c, v]) => { if (g > c) s += v * eOut((g - c) / (v > 1000 ? 1.2 : .4)); }); return Math.round(s); }
+const hearts = (g) => g < 11.3 ? 3 : g < 20.6 ? 2 : 1;
+
+// ---------------------------------------------------------------- the level (built once)
+function buildLevel() {
+ const far = createCanvas(3000, H), f = far.getContext("2d");
+ for (const [base, col, amp] of [[560, "#C9DDB8", 70], [640, "#B2D29A", 55]]) { f.beginPath(); f.moveTo(0, H); for (let x = 0; x <= 3000; x += 30) f.lineTo(x, base - amp * Math.sin(x * .0023 + base) - 30 * Math.sin(x * .008)); f.lineTo(3000, H); f.closePath(); f.fillStyle = col; f.fill(); f.strokeStyle = "rgba(30,22,18,.3)"; f.lineWidth = 2; f.stroke(); }
+ hatch(f, () => { f.beginPath(); f.rect(0, 520, 3000, 560); }, rad(-30), 10, "#88AE72", 1, .25, [0, 500, 3000, H]);
+ const mid = createCanvas(4000, H), m = mid.getContext("2d"), r = rng(4);
+ for (let i = 0; i < 34; i++) { const x = 60 + i * 118 + r() * 50, h2 = 150 + r() * 120, y = 790; line(m, [[x, y], [x, y - h2]], 10, "#6B4A2E"); line(m, [[x, y], [x, y - h2]], 5, "#8A6240");
+ ellipse(m, x, y - h2 - 40, 62 + r() * 20, 70 + r() * 20); const tg = m.createRadialGradient(x - 20, y - h2 - 70, 5, x, y - h2 - 40, 90); tg.addColorStop(0, "#9CCB7C"); tg.addColorStop(1, "#5E9A4E"); m.fillStyle = tg; m.fill(); m.lineWidth = 3; m.strokeStyle = "rgba(30,22,18,.6)"; m.stroke(); }
+ const wc = createCanvas(WORLD, H), w = wc.getContext("2d"), r2 = rng(9);
+ const groundSpan = (x0, x1) => { const gg = w.createLinearGradient(0, G, 0, H); gg.addColorStop(0, "#A2744C"); gg.addColorStop(1, "#6A4428"); w.fillStyle = gg; w.fillRect(x0, G, x1 - x0, H - G);
+ hatch(w, () => { w.beginPath(); w.rect(x0, G, x1 - x0, H - G); }, rad(-30), 7, "#4E321C", 1, .3, [x0, G, x1, H]);
+ for (let bx = x0; bx < x1; bx += 100) { w.strokeStyle = "rgba(60,35,18,.5)"; w.lineWidth = 2; w.strokeRect(bx, G + 26, 100, 90); w.strokeRect(bx + 50, G + 116, 100, 90); }
+ w.fillStyle = "#6FB25A"; w.fillRect(x0, G - 4, x1 - x0, 26); line(w, [[x0, G + 22], [x1, G + 22]], 3); line(w, [[x0, G - 4], [x1, G - 4]], 3);
+ for (let x = x0 + 10; x < x1; x += 22) { ctxBlade(w, x, G - 2); } line(w, [[x0, G - 4], [x0, H]], 3); line(w, [[x1, G - 4], [x1, H]], 3); };
+ const ctxBlade = (c, x, y) => { c.beginPath(); c.moveTo(x - 6, y); c.quadraticCurveTo(x, y - 14 - hash(x) * 10, x + 4, y - 18 - hash(x) * 10); c.quadraticCurveTo(x + 2, y - 6, x + 8, y); c.fillStyle = "#5E9A4E"; c.fill(); };
+ groundSpan(-10, 1500); groundSpan(1760, WORLD + 10);
+ // floating brick platforms
+ for (const [x0, x1, y] of [[1300, 1620, 700], [1800, 2120, 560]]) { const P = rrect(x0, y, x1 - x0, 64, 8); poly(w, P); const pg = w.createLinearGradient(0, y, 0, y + 64); pg.addColorStop(0, "#D8925E"); pg.addColorStop(1, "#A8633A"); w.fillStyle = pg; w.fill();
+ for (let bx = x0; bx < x1; bx += 53) { w.strokeStyle = "rgba(60,25,10,.55)"; w.lineWidth = 2; w.strokeRect(bx, y, 53, 32); w.strokeRect(bx + 26, y + 32, 53, 32); }
+ hatch(w, () => poly(w, P), rad(-40), 6, "#6A3418", 1, .3, [x0, y, x1, y + 64]); w.fillStyle = "#6FB25A"; w.fillRect(x0, y - 6, x1 - x0, 14); poly(w, P); stroke(w, 3.4); line(w, [[x0, y - 6], [x1, y - 6]], 3); }
+ // props: sign, flowers, mushrooms, rocks; the arena gets cracked stones
+ w.save(); line(w, [[240, G - 4], [240, G - 150]], 10, "#6B4A2E"); poly(w, rrect(150, G - 250, 190, 110, 12)); fill(w, "#E9D2A6"); stroke(w, 3.4); w.font = "40px MBlack"; w.fillStyle = INK; w.textAlign = "center"; w.fillText("1-1", 245, G - 180); w.font = "26px ISemi"; w.fillText("→ bugs ahead", 245, G - 150); w.restore();
+ for (let i = 0; i < 18; i++) { const x = 120 + i * 270 + r2() * 90; if (x > 1450 && x < 1800) continue; if (x > 2750) break; line(w, [[x, G - 2], [x + 4, G - 70]], 4, "#4E8A3A"); at(w, x + 4, G - 72, .32, 0, () => blossom(w, 1, r2() > .5 ? GOLD : "#F4F0E6")); }
+ for (const x of [700, 2300]) { poly(w, rrect(x - 12, G - 40, 24, 40, 6)); fill(w, "#F2EAD8"); stroke(w, 2.6); ellipse(w, x, G - 44, 40, 24); fill(w, "#E5484D"); stroke(w, 3); for (const dx of [-16, 4, 18]) { ellipse(w, x + dx, G - 50, 5, 4); fill(w, "#fff"); } }
+ for (let i = 0; i < 9; i++) { const x = 3300 + i * 180 + r2() * 60; ellipse(w, x, G + 2, 30 + r2() * 20, 18); fill(w, "#8C8478"); stroke(w, 2.6); line(w, [[x - 10, G - 8], [x + 4, G + 2]], 2, "rgba(30,22,18,.6)"); }
+ return { far, mid, world: wc };
+}
+function cloud(ctx, x, y, s, dark = 0) { const P = []; for (let i = 0; i < 22; i++) { const a = i / 22 * Math.PI * 2, rr = 1 + .22 * Math.sin(a * 5) + .1 * Math.sin(a * 11); P.push([x + Math.cos(a) * 120 * s * rr, y + Math.sin(a) * 50 * s * rr * (Math.sin(a) > 0 ? .6 : 1)]); }
+ smooth(ctx, P); ctx.fillStyle = dark ? `rgba(${lerp(250, 110, dark)},${lerp(248, 100, dark)},${lerp(240, 110, dark)},.95)` : "rgba(250,248,240,.95)"; ctx.fill(); smooth(ctx, P); stroke(ctx, 3, "rgba(30,22,18,.45)"); }
+
+// ---------------------------------------------------------------- HUD + titles (screen space)
+function outlined(ctx, str, x, y, size, col = "#FFFFFF", font = "MBlack", align = "left") { ctx.save(); ctx.font = `${size}px "${font}"`; ctx.textAlign = align; ctx.lineJoin = "round"; ctx.lineWidth = size * .2; ctx.strokeStyle = INK; ctx.strokeText(str, x, y); ctx.fillStyle = col; ctx.fillText(str, x, y); ctx.restore(); }
+function hud(ctx, g, t) {
+ const a = ss(1.9, 2.4, g) * (1 - ss(END_T - .3, END_T, t)); if (a <= 0) return; ctx.save(); ctx.globalAlpha *= a;
+ const hn = hearts(g); for (let i = 0; i < 3; i++) { const lost = i >= hn, pop = lost ? 1 + .6 * (1 - ss(0, .3, g - (i === 2 ? 11.3 : 20.6))) : 1; at(ctx, 80 + i * 70, 78, pop, 0, () => heart(ctx, 0, 0, 1.6, !lost)); }
+ outlined(ctx, "SCORE", 330, 72, 30, "#FFFFFF"); outlined(ctx, String(score(g)).padStart(6, "0"), 330, 118, 50, GOLD, "Mono");
+ outlined(ctx, "WORLD 1-1", 1840, 90, 40, "#FFFFFF", "MBlack", "right");
+ // boss bar
+ const bb = ss(15.2, 15.6, g) * (1 - ss(24.05, 24.4, g));
+ if (bb > 0) { ctx.save(); ctx.globalAlpha *= bb; const x0 = 560, w = 800, y = 150, hp = bossHP(g), lag = bossHP(Math.max(15, g - .35));
+ outlined(ctx, "BOSS · THE LEGACY BUG", 960, y - 16, 34, "#FFFFFF", "MBlack", "center");
+ poly(ctx, rrect(x0 - 6, y - 6, w + 12, 44, 12)); fill(ctx, INK); ctx.fillStyle = "#FFF3C4"; ctx.fillRect(x0, y, w * lag / 100, 32); const hg = ctx.createLinearGradient(0, y, 0, y + 32); hg.addColorStop(0, "#FF7A6A"); hg.addColorStop(1, "#C02A30"); ctx.fillStyle = hg; ctx.fillRect(x0, y, w * hp / 100, 32);
+ ctx.fillStyle = "rgba(255,255,255,.35)"; ctx.fillRect(x0, y + 4, w * hp / 100, 6); ctx.restore(); }
+ ctx.restore();
+}
+function title(ctx, g) {
+ if (g > 2.6) return; const out = eIn(clamp((g - 2.2) / .35));
+ const word = "CLAUDE"; ctx.save(); ctx.translate(0, -out * 700);
+ [...word].forEach((ch, i) => { const t0 = .15 + i * .07, k = g < t0 ? 0 : eBack(clamp((g - t0) / .3), 2.4); if (k <= 0) return; const x = 960 + (i - 2.5) * 150, y = 330 + (1 - Math.min(1, k)) * -300;
+ at(ctx, x, y, 1, Math.sin(i * 2) * .06, () => outlined(ctx, ch, 0, 0, 190, ORANGE, "MBlack", "center")); });
+ const k2 = popS(g, .75, .35, 2); if (k2 > 0) at(ctx, 960, 450, k2, -.04, () => outlined(ctx, "vs THE BUGS", 0, 0, 84, "#FFFFFF", "MBlack", "center"));
+ ctx.restore();
+}
+function warning(ctx, g) {
+ if (g < 13.4 || g > 15.1) return; const a = ss(13.4, 13.6, g) * (1 - ss(14.9, 15.1, g)), blink = .6 + .4 * Math.sin(g * 18);
+ ctx.save(); ctx.globalAlpha *= a; ctx.fillStyle = `rgba(229,72,77,${.18 * blink})`; ctx.fillRect(0, 0, W, H);
+ for (const y of [300, 700]) { ctx.fillStyle = "rgba(20,10,10,.85)"; ctx.fillRect(0, y, W, 90); ctx.save(); ctx.beginPath(); ctx.rect(0, y, W, 90); ctx.clip(); for (let x = -200 + ((g * 300) % 120); x < W + 200; x += 120) { ctx.fillStyle = GOLD; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + 60, y); ctx.lineTo(x + 20, y + 90); ctx.lineTo(x - 40, y + 90); ctx.closePath(); ctx.fill(); } ctx.restore(); }
+ ctx.globalAlpha *= blink; outlined(ctx, "WARNING", 960, 580, 170, "#FF5A50", "MBlack", "center"); outlined(ctx, "a big bug approaches", 960, 650, 44, "#FFFFFF", "IBold", "center"); ctx.restore();
+}
+function levelClear(ctx, g, t) {
+ if (g < 24.35 || t > END_T) return; const word = "LEVEL CLEAR!";
+ [...word].forEach((ch, i) => { const t0 = 24.35 + i * .045, k = g < t0 ? 0 : eBack(clamp((g - t0) / .3), 2.6); if (k <= 0) return; const x = 960 + (i - 5.5) * 104, y = 360 + Math.sin(g * 6 + i * .7) * 8;
+ at(ctx, x, y, k, 0, () => outlined(ctx, ch, 0, 0, 150, i < 5 ? GOLD : "#FFFFFF", "MBlack", "center")); });
+ [24.95, 25.15, 25.35].forEach((t0, i) => { const k = popS(g, t0, .35, 2.5); if (k > 0) starburst(ctx, 820 + i * 140, 470 - (i === 1 ? 30 : 0), 52 * k, { rays: 5, color: GOLD, inner: .45, rot: -Math.PI / 2, glow: .6 }); });
+}
+function endCard(ctx, t) {
+ const a = ss(END_T, END_T + .4, t); if (a <= 0) return;
+ ctx.save(); ctx.globalAlpha = .9 * a; ctx.fillStyle = "#F3EEDD"; ctx.fillRect(0, 0, W, H); ctx.restore();
+ lightBands(ctx, W, H, t, { alpha: .45 * a });
+ const k1 = popS(t, END_T + .2, .35, 2); if (k1 > 0) at(ctx, 960, 300, k1, 0, () => outlined(ctx, "Every frame is code.", 0, 0, 104, "#FFFFFF", "MBlack", "center"));
+ const k2 = popS(t, END_T + .55, .35, 2); if (k2 > 0) at(ctx, 960, 430, k2, 0, () => outlined(ctx, "claude-animation", 0, 0, 80, ORANGE, "MBlack", "center"));
+ const k3 = clamp((t - END_T - .9) / .25); if (k3 > 0) { ctx.save(); ctx.globalAlpha *= k3; ctx.font = "34px Mono"; const s = "github.com/buildwithhanif/claude-animation-skill", w = ctx.measureText(s).width + 60; poly(ctx, rrect(960 - w / 2, 505, w, 66, 20)); fill(ctx, INK); ctx.fillStyle = "#F3EEDD"; ctx.textAlign = "center"; ctx.fillText(s, 960, 549); ctx.restore(); }
+ const hop = Math.abs(Math.sin((t - END_T) * 7)) * 60; critter(ctx, 960, 900 - hop, 1.1, { t, face: "happy", arms: "up", sq: hop < 6 ? 1.2 : .9, air: hop > 6 });
+ ctx.save(); ctx.font = "30px ISemi"; ctx.fillStyle = "rgba(30,22,18,.55)"; ctx.textAlign = "right"; ctx.fillText("@hanifproduktif", 1880, 1050); ctx.restore();
+}
+
+// ---------------------------------------------------------------- the frame
+function frame(ctx, t, S) {
+ const g = TW.game(t), h = hero(g);
+ // camera: follow the hero, then settle on the arena
+ const Z = 1.32, VW = W / Z, follow = clamp(h.x - VW * .4, 0, WORLD - VW), camX = lerp(follow, 2720, ss(12.9, 14.4, g));
+ const [sx, sy] = shake(t, SHAKES);
+ const danger = ss(13.4, 15, g) * (1 - ss(23.9, 24.6, g)), glow = ss(23.9, 24.8, g);
+ // sky
+ const sk = ctx.createLinearGradient(0, 0, 0, G); sk.addColorStop(0, danger > 0 ? `rgb(${lerp(190, 120, danger)},${lerp(222, 70, danger)},${lerp(236, 90, danger)})` : glow > 0 ? "#F4D49A" : "#BEDDEB"); sk.addColorStop(1, danger > 0 ? `rgb(${lerp(246, 200, danger)},${lerp(238, 130, danger)},${lerp(220, 120, danger)})` : "#F6EEDC");
+ ctx.fillStyle = sk; ctx.fillRect(0, 0, W, H);
+ sun(ctx, 1540 - camX * .03, 200, 86, { rayColor: danger > .5 ? "#C0392B" : "#D9A035" });
+ lightBands(ctx, W, H, t, { alpha: .35 * (1 - danger) + .25 * glow });
+ for (let i = 0; i < 6; i++) { const x = ((i * 520 - camX * .15 + t * 18) % 3120 + 3120) % 3120 - 400; cloud(ctx, x, 150 + (i % 3) * 70, .8 + (i % 2) * .3, danger); }
+ ctx.save(); ctx.translate(sx, sy);
+ ctx.drawImage(S.L.far, -camX * .25, 0); ctx.drawImage(S.L.mid, -camX * .5, 0);
+ ctx.save(); ctx.translate(0, G); ctx.scale(Z, Z); ctx.translate(-camX, -G); ctx.drawImage(S.L.world, 0, 0);
+ // tokens
+ TOKENS.forEach((c, i) => { const hp = hero(c), x = hp.x + 20, y = hp.y - 80;
+ if (g < c) { const sc = Math.abs(Math.cos(g * 3 + i)) * .8 + .2; at(ctx, x, y + Math.sin(g * 4 + i) * 6, 1, 0, () => { ctx.save(); ctx.scale(sc, 1); starburst(ctx, 0, 0, 28, { rays: 10, glow: .5, rot: i }); ctx.restore(); }); }
+ else { burstParticles(ctx, t, R(c), x, y, { n: 10, speed: 300, life: .4, kind: "spark", seed: i + 1 }); floatText(ctx, t, R(c), x, y - 20, "+100", { size: 38, color: GOLD, font: "MBlack" }); } });
+ // enemies
+ for (const e of enemies(g)) { bug(ctx, e.x, e.y, BS, { t: g, ...e.p, flash: Math.min(.6, e.p.flash || 0) }); if (e.stars) for (let i = 0; i < 3; i++) { const a = g * 6 + i * 2.1; starburst(ctx, e.x + Math.cos(a) * 60, e.y - 60 + Math.sin(a) * 16, 12, { rays: 5, color: GOLD, inner: .45 }); } }
+ const bo = boss(g); if (bo) bug(ctx, bo.x, bo.y, 2, { ...bo.p, flash: Math.min(.55, bo.p.flash || 0) });
+ // boss shots: red error blobs rolling along the ground
+ SHOTS.forEach((f, i) => { const d = g - f; if (d < 0 || d > 1.3) return; const x = BOSS_X - 250 - SHOT_V * d, y = G - 34; if (x < 2600) return;
+ for (let k = 1; k <= 4; k++) { ctx.save(); ctx.globalAlpha *= .25 / k; ellipse(ctx, x + k * 28, y, 30 - k * 3, 30 - k * 3); fill(ctx, RED); ctx.restore(); }
+ at(ctx, x, y, 1, -d * 10, () => { ellipse(ctx, 0, 0, 34, 34); const rg = ctx.createRadialGradient(-10, -10, 4, 0, 0, 36); rg.addColorStop(0, "#FF9A8A"); rg.addColorStop(1, "#B82028"); ctx.fillStyle = rg; ctx.fill(); stroke(ctx, 3); });
+ outlined(ctx, "ERR", x, y + 10, 26, "#FFFFFF", "MBlack", "center"); });
+ // the hero (afterimages while dashing, flicker while invulnerable)
+ const drawHero = (c, gg, a = 1) => { const hh = hero(gg); if (hh.hide) return; critter(c, hh.x, hh.y, 1, hh.pose); };
+ if (h.dash) { afterimages(ctx, g, (c, gg) => drawHero(c, gg), { n: 4, gap: .03, alpha: .45 }); speedLines(ctx, h.x - 40, h.y - 60, 0, 3, 90, 22, 3); }
+ if (!h.hide) { ctx.save(); if (flicker(g)) ctx.globalAlpha *= .3; critter(ctx, h.x, h.y, 1, h.pose); ctx.restore(); }
+ // charge: starburst forming above, embers
+ if (g > 21.2 && g < 22.8) { const k = ss(21.3, 22.5, g); starburst(ctx, h.x, h.y - 220, 20 + 60 * k, { rays: 10, rot: g * 6, glow: k }); burstParticles(ctx, t, R(21.25), h.x, h.y - 20, { n: 26, speed: 40, life: 1.4, gravity: 300, kind: "ember", colors: ["rgba(255,200,110,.9)", "rgba(255,160,80,.9)"], size: 10, spread: 2, seed: 7 });
+ burstParticles(ctx, t, R(21.9), h.x, h.y - 20, { n: 26, speed: 40, life: 1.2, gravity: 300, kind: "ember", colors: ["rgba(255,220,140,.9)"], size: 9, spread: 2, seed: 8 }); }
+ // special: the starburst flies
+ if (g >= 22.8 && g < 23.15) { const k = (g - 22.8) / .35, x = lerp(3290, BOSS_X - 90, eIn(k)), y = lerp(560, G - 130, k); afterimages(ctx, g, (c, gg) => { const kk = clamp((gg - 22.8) / .35); starburst(c, lerp(3290, BOSS_X - 90, eIn(kk)), lerp(560, G - 130, kk), 80, { rays: 10, rot: gg * 14, outline: false }); }, { n: 5, gap: .025, alpha: .5 });
+ starburst(ctx, x, y, 80, { rays: 10, rot: g * 14, glow: 1 }); }
+ // contact effects (real time)
+ const FX = [[7.72, "POW!", 2860], [8.42, "WHAM!", 2830], [9.45, "STOMP!", 2960], [12.82, "BAM!!", 3060]];
+ FX.forEach(([gc, word, x], i) => { const tc = R(gc), y = G - 90; burstParticles(ctx, t, tc, x, y, { n: 18, speed: 700, life: .45, seed: 11 + i }); ring(ctx, t, tc, x, y, 150); comicText(ctx, t, tc, x + 20, y - 170, word, { size: 88, font: "MBlack" }); });
+ [8.3, 8.95, 9.95, 13.4].forEach((gc, i) => { const e = [[3406, 390], [3370, 880], [2960, 880], [3770, 580]][i], tc = R(gc);
+ burstParticles(ctx, t, tc, e[0], e[1] - 50, { n: 16, speed: 420, life: .5, kind: "dust", colors: ["rgba(200,180,220,.9)", "rgba(255,255,255,.9)"], size: 16, gravity: 200, seed: 21 + i });
+ floatText(ctx, t, tc, e[0], e[1] - 110, "+500", { size: 46, color: GOLD, font: "MBlack" }); });
+ LANDS.forEach((L) => { const hh = hero(L + .001); landDust(ctx, t, R(L), hh.x, hh.y, 1); });
+ BOSS_HITS.forEach((gc, i) => { const tc = R(gc), x = BOSS_X - 230, y = G - 120 - (i === 4 ? 60 : 0); burstParticles(ctx, t, tc, x, y, { n: 14, speed: 650, life: .4, seed: 31 + i }); ring(ctx, t, tc, x, y, 120, { w: 8 });
+ floatText(ctx, t, tc, x + 40 + i * 12, y - 90, `-${BOSS_DMG[i]}`, { size: 52, color: "#FF6A5A", font: "MBlack" });
+ if (i === 4) comicText(ctx, t, tc, x, y - 230, "UPPERCUT!", { size: 74, font: "MBlack" }); });
+ if (g >= 19.2 && g < 20.9) { const n = BOSS_HITS.filter((hh) => g >= hh).length; if (n) at(ctx, 3380, 600, 1 + .25 * (1 - ss(0, .15, g - BOSS_HITS[n - 1])), -.08, () => { outlined(ctx, `x${n}`, 0, 0, 110, GOLD, "MBlack", "center"); outlined(ctx, "COMBO", 0, 50, 40, "#FFFFFF", "MBlack", "center"); }); }
+ { const tc = R(15.0); ring(ctx, t, tc, BOSS_X, G, 420, { w: 16, squash: .25, dur: .5 }); burstParticles(ctx, t, tc, BOSS_X, G - 10, { n: 30, speed: 600, life: .7, kind: "debris", colors: ["#8C6A48", "#A2744C", "#6A4428"], size: 12, dir: -Math.PI / 2, spread: 2.2, seed: 41 }); }
+ [15.45, 15.65, 15.85].forEach((gc) => ring(ctx, t, R(gc), BOSS_X - 200, G - 60, 380, { w: 12, color: "rgba(255,120,110,.8)", dur: .5 }));
+ { const tc = R(23.15); ring(ctx, t, tc, BOSS_X - 90, G - 130, 600, { w: 24, dur: .6 }); ring(ctx, t, tc + .08, BOSS_X - 90, G - 130, 400, { w: 14, dur: .5, color: ORANGE }); burstParticles(ctx, t, tc, BOSS_X - 90, G - 130, { n: 40, speed: 1100, life: .6, seed: 51 });
+ comicText(ctx, t, tc + .05, BOSS_X - 120, G - 430, "CRITICAL!", { size: 110, font: "MBlack", dur: 1.0, star: "#FF8A5A" }); }
+ { const tc = R(23.95); burstParticles(ctx, t, tc, BOSS_X, G - 120, { n: 36, speed: 900, life: .8, kind: "debris", colors: ["#3E6B4A", "#5E8F6A", "#2A4A33"], size: 16, seed: 61 }); burstParticles(ctx, t, tc, BOSS_X, G - 160, { n: 60, speed: 800, life: 1.8, kind: "confetti", colors: [GOLD, ORANGE, "#FFFFFF", "#6FB25A"], size: 14, gravity: 700, seed: 62 });
+ ring(ctx, t, tc, BOSS_X, G - 120, 700, { w: 20, dur: .6 }); floatText(ctx, t, tc + .3, BOSS_X, G - 250, "+5000", { size: 70, color: GOLD, font: "MBlack", dur: .9 }); }
+ ctx.restore(); // world
+ ctx.restore(); // shake
+ // darken for the charge, flash for the special and the K.O.
+ const dim = ss(21.3, 21.8, g) * (1 - ss(22.9, 23.2, g)); if (dim > 0) { ctx.save(); ctx.globalCompositeOperation = "multiply"; ctx.fillStyle = `rgba(80,60,90,${.45 * dim})`; ctx.fillRect(0, 0, W, H); ctx.restore(); }
+ const fl = Math.max(flashAlpha(t, R(23.15), .3), .7 * flashAlpha(t, R(23.95), .25), .5 * flashAlpha(t, R(15.0), .15)); if (fl > 0) { ctx.save(); ctx.globalAlpha = fl; ctx.fillStyle = "#FFFBEE"; ctx.fillRect(0, 0, W, H); ctx.restore(); }
+ comicText(ctx, t, R(23.95), 960, 560, "K.O.", { size: 260, font: "MBlack", dur: 1.1, star: "#FF8A5A", rot: -.06 });
+ title(ctx, g); warning(ctx, g); hud(ctx, g, t); levelClear(ctx, g, t);
+ S.finish(ctx, Math.round(t * FPS));
+ endCard(ctx, t);
+}
+const SHAKES = [[R(1.0), 6], [R(7.72), 12], [R(8.42), 12], [R(9.45), 14], [R(11.3), 16], [R(12.82), 20], [R(15.0), 34], [R(15.45), 12], [R(15.65), 12], [R(15.85), 12],
+ ...BOSS_HITS.map((h, i) => [R(h), i === 4 ? 18 : 10]), [R(20.6), 18], [R(23.15), 44], [R(23.95), 30]];
+
+// ---------------------------------------------------------------- sound cues + music sections (real time)
+function cues() {
+ const Q = [], add = (sfx, t, vol = .45, o = {}) => Q.push({ sfx, t: +(t - .03).toFixed(3), vol, ...o });
+ [.15, .22, .29, .36, .43, .5].forEach((t, i) => add("pop", t, .4, { pitch: .8 + i * .08 })); add("thump", .78, .45); add("whoosh", .3, .35, { dur: .6 });
+ add("fall", .35, .3); add("thump", R(1.0), .55); add("boing", R(1.0) + .02, .25);
+ SEG.filter((s) => s.k === "jump").forEach((s) => add("boing", R(s.a), .35, { pitch: 1.3 + (s.h > 200 ? .15 : 0) }));
+ LANDS.forEach((L) => add("step", R(L), .5, { pitch: .6 }));
+ SEG.filter((s) => s.k === "run").forEach((s) => { for (let g = s.a; g < s.b; g += .09) add("step", R(g), .18); });
+ TOKENS.forEach((c, i) => { add("chime", R(c), .3, { dur: .4, pitch: 1.4 + i * .05 }); add("tick", R(c), .3, { pitch: 1.5 }); });
+ add("pop", R(6.9), .4, { pitch: 1.3 });
+ for (const [a] of [[7.35], [18.75]]) add("whip", R(a), .5, { dur: .35 });
+ for (const gc of [7.72, 8.42, 12.82]) { add("thump", R(gc), .7); add("crack", R(gc), .55); }
+ add("thump", R(9.45), .6); add("pop", R(9.45), .5, { pitch: .7 });
+ [8.3, 8.95, 9.95, 13.4].forEach((gc) => { add("pop", R(gc), .45, { pitch: 1.2 }); add("sparkle", R(gc) + .05, .25); });
+ add("fall", R(10.9), .35); add("thump", R(11.3), .5); add("fall", R(11.32), .45, { pitch: .8 });
+ add("riser", R(13.4), .35, { dur: 1.5 });
+ add("thump", R(15.0), .9, { pitch: .6 }); add("crack", R(15.0), .6, { pitch: .7 });
+ [15.45, 15.65, 15.85].forEach((gc) => add("buzz", R(gc), .45, { dur: .25, pitch: .6 }));
+ SHOTS.forEach((f) => add("whip", R(f), .45, { pitch: .8 }));
+ BOSS_HITS.forEach((h, i) => { add("thump", R(h), .6, { pitch: 1 + i * .06 }); add("crack", R(h), .45, { pitch: 1 + i * .08 }); });
+ add("whoosh", R(20.45), .5); add("thump", R(20.6), .6); add("fall", R(20.62), .4, { pitch: .8 });
+ add("riser", R(21.3), .55, { dur: 1.4 }); add("sparkle", R(22.4), .4);
+ add("whip", R(22.8), .6, { dur: .4, pitch: .7 }); add("thump", R(23.15), 1.0, { pitch: .5 }); add("crack", R(23.15), .8, { pitch: .6 });
+ add("riser", R(23.3), .35, { dur: .6 }); add("thump", R(23.95), .8, { pitch: .55 }); add("crack", R(23.95), .6); add("sparkle", R(24.0), .5); add("chime", R(24.0), .45);
+ [24.3, 24.9].forEach((g) => add("boing", R(g), .35, { pitch: 1.4 }));
+ [24.95, 25.15, 25.35].forEach((g, i) => add("chime", R(g), .35, { dur: .4, pitch: 1.2 + i * .15 }));
+ add("whoosh", END_T, .35); add("pop", END_T + .2, .45); add("pop", END_T + .55, .4, { pitch: 1.2 });
+ return Q;
+}
+if (process.argv[2] === "cues") {
+ fs.writeFileSync(path.join(HERE, "cues.json"), JSON.stringify(cues()));
+ const sec = `level:0-${R(13.4).toFixed(2)},alarm:${R(13.4).toFixed(2)}-${R(15.0).toFixed(2)},boss:${R(15.0).toFixed(2)}-${R(24.0).toFixed(2)},fanfare:${R(24.0).toFixed(2)}-${(R(24.0) + 2.6).toFixed(2)},outro:${(R(24.0) + 2.6).toFixed(2)}-30`;
+ fs.writeFileSync(path.join(HERE, "sections.txt"), sec); console.log("wrote cues.json", cues().length, "cues; sections", sec); process.exit(0);
+}
+
+run({ name: "claude-game", W, H, fps: FPS, dur: DUR, out: path.join(HERE, "out"),
+ setup() { return { L: buildLevel(), finish: filmFinish(W, H, { grain: .08, flicker: .01, vignette: .16 }) }; },
+ frame: (ctx, t, i, S) => frame(ctx, t, S) });
diff --git a/examples/claude-game/make.sh b/examples/claude-game/make.sh
new file mode 100755
index 0000000..3f1b914
--- /dev/null
+++ b/examples/claude-game/make.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# make.sh — render the game short, then chiptune + synthesised SFX -> out/claude-game-final.mp4
+set -e
+cd "$(dirname "$0")"
+SK=../../plugins/claude-animation/skills/claude-animation
+node film.mjs verify
+node film.mjs render
+node film.mjs cues # writes cues.json and sections.txt (music sections in real time, after hit-stop)
+node $SK/scripts/chiptune.mjs out/music.wav --dur 30 --bpm 150 --sections "$(cat sections.txt)"
+node $SK/scripts/sound.mjs cues.json out/claude-game.mp4 out/claude-game-final.mp4 --bed out/music.wav --bed-vol .42 --lufs -14
diff --git a/plugins/claude-animation/skills/claude-animation/SKILL.md b/plugins/claude-animation/skills/claude-animation/SKILL.md
index 85e1f95..2bea25c 100644
--- a/plugins/claude-animation/skills/claude-animation/SKILL.md
+++ b/plugins/claude-animation/skills/claude-animation/SKILL.md
@@ -20,6 +20,7 @@ recap and a set of storybook insect films — and took a render to find.
| **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` |
+| **Action / video-game feel**: jumps, punches, hit-stop, shake, sparks, combo, boss bar | `lib/fx.mjs`, `lib/rigs/critter.mjs`, `lib/rigs/bug.mjs`, `examples/claude-game/` |
| 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` |
@@ -37,6 +38,9 @@ recap and a set of storybook insect films — and took a render to find.
| `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) |
+| `fx.mjs` | `timeWarp` (hit-stop: game time freezes on contact, effects keep running), `shake`, `burstParticles` (spark / debris / dust / confetti / ember), `landDust`, `ring`, `flashAlpha`, `comicText`, `floatText`, `afterimages`, `starburst`, `heart` |
+| `rigs/critter.mjs` | a blocky action hero: run, jump, flip, squash & stretch, punch, kick, hurt, charge aura, expressions |
+| `rigs/bug.mjs` | a beetle enemy (and boss with horns): scuttle, jaw, flash, squash, spin |
| `rigs/bean.mjs` | `person bust bubble flagCloth hat SKIN` |
| `film.mjs` | `run({...})` → `render / sheet / strip / verify`; `exposure(t, track, fps)` for ones / twos / holds |
@@ -82,6 +86,7 @@ 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,
+Worked films in the repo: `examples/claude-game/` — a 30 s video-game short (platforming, bugs, a boss fight
+with hit-stop, combo, special, K.O., chiptune from `scripts/chiptune.mjs`); and `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/fx.mjs b/plugins/claude-animation/skills/claude-animation/lib/fx.mjs
new file mode 100644
index 0000000..029a51b
--- /dev/null
+++ b/plugins/claude-animation/skills/claude-animation/lib/fx.mjs
@@ -0,0 +1,97 @@
+// fx.mjs — game-feel effects, all pure functions of time (seeded, no state between frames).
+// hit-stop: const tw = timeWarp(STOPS); g = tw.game(t) (freezes on contacts); tw.real(g) for sound cues
+// screen shake: const [dx, dy] = shake(t, [[t0, amp], ...])
+// particles: sparks / debris / dust / confetti / rising embers bursting at t0
+// impact: ring(), flashAlpha(), comicText(), floatText(), afterimages via a draw callback
+// shapes: starburst() (rounded-ray spark), heart(), speed lines are in core.mjs
+import { clamp, lerp, eOut, eIn, eBack, rng, hash, ellipse, stroke, fill, line, at, poly, INK } from "./core.mjs";
+
+// ---------------------------------------------------------------- hit-stop: game time freezes briefly on contact
+// stops: [[gameTime, duration], ...] in GAME time. game(t) maps real -> game; real(g) maps game -> real.
+export function timeWarp(stops) {
+ const S = [...stops].sort((a, b) => a[0] - b[0]);
+ return {
+ game(t) { let acc = 0; for (const [s, d] of S) { if (t < s + acc) break; if (t < s + acc + d) return s; acc += d; } return t - acc; },
+ real(g) { let acc = 0; for (const [s, d] of S) { if (s >= g) break; acc += d; } return g + acc; },
+ frozen(t) { let acc = 0; for (const [s, d] of S) { if (t < s + acc) break; if (t < s + acc + d) return true; acc += d; } return false; },
+ };
+}
+// ---------------------------------------------------------------- screen shake: decaying, deterministic
+export function shake(t, events, dur = .45) {
+ let x = 0, y = 0;
+ for (const [t0, amp] of events) { const d = t - t0; if (d < 0 || d > dur) continue; const k = Math.exp(-d * 9) * amp;
+ x += Math.sin(d * 97 + t0) * k; y += Math.cos(d * 83 + t0 * 3) * k * .8; }
+ return [x, y];
+}
+// ---------------------------------------------------------------- particles
+// kind: "spark" (streaks), "debris" (tumbling chunks), "dust" (puffs), "confetti", "ember" (rising glow)
+export function burstParticles(ctx, t, t0, x, y, o = {}) {
+ const d = t - t0, { n = 14, speed = 520, life = .6, gravity = 900, colors = ["#FFD35A", "#FFF3C4", "#F28C28"], size = 8, kind = "spark", seed = 1, spread = Math.PI * 2, dir = -Math.PI / 2 } = o;
+ if (d < 0 || d > life * 1.6) return;
+ const r = rng(seed * 977 + Math.floor(t0 * 1000));
+ for (let i = 0; i < n; i++) {
+ const a = dir + (r() - .5) * spread, sp = speed * (.45 + r() * .75), L = life * (.6 + r() * .6), dd = Math.min(d, L), fade = 1 - clamp(d / L);
+ if (fade <= 0) { r(); r(); continue; }
+ const px = x + Math.cos(a) * sp * dd, py = y + Math.sin(a) * sp * dd + (kind === "ember" ? -gravity * .3 * dd * dd : .5 * gravity * dd * dd), col = colors[i % colors.length], sz = size * (.6 + r() * .8);
+ ctx.save(); ctx.globalAlpha *= fade;
+ if (kind === "spark") { const vx = Math.cos(a) * sp, vy = Math.sin(a) * sp + gravity * dd, vl = Math.hypot(vx, vy) || 1; line(ctx, [[px, py], [px - vx / vl * sz * 3, py - vy / vl * sz * 3]], sz * .55, col); }
+ else if (kind === "debris") { at(ctx, px, py, 1, d * (6 + i), () => { poly(ctx, [[-sz, -sz * .6], [sz * .8, -sz], [sz, sz * .7], [-sz * .7, sz]]); fill(ctx, col); stroke(ctx, 1.8); }); }
+ else if (kind === "dust") { const s2 = sz * (1 + d * 3); ellipse(ctx, px, py, s2, s2 * .7); fill(ctx, col); }
+ else if (kind === "confetti") { at(ctx, px, py, 1, d * 8 + i, () => { ctx.scale(Math.cos(d * 10 + i), 1); ctx.fillStyle = col; ctx.fillRect(-sz / 2, -sz * .7, sz, sz * 1.4); ctx.strokeStyle = INK; ctx.lineWidth = 1.4; ctx.strokeRect(-sz / 2, -sz * .7, sz, sz * 1.4); }); }
+ else if (kind === "ember") { const g = ctx.createRadialGradient(px, py, 0, px, py, sz * 2); g.addColorStop(0, col); g.addColorStop(1, "rgba(255,200,80,0)"); ctx.fillStyle = g; ctx.fillRect(px - sz * 2, py - sz * 2, sz * 4, sz * 4); }
+ ctx.restore();
+ }
+}
+// dust puff at the feet on landing (two clouds sliding out sideways)
+export function landDust(ctx, t, t0, x, y, s = 1, color = "rgba(214,190,150,.85)") {
+ const d = t - t0; if (d < 0 || d > .5) return; const k = eOut(d / .5), a = 1 - d / .5;
+ ctx.save(); ctx.globalAlpha *= a; for (const sg of [-1, 1]) for (let i = 0; i < 3; i++) { const px = x + sg * (30 + k * (70 + i * 30)) * s, py = y - (6 + i * 7) * s - k * 10 * s, r = (16 + i * 5) * s * (1 - .3 * k);
+ ellipse(ctx, px, py, r, r * .75); fill(ctx, color); ellipse(ctx, px, py, r, r * .75); stroke(ctx, 1.6, "rgba(90,70,50,.5)"); } ctx.restore();
+}
+// expanding shock ring
+export function ring(ctx, t, t0, x, y, r1 = 160, { dur = .35, w = 10, color = "#FFF3C4", squash = 1 } = {}) {
+ const d = t - t0; if (d < 0 || d > dur) return; const k = eOut(d / dur);
+ ctx.save(); ctx.globalAlpha *= 1 - d / dur; ctx.beginPath(); ctx.ellipse(x, y, Math.max(1, r1 * k), Math.max(1, r1 * k * squash), 0, 0, Math.PI * 2); ctx.lineWidth = w * (1 - k * .7); ctx.strokeStyle = color; ctx.stroke(); ctx.restore();
+}
+// full-frame (or local) white flash intensity after a hit
+export const flashAlpha = (t, t0, dur = .12) => (t < t0 || t > t0 + dur) ? 0 : 1 - (t - t0) / dur;
+// radial impact spikes (comic "pow" star) behind a word
+export function impactStar(ctx, x, y, r, n = 12, color = "#FFD35A", rot = 0) {
+ const P = []; for (let i = 0; i < n * 2; i++) { const a = rot + i / (n * 2) * Math.PI * 2, rr = i % 2 ? r * .55 : r * (1 + .12 * hash(i)); P.push([x + Math.cos(a) * rr, y + Math.sin(a) * rr]); }
+ poly(ctx, P); fill(ctx, color); poly(ctx, P); stroke(ctx, 4);
+}
+// comic word that slams in over an impact star and holds, e.g. "POW!", "HIT!", "K.O."
+export function comicText(ctx, t, t0, x, y, str, { size = 90, dur = .7, color = "#FFFFFF", star = "#FFD35A", rot = -.12, font = "sans-serif" } = {}) {
+ const d = t - t0; if (d < 0 || d > dur) return; const k = eBack(clamp(d / .16), 2.6), out = 1 - clamp((d - dur + .15) / .15);
+ ctx.save(); ctx.translate(x, y); ctx.rotate(rot); ctx.scale(k * out, k * out);
+ if (star) impactStar(ctx, 0, -size * .3, size * 1.25, 12, star, d * 2);
+ ctx.font = `${size}px "${font}"`; ctx.textAlign = "center"; ctx.lineJoin = "round"; ctx.lineWidth = size * .16; ctx.strokeStyle = INK; ctx.strokeText(str, 0, 0); ctx.fillStyle = color; ctx.fillText(str, 0, 0);
+ ctx.restore();
+}
+// a number or word that pops and floats up, e.g. "+100", "-12"
+export function floatText(ctx, t, t0, x, y, str, { size = 44, color = "#FFFFFF", dur = .8, rise = 90, font = "sans-serif" } = {}) {
+ const d = t - t0; if (d < 0 || d > dur) return; const k = eBack(clamp(d / .15), 2), a = 1 - clamp((d - dur * .6) / (dur * .4));
+ ctx.save(); ctx.globalAlpha *= a; ctx.translate(x, y - eOut(d / dur) * rise); ctx.scale(k, k); ctx.font = `${size}px "${font}"`; ctx.textAlign = "center"; ctx.lineJoin = "round";
+ ctx.lineWidth = size * .18; ctx.strokeStyle = INK; ctx.strokeText(str, 0, 0); ctx.fillStyle = color; ctx.fillText(str, 0, 0); ctx.restore();
+}
+// afterimages: call draw(ctx, gamePastTime, alpha) for a few earlier moments (dashes, fast flips)
+export function afterimages(ctx, g, draw, { n = 4, gap = .035, alpha = .35, tint = null } = {}) {
+ for (let i = n; i >= 1; i--) { ctx.save(); ctx.globalAlpha *= alpha * (1 - i / (n + 1)); draw(ctx, g - i * gap, i); ctx.restore(); }
+}
+// a rounded-ray spark: the special-attack projectile, pickups, stars
+export function starburst(ctx, x, y, r, { rays = 10, color = "#D97757", inner = .4, rot = 0, glow = 0, outline = true } = {}) {
+ if (glow > 0) { const g = ctx.createRadialGradient(x, y, r * .2, x, y, r * 2.2); g.addColorStop(0, `rgba(255,190,120,${.7 * glow})`); g.addColorStop(1, "rgba(255,190,120,0)"); ctx.fillStyle = g; ctx.fillRect(x - r * 2.2, y - r * 2.2, r * 4.4, r * 4.4); }
+ ctx.save(); ctx.translate(x, y); ctx.rotate(rot);
+ const drawRays = () => { ctx.beginPath(); let first = true; const pt = (x2, y2) => { first ? ctx.moveTo(x2, y2) : ctx.lineTo(x2, y2); first = false; };
+ for (let i = 0; i < rays; i++) { const a = i / rays * Math.PI * 2, w = Math.PI / rays * .85;
+ pt(Math.cos(a - w) * r * inner, Math.sin(a - w) * r * inner);
+ for (let k = 0; k <= 6; k++) { const aa = a - w * .35 + k / 6 * w * .7, rr = r * (1 - .06 * Math.pow((k - 3) / 3, 2)); pt(Math.cos(aa) * rr, Math.sin(aa) * rr); }
+ pt(Math.cos(a + w) * r * inner, Math.sin(a + w) * r * inner); }
+ ctx.closePath(); };
+ drawRays(); const g2 = ctx.createRadialGradient(0, 0, r * .1, 0, 0, r); g2.addColorStop(0, "#FFD3B8"); g2.addColorStop(1, color); ctx.fillStyle = g2; ctx.fill(); if (outline) { ctx.lineWidth = Math.max(2, r * .045); ctx.strokeStyle = INK; ctx.lineJoin = "round"; ctx.stroke(); }
+ ctx.restore();
+}
+export function heart(ctx, x, y, s, full = true) {
+ const P = []; for (let i = 0; i <= 30; i++) { const a = i / 30 * Math.PI * 2; P.push([x + 16 * Math.pow(Math.sin(a), 3) * s, y - (13 * Math.cos(a) - 5 * Math.cos(2 * a) - 2 * Math.cos(3 * a) - Math.cos(4 * a)) * s]); }
+ poly(ctx, P); fill(ctx, full ? "#E5484D" : "rgba(40,30,30,.35)"); if (full) { ellipse(ctx, x - 6 * s, y - 6 * s, 3.5 * s, 2.5 * s, -.5); fill(ctx, "rgba(255,255,255,.8)"); } poly(ctx, P); stroke(ctx, 3);
+}
diff --git a/plugins/claude-animation/skills/claude-animation/lib/rigs/bug.mjs b/plugins/claude-animation/skills/claude-animation/lib/rigs/bug.mjs
new file mode 100644
index 0000000..536efaf
--- /dev/null
+++ b/plugins/claude-animation/skills/claude-animation/lib/rigs/bug.mjs
@@ -0,0 +1,53 @@
+// bug.mjs — a beetle-ish enemy: glossy domed shell with spots, head with glowing eyes and mandibles, six
+// legs that scuttle, antennae. Same textured style as the ant (gradient, hatch, specular, rim light).
+//
+// LOCAL SPACE: facing -x (it walks toward a hero on its left), origin on the ground under the shell,
+// feet on y = 0. Shell ≈ 170 × 90 at s = 1. bug(ctx, x, groundY, s, pose)
+// pose: { shell: colour, flip (face +x), gait, rot, squash (0..1 flattened), flash, jaw (0..1), angry,
+// hurt (x eyes), horns (boss), t }
+import { clamp, lerp, rad, ellipse, stroke, fill, line, at, poly, hatch, INK } from "../core.mjs";
+
+function shade(hex, k) { const n = parseInt(hex.slice(1), 16), c = [n >> 16, (n >> 8) & 255, n & 255].map((v) => Math.round(clamp(k > 0 ? v + (255 - v) * k : v * (1 + k), 0, 255))); return `rgb(${c.join(",")})`; }
+
+export function bug(ctx, x, y, s = 1, p = {}) {
+ const col = p.shell || "#6A3FA0", flip = !!p.flip, sq = p.squash || 0, t = p.t || 0, ph = p.gait;
+ ctx.save(); ctx.translate(x, y); ctx.scale(s * (flip ? -1 : 1), s * (1 - sq * .65));
+ if (!p.rot) { ctx.save(); ctx.globalAlpha *= .25; ellipse(ctx, 0, 2, 105, 9); fill(ctx, "#1A1020"); ctx.restore(); }
+ if (p.rot) { ctx.translate(0, -60); ctx.rotate(p.rot); ctx.translate(0, 60); }
+ // legs (three pairs): hip under the shell, knee out and up beside it, foot splayed on the ground
+ const legs = (far) => { for (let i = 0; i < 3; i++) {
+ const hx = -40 + i * 40 + (far ? 10 : 0), hy = -36, set = (i % 2) ^ (far ? 1 : 0), sw = ph === undefined ? 0 : Math.sin(ph + set * Math.PI) * 16, lift = ph === undefined ? 0 : Math.max(0, Math.cos(ph + set * Math.PI)) * 9;
+ const kx = hx + (i - 1) * 46 - 8 + sw * .5, ky = -30 - lift, fx = hx + (i - 1) * 64 - 16 + sw, fy = -lift;
+ line(ctx, [[hx, hy], [kx, ky], [fx, fy]], far ? 6 : 7.6, INK); line(ctx, [[hx, hy], [kx, ky], [fx, fy]], far ? 3 : 4, far ? "#2E2238" : "#4A3858");
+ line(ctx, [[fx, fy], [fx - 9, fy + 1]], 3, INK); } };
+ legs(true);
+ // shell
+ const SH = () => { ctx.beginPath(); ctx.moveTo(-88, -34); ctx.bezierCurveTo(-92, -112, 70, -118, 84, -40); ctx.quadraticCurveTo(0, -26, -88, -34); ctx.closePath(); };
+ const g = ctx.createRadialGradient(-20, -100, 10, 0, -60, 120); g.addColorStop(0, shade(col, .35)); g.addColorStop(.6, col); g.addColorStop(1, shade(col, -.45)); SH(); fill(ctx, g);
+ ctx.save(); SH(); ctx.clip();
+ hatch(ctx, () => ellipse(ctx, 10, -40, 100, 30), rad(-40), 6, "#140A1E", 1.2, .35, [-100, -120, 100, -20]);
+ line(ctx, [[-2, -104], [-4, -32]], 3, "rgba(20,10,30,.6)"); // elytra seam
+ for (const [sx, sy, r] of [[-50, -70, 11], [-22, -88, 9], [28, -86, 10], [50, -62, 12], [-6, -58, 8]]) { ellipse(ctx, sx, sy, r, r * .8); fill(ctx, shade(col, -.55)); }
+ ctx.beginPath(); ctx.ellipse(0, -70, 84, 40, 0, .3, 2.6); stroke(ctx, 3, "rgba(255,200,255,.25)");
+ ctx.restore(); SH(); stroke(ctx, 3.4);
+ ellipse(ctx, -34, -96, 22, 7, -.3); fill(ctx, "rgba(255,255,255,.6)");
+ legs(false);
+ if (p.horns) { for (const [hx2, a] of [[-40, -.5], [30, .4]]) { ctx.beginPath(); ctx.moveTo(hx2 - 8, -104); ctx.quadraticCurveTo(hx2 + a * 30, -150, hx2 + a * 50, -168); ctx.quadraticCurveTo(hx2 + a * 16, -130, hx2 + 8, -106); ctx.closePath(); fill(ctx, "#E8DCC0"); stroke(ctx, 2.8); } }
+ // head
+ ctx.save(); ctx.translate(-92, -46);
+ ellipse(ctx, 0, 0, 30, 25); const hg = ctx.createRadialGradient(-8, -10, 2, 0, 0, 32); hg.addColorStop(0, shade(col, -.1)); hg.addColorStop(1, shade(col, -.6)); fill(ctx, hg); stroke(ctx, 3);
+ // mandibles
+ const j = p.jaw || 0; for (const sg of [-1, 1]) at(ctx, -24, 8, 1, sg * (.2 + j * .6), () => { ctx.beginPath(); ctx.moveTo(0, 0); ctx.quadraticCurveTo(-26, sg * 4, -30, sg * 16); ctx.lineTo(-20, sg * 8); ctx.lineTo(-14, sg * 12); ctx.quadraticCurveTo(-8, sg * 4, 0, sg * 6); ctx.closePath(); fill(ctx, "#2A1E30"); stroke(ctx, 2); });
+ if (j > .3) { ellipse(ctx, -26, 8, 10 * j, 12 * j); fill(ctx, "#5A0E1A"); }
+ // eyes
+ for (const [ex, ey] of [[-10, -8], [8, -12]]) {
+ if (p.hurt) { line(ctx, [[ex - 6, ey - 6], [ex + 6, ey + 6]], 3.4); line(ctx, [[ex + 6, ey - 6], [ex - 6, ey + 6]], 3.4); continue; }
+ const gl = ctx.createRadialGradient(ex, ey, 1, ex, ey, 16); gl.addColorStop(0, "rgba(255,80,60,.55)"); gl.addColorStop(1, "rgba(255,80,60,0)"); ctx.fillStyle = gl; ctx.fillRect(ex - 16, ey - 16, 32, 32);
+ ellipse(ctx, ex, ey, 7, 8); fill(ctx, "#FF4A36"); stroke(ctx, 2); ellipse(ctx, ex - 2, ey - 3, 2.2, 2.2); fill(ctx, "#fff");
+ if (p.angry) line(ctx, [[ex - 10, ey - 14 + (ex < 0 ? -4 : 2)], [ex + 10, ey - 14 + (ex < 0 ? 2 : -4)]], 4); }
+ // antennae
+ for (const [ax, sw] of [[-4, 0], [10, 1.3]]) { const w = Math.sin(t * 8 + sw) * 8; ctx.beginPath(); ctx.moveTo(ax, -22); ctx.quadraticCurveTo(ax - 10, -60, ax - 34 + w, -70); stroke(ctx, 3); ellipse(ctx, ax - 34 + w, -70, 4.5, 4.5); fill(ctx, INK); }
+ ctx.restore();
+ if (p.flash > 0) { ctx.save(); ctx.globalAlpha *= p.flash; SH(); fill(ctx, "#FFFFFF"); ellipse(ctx, -92, -46, 30, 25); fill(ctx, "#FFFFFF"); ctx.restore(); }
+ ctx.restore();
+}
diff --git a/plugins/claude-animation/skills/claude-animation/lib/rigs/critter.mjs b/plugins/claude-animation/skills/claude-animation/lib/rigs/critter.mjs
new file mode 100644
index 0000000..794a977
--- /dev/null
+++ b/plugins/claude-animation/skills/claude-animation/lib/rigs/critter.mjs
@@ -0,0 +1,82 @@
+// critter.mjs — a blocky little hero built for action: squash & stretch, run, jump, flip, punch, kick,
+// get hurt, charge up. Rounded block body with a faint pixel grid, two tall eyes, stub arms, four legs.
+//
+// LOCAL SPACE: facing +x, origin on the ground under the body centre; feet on y = 0. Body 130 × 100 at s = 1.
+// critter(ctx, x, groundY, s, pose)
+// pose: {
+// color body colour (default a warm orange)
+// flip face -x
+// gait run phase (radians); omit to stand
+// sq squash/stretch: >1 = squashed (wide, short), <1 = stretched (tall, thin); about the feet
+// rot whole-body spin about the body centre (flips, tumbles)
+// face "normal" | "blink" | "happy" | "angry" | "hurt" | "surprised" | "focus"
+// punch 0..1 front arm jab (0 rest, 1 fully out); punchBack for the rear arm
+// kick 0..1 front leg kick
+// arms "rest" | "up" (cheer) | "guard"
+// crouch 0..1 lowers the body (charging, before a jump)
+// aura 0..1 power-up glow + flame tongues
+// flash 0..1 white hit flash
+// air true while airborne: legs tuck
+// }
+import { clamp, lerp, rad, ellipse, stroke, fill, line, at, poly, rrect, hatch, INK } from "../core.mjs";
+
+function shade(hex, k) { const n = parseInt(hex.slice(1), 16), c = [n >> 16, (n >> 8) & 255, n & 255].map((v) => Math.round(clamp(k > 0 ? v + (255 - v) * k : v * (1 + k), 0, 255))); return `rgb(${c.join(",")})`; }
+
+export function critter(ctx, x, y, s = 1, p = {}) {
+ const col = p.color || "#D97757", flip = !!p.flip, sq = p.sq ?? 1, crouch = p.crouch || 0, face = p.face || "normal", t = p.t || 0;
+ const BW = 130 * Math.sqrt(sq), BH = 100 / Math.sqrt(sq) * (1 - crouch * .18), LEG = p.air ? 8 : 14 * (1 - crouch * .5), cy = -LEG - BH / 2;
+ ctx.save(); ctx.translate(x, y); ctx.scale(s * (flip ? -1 : 1), s);
+ // aura behind everything
+ if (p.aura > 0) { const a = p.aura, g = ctx.createRadialGradient(0, cy, 20, 0, cy, 170 + 40 * a); g.addColorStop(0, `rgba(255,190,110,${.55 * a})`); g.addColorStop(1, "rgba(255,190,110,0)"); ctx.fillStyle = g; ctx.fillRect(-260, cy - 260, 520, 520);
+ for (let i = 0; i < 9; i++) { const u = i / 9, fx = -BW / 2 - 10 + u * (BW + 20), h = (60 + 50 * Math.abs(Math.sin(t * 9 + i * 1.7))) * a;
+ ctx.beginPath(); ctx.moveTo(fx - 14, -LEG); ctx.quadraticCurveTo(fx - 18, -LEG - h * .6, fx + Math.sin(t * 7 + i) * 8, -LEG - BH - h * .4); ctx.quadraticCurveTo(fx + 18, -LEG - h * .6, fx + 14, -LEG); ctx.closePath();
+ ctx.fillStyle = `rgba(255,${150 + (i % 3) * 30},70,${.35 * a})`; ctx.fill(); } }
+ // contact shadow
+ if (!p.air) { ctx.save(); ctx.globalAlpha *= .25; ellipse(ctx, 0, 2, BW * .62, 8); fill(ctx, "#2A1A10"); ctx.restore(); }
+ ctx.save(); if (p.rot) { ctx.translate(0, cy); ctx.rotate(p.rot); ctx.translate(0, -cy); }
+ // legs: four stubs, far pair darker; running alternates pairs
+ const run = p.gait !== undefined, ph = p.gait || 0;
+ const legX = [-44, -16, 16, 44];
+ legX.forEach((lx, i) => { const far = i % 2 === 1, pair = (i === 0 || i === 3) ? 0 : 1, sw = run ? Math.sin(ph + pair * Math.PI) : 0;
+ const lift = run ? Math.max(0, Math.cos(ph + pair * Math.PI)) * 10 : 0, kx = (p.kick && i === 3) ? p.kick * 60 : 0, ky = (p.kick && i === 3) ? -p.kick * 30 : 0;
+ const L = p.air ? LEG + 4 : LEG, x0 = lx * (BW / 130) + sw * 12, y0 = -L - lift * .5;
+ if (kx) { poly(ctx, rrect(x0 - 8, -L - 10, 16 + kx, 16, 6)); fill(ctx, shade(col, -.15)); stroke(ctx, 2.6); poly(ctx, rrect(x0 + kx - 4, -L - 16 + ky * .2, 22, 26, 7)); fill(ctx, shade(col, .05)); stroke(ctx, 2.8); return; }
+ poly(ctx, rrect(x0 - 8, y0 - 4, 16, L + 4 - lift * .5, 4)); fill(ctx, far ? shade(col, -.35) : shade(col, -.15)); stroke(ctx, 2.6); });
+ // rear arm
+ const arm = (front, jab) => { const ax = front ? BW / 2 - 6 : -BW / 2 + 6, ay = cy + 8, up = p.arms === "up", guard = p.arms === "guard";
+ const ext = jab * 78, ex = ax + (front ? 1 : -1) * (up ? 4 : 10) + (front ? ext : ext * .6 * (front ? 1 : 1)), ey = up ? ay - 48 : guard ? ay - 18 : ay + 6 - jab * 6;
+ const fx = front ? ex : (jab > 0 ? ax + ext : ex);
+ ctx.save(); poly(ctx, rrect(Math.min(ax, fx) - 2, ey - 10, Math.abs(fx - ax) + 4 + 16, 20, 8)); fill(ctx, shade(col, front ? -.05 : -.3)); stroke(ctx, 2.6);
+ if (jab > .3) { poly(ctx, rrect(fx + 4, ey - 15, 30, 30, 9)); fill(ctx, shade(col, .1)); stroke(ctx, 3); line(ctx, [[fx + 12, ey - 6], [fx + 12, ey + 6]], 2, "rgba(30,20,15,.5)"); }
+ ctx.restore(); };
+ arm(false, p.punchBack || 0);
+ // body: gradient + pixel grid + hatch + rim + specular
+ const B = rrect(-BW / 2, cy - BH / 2, BW, BH, 20);
+ const g = ctx.createLinearGradient(-BW / 2, cy - BH / 2, BW / 2, cy + BH / 2); g.addColorStop(0, shade(col, .28)); g.addColorStop(.55, col); g.addColorStop(1, shade(col, -.28));
+ poly(ctx, B); fill(ctx, g);
+ ctx.save(); poly(ctx, B); ctx.clip();
+ ctx.strokeStyle = "rgba(90,35,15,.12)"; ctx.lineWidth = 1.2; for (let gx = -BW / 2; gx < BW / 2; gx += 13) { ctx.beginPath(); ctx.moveTo(gx, cy - BH / 2); ctx.lineTo(gx, cy + BH / 2); ctx.stroke(); } for (let gy = cy - BH / 2; gy < cy + BH / 2; gy += 13) { ctx.beginPath(); ctx.moveTo(-BW / 2, gy); ctx.lineTo(BW / 2, gy); ctx.stroke(); }
+ hatch(ctx, () => { ctx.beginPath(); ctx.rect(-BW / 2, cy + BH * .1, BW, BH); }, rad(-50), 6, "#7A2E14", 1, .3, [-BW / 2, cy, BW / 2, cy + BH / 2]);
+ line(ctx, [[-BW / 2 + 14, cy + BH / 2 - 7], [BW / 2 - 14, cy + BH / 2 - 7]], 4, "rgba(255,210,170,.5)");
+ ctx.restore();
+ poly(ctx, B); stroke(ctx, 3.4);
+ poly(ctx, rrect(-BW / 2 + 12, cy - BH / 2 + 9, BW * .32, 10, 5)); fill(ctx, "rgba(255,255,255,.55)");
+ // eyes (side view: both on the front half)
+ const ex = [BW * .1, BW * .34], eyY = cy - BH * .06;
+ const eye = (xx) => {
+ if (face === "blink") line(ctx, [[xx - 7, eyY + 4], [xx + 7, eyY + 4]], 4);
+ else if (face === "happy") { ctx.beginPath(); ctx.moveTo(xx - 9, eyY + 6); ctx.lineTo(xx, eyY - 6); ctx.lineTo(xx + 9, eyY + 6); stroke(ctx, 4.4); }
+ else if (face === "hurt") { line(ctx, [[xx - 8, eyY - 8], [xx + 8, eyY + 8]], 4); line(ctx, [[xx + 8, eyY - 8], [xx - 8, eyY + 8]], 4); }
+ else { const tall = face === "surprised" ? 32 : face === "focus" ? 16 : 26, w = face === "surprised" ? 15 : 13;
+ poly(ctx, rrect(xx - w / 2, eyY - tall / 2, w, tall, 4)); fill(ctx, "#1A120E"); ellipse(ctx, xx - 2, eyY - tall / 2 + 6, 3, 4); fill(ctx, "#fff");
+ if (face === "angry" || face === "focus") line(ctx, [[xx - 12, eyY - tall / 2 - 12 + (xx > BW * .2 ? 6 : 0)], [xx + 12, eyY - tall / 2 - 12 + (xx > BW * .2 ? 0 : 6)]], 5); } };
+ ex.forEach(eye);
+ if (face === "surprised") { ctx.font = "bold 64px sans-serif"; ctx.fillStyle = INK; ctx.fillText("!", BW * .2, cy - BH / 2 - 26); }
+ if (face === "happy" || face === "hurt") { ellipse(ctx, BW * .44, cy + BH * .22, 9, 5); fill(ctx, "rgba(229,72,77,.45)"); }
+ // front arm on top
+ arm(true, p.punch || 0);
+ // hit flash
+ if (p.flash > 0) { ctx.save(); ctx.globalAlpha *= p.flash; poly(ctx, B); fill(ctx, "#FFFFFF"); ctx.restore(); }
+ ctx.restore();
+ ctx.restore();
+}
diff --git a/plugins/claude-animation/skills/claude-animation/references/motion.md b/plugins/claude-animation/skills/claude-animation/references/motion.md
index dec0fd8..1083d71 100644
--- a/plugins/claude-animation/skills/claude-animation/references/motion.md
+++ b/plugins/claude-animation/skills/claude-animation/references/motion.md
@@ -47,6 +47,21 @@ In the Pen, boil is opt-in: `pen.begin(name, reveal, { boil: 10, t })`.
- 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").
+## Action and game feel (from the game short)
+
+- **Write choreography in game time, render in real time.** `timeWarp(STOPS)` freezes game time for 2–3
+ frames on every contact (0.083 s; 0.125 for a big hit; 0.3 for the finisher) while sparks, rings and
+ comic words keep moving in real time. Convert cues with `tw.real(g)` so sound lands on the freeze.
+- **Squash on landing** (1.35 → 1 over 0.18 s), **stretch in the air** (0.8), **anticipation** before a jump
+ (1.22 for ~2 frames). A dash is 0.72 stretch + 0.12 lean + afterimages + speed lines.
+- **Every hit = five things on the same frame**: target flash (cap ~0.6 or the body turns into a white
+ hole), sparks, a ring, a comic word or a damage number, screen shake. Plus a sound pair (thump + crack).
+- **Knockback reads as a hit** only with a hurt face, a back-spin and invulnerability flicker afterwards.
+- **A world camera zoom of ~1.3** around the ground line: at 1× a 130 px hero on 1920 reads as a UI icon.
+- Boss beats: WARNING bars before it appears, a drop with squash + ring + debris, a roar (jaw + rings),
+ a readable attack pattern the hero dodges, a combo, a hit back, a charge (darken the screen, embers),
+ the finisher, a drain on the HP bar, K.O., LEVEL CLEAR.
+
## Effects vocabulary
burst lines (a pop, a realisation) · speed lines (fast travel) · impact lines (landing) · dirt clods (dig)
diff --git a/plugins/claude-animation/skills/claude-animation/references/sound.md b/plugins/claude-animation/skills/claude-animation/references/sound.md
index 7760864..a363984 100644
--- a/plugins/claude-animation/skills/claude-animation/references/sound.md
+++ b/plugins/claude-animation/skills/claude-animation/references/sound.md
@@ -10,6 +10,9 @@
~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/chiptune.mjs`**: an original game soundtrack (pulse lead, triangle bass, noise drums) with
+ sections placed on absolute times: `--sections "level:0-13.8,alarm:13.8-15.4,boss:15.4-25.1,fanfare:25.1-27.7,outro:27.7-30"`.
+ Compute the times after hit-stop (`tw.real`), or the boss music starts before the boss.
- **`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).
diff --git a/plugins/claude-animation/skills/claude-animation/scripts/chiptune.mjs b/plugins/claude-animation/skills/claude-animation/scripts/chiptune.mjs
new file mode 100644
index 0000000..041d687
--- /dev/null
+++ b/plugins/claude-animation/skills/claude-animation/scripts/chiptune.mjs
@@ -0,0 +1,60 @@
+// chiptune.mjs — an original video-game soundtrack synthesised in code: pulse-wave lead and arpeggio,
+// triangle bass, noise hats/snare, a pitch-drop kick. Sections are placed on absolute times so the music
+// can turn with the picture (level → alarm → boss → fanfare → outro).
+//
+// node chiptune.mjs out.wav --dur 30 --bpm 150 --sections "level:0-13.5,alarm:13.5-15,boss:15-24,fanfare:24-26.6,outro:26.6-30"
+//
+// section kinds: level (major, bouncy), alarm (pulsing low bass + siren blip), boss (minor, driving 16ths),
+// fanfare (rising arpeggio to a held chord), outro (soft arpeggio, ends on a chord), silence
+import fs from "node:fs";
+
+const A = process.argv, opt = (k, d) => A.includes(k) ? A[A.indexOf(k) + 1] : d;
+const OUT = A[2] && !A[2].startsWith("--") ? A[2] : "chiptune.wav";
+const SR = 44100, DUR = parseFloat(opt("--dur", "30")), BPM = parseFloat(opt("--bpm", "150")), B = 60 / BPM, BAR = B * 4, E8 = B / 2, S16 = B / 4;
+const SECTIONS = opt("--sections", `level:0-${DUR}`).split(",").map((s) => { const [k, r] = s.split(":"); const [a, b] = r.split("-").map(Number); return { k, a, b }; });
+const N = Math.floor(SR * DUR), L = new Float32Array(N), R = new Float32Array(N);
+const hz = (m) => 440 * Math.pow(2, (m - 69) / 12);
+const add = (i, v, pan = 0) => { if (i >= 0 && i < N) { L[i] += v * (1 - pan) * .5; R[i] += v * (1 + pan) * .5; } };
+
+function pulse(t0, dur, midi, amp, duty = .25, pan = 0, vib = 0) { const f = hz(midi), s0 = Math.round(t0 * SR), n = Math.round(dur * SR); let ph = 0;
+ for (let i = 0; i < n; i++) { const tt = i / SR, env = Math.min(1, i / 60) * (tt < dur * .7 ? 1 : 1 - (tt - dur * .7) / (dur * .3)) * (1 - .25 * Math.min(1, tt / .12)); ph += f * (1 + vib * Math.sin(tt * 34) * Math.min(1, tt / .2)) / SR; add(s0 + i, ((ph % 1) < duty ? 1 : -1) * amp * env, pan); } }
+function tri(t0, dur, midi, amp) { const f = hz(midi), s0 = Math.round(t0 * SR), n = Math.round(dur * SR); let ph = 0;
+ for (let i = 0; i < n; i++) { ph += f / SR; const x = ph % 1, v = x < .5 ? 4 * x - 1 : 3 - 4 * x, env = Math.min(1, i / 40) * Math.min(1, (n - i) / 400); add(s0 + i, v * amp * env); } }
+let seed = 7; const noise = () => ((seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff) * 2 - 1;
+function hat(t0, amp = .12, len = .04) { const s0 = Math.round(t0 * SR), n = Math.round(len * SR); let prev = 0; for (let i = 0; i < n; i++) { const w = noise(), hp = w - prev; prev = w; add(s0 + i, hp * amp * (1 - i / n), .2); } }
+function snare(t0, amp = .3) { const s0 = Math.round(t0 * SR), n = Math.round(.14 * SR); for (let i = 0; i < n; i++) add(s0 + i, (noise() * .8 + Math.sin(2 * Math.PI * 190 * i / SR) * .4) * amp * Math.exp(-i / SR * 22)); }
+function kick(t0, amp = .6) { const s0 = Math.round(t0 * SR), n = Math.round(.2 * SR); let ph = 0; for (let i = 0; i < n; i++) { const tt = i / SR; ph += (48 + 110 * Math.exp(-tt * 35)) / SR; add(s0 + i, Math.sin(ph * 2 * Math.PI) * amp * Math.exp(-tt * 14)); } }
+
+// C major level loop: C G Am F. Melody in 8th-note slots (null = rest, "-" = hold previous)
+const LEVEL_CH = [[48, 52, 55], [43, 47, 50], [45, 48, 52], [41, 45, 48]];
+const LEVEL_MEL = [[76, "-", 79, "-", 84, "-", 83, 81], [79, "-", 74, "-", 79, 81, 83, "-"], [81, "-", 76, "-", 84, "-", 83, 81], [77, 79, 81, "-", 84, "-", 81, null]];
+const BOSS_CH = [[45, 48, 52], [41, 45, 48], [43, 47, 50], [40, 44, 47]]; // Am F G E
+const BOSS_MEL = [[69, 72, 76, 72, 81, 76, 72, 76], [65, 69, 72, 69, 77, 72, 69, 72], [67, 71, 74, 71, 79, 74, 71, 74], [68, 71, 76, 71, 80, 76, 71, 76]];
+
+function level(a, b) {
+ for (let bar = 0; a + bar * BAR < b; bar++) { const t0 = a + bar * BAR, ch = LEVEL_CH[bar % 4], mel = LEVEL_MEL[bar % 4];
+ for (let q = 0; q < 4; q++) { const t = t0 + q * B; if (t >= b) break; tri(t, B * .9, ch[0] - 12 + (q % 2 ? 7 : 0), .32); kick(t, q % 2 ? 0 : .5); if (q % 2) snare(t, .22); hat(t + E8, .1); hat(t, .06); }
+ for (let k = 0; k < 16; k++) { const t = t0 + k * S16; if (t >= b) break; pulse(t, S16 * .9, ch[k % 3] + 24 + (k >= 8 ? 12 : 0), .045, .125, -.3); }
+ let held = null; for (let k = 0; k < 8; k++) { const t = t0 + k * E8, m = mel[k]; if (t >= b) break; if (m === "-") continue; if (m === null) continue;
+ let len = 1; while (k + len < 8 && mel[k + len] === "-") len++; pulse(t, E8 * len * .95, m, .1, .25, .15, .006); } }
+}
+function boss(a, b) {
+ for (let bar = 0; a + bar * BAR < b; bar++) { const t0 = a + bar * BAR, ch = BOSS_CH[bar % 4], mel = BOSS_MEL[bar % 4];
+ for (let k = 0; k < 8; k++) { const t = t0 + k * E8; if (t >= b) break; tri(t, E8 * .85, ch[0] - 12 + (k % 2 ? 12 : 0), .34); if (k % 2 === 0) kick(t, .55); hat(t + S16, .09); }
+ snare(t0 + B, .3); snare(t0 + 3 * B, .3); if (bar % 2) snare(t0 + 3.5 * B, .2);
+ for (let k = 0; k < 16; k++) { const t = t0 + k * S16; if (t >= b) break; pulse(t, S16 * .85, mel[k % 8] + (bar % 2 ? 12 : 0), .07, .25, .1); }
+ for (let q = 0; q < 2; q++) { const t = t0 + q * 2 * B; if (t < b) pulse(t, 2 * B * .9, ch[1] + 12, .035, .5, -.3); } }
+}
+function alarm(a, b) { for (let t = a; t < b; t += B) { tri(t, B * .8, 33, .4); kick(t, .45); pulse(t, B * .45, 81, .05, .5, 0); pulse(t + B * .5, B * .45, 76, .05, .5, 0); } }
+function fanfare(a, b) { const run = [60, 64, 67, 72, 76, 79, 84]; run.forEach((m, i) => pulse(a + i * S16 * 1.3, S16 * 1.2, m, .1, .25)); const h = a + run.length * S16 * 1.3;
+ for (const m of [72, 76, 79, 84]) pulse(h, Math.max(.2, b - h - .1), m, .06, .5); tri(h, b - h, 36, .35); kick(a, .6); kick(h, .6); snare(h, .3); for (let t = h; t < b; t += E8) hat(t, .08); }
+function outro(a, b) { const ch = [[60, 64, 67, 72], [57, 60, 64, 69], [53, 57, 60, 65], [55, 59, 62, 67]];
+ for (let bar = 0; a + bar * BAR < b - 1.2; bar++) { const t0 = a + bar * BAR, c = ch[bar % 4]; for (let k = 0; k < 8; k++) { const t = t0 + k * E8; if (t < b - 1.2) pulse(t, E8 * .9, c[k % 4] + 12, .05, .125, (k % 2 ? .3 : -.3)); } tri(t0, BAR * .95, c[0] - 24, .25); }
+ for (const m of [60, 64, 67, 72]) pulse(b - 1.2, 1.1, m, .06, .5); tri(b - 1.2, 1.1, 36, .3); }
+for (const { k, a, b } of SECTIONS) ({ level, boss, alarm, fanfare, outro, silence: () => {} })[k]?.(a, b);
+
+let pk = 0; for (let i = 0; i < N; i++) pk = Math.max(pk, Math.abs(L[i]), Math.abs(R[i]));
+const g = .89 / (pk || 1), 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 i = 0; i < N; i++) { const f = i > N - SR * .6 ? (N - i) / (SR * .6) : 1; buf.writeInt16LE(Math.round(Math.tanh(L[i] * g) * f * 32767), 44 + i * 4); buf.writeInt16LE(Math.round(Math.tanh(R[i] * g) * f * 32767), 46 + i * 4); }
+fs.writeFileSync(OUT, buf); console.log("chiptune", DUR, "s,", SECTIONS.map((s) => s.k).join(" → "));
diff --git a/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs b/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs
index 00940f5..2b3fb7d 100644
--- a/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs
+++ b/plugins/claude-animation/skills/claude-animation/scripts/sound.mjs
@@ -7,7 +7,8 @@
// 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.
+// The mix gets a two-pass loudnorm (default -16 LUFS), then a 4x-oversampled limiter at -3.1 dBFS (AAC adds ~1.5 dB of inter-sample overshoot) so dense
+// hit-heavy mixes can't overshoot (a game mix hit +1.6 dBTP without it), and is muxed onto the picture.
import fs from "node:fs";
import { execFileSync } from "node:child_process";
@@ -62,7 +63,7 @@ if (process.argv[1] && process.argv[1].endsWith("sound.mjs")) {
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`;
+ 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=192000,alimiter=limit=0.7:level=false:attack=1:release=40,aresample=48000` : `loudnorm=I=${I}:TP=-1.5,alimiter=limit=0.7:level=false`;
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)` : "");