Animating with code
You write the drawing; a headless browser (or PIL, cairo, ffmpeg) renders it. The
method below comes from the ClaudeAnimationBase kit's guide and holds for any
renderer. The kit itself is the fastest route to a hand-painted character short.
Before building, name the route and why (Oskar's standing steer, memory 06886186):
the kit, a CSS/HTML page captured frame by frame, a pure ffmpeg filtergraph, or
PIL/cairo frames.
The contract: frames are pure functions of t
- A shot is
fn(t). Same t, same pixels. No counters, no state carried between
frames, no integrated physics, no unseeded random. Then frames can
render out of order, split across parallel workers, and resume after a crash.
- Stable per-object values come from a hash of an index. Deliberate wobble
("boil") comes from a seed that changes on a fixed clock (the kit uses 12 Hz,
each drawing held two frames).
- Reseed per element. A moving element consumes a variable amount of randomness;
without its own seed it shifts the stream for everything drawn after it and
the still parts jitter every frame.
Procedure
- Storyboard in writing, before any scene code. One logline (wants ___, but
___, so ___), a small palette with a colour arc, a motif that pays off, and
the emotion keys across the whole film. Then per shot: time span, transition
in, the event, the reaction, the camera, and the reads.
- Write the reads. A read is one thing the viewer must understand, with a
start and end time. Each needs time for the eye to find it, to understand it,
and to register before the next starts. No two important reads overlap. If
they do not fit the shot, lengthen the shot or cut a read. Timing is where
generated animation fails most: everything at one brisk speed, events stacked,
moments gone before they land.
- Check the storyboard: an event in every shot, a transition at every seam
(including in and out of the film), no text, the ending rhymes with the opening.
If a person is waiting, show them the storyboard before building.
- Block key poses as stills at each shot's storytelling moments. If the
poses do not read as stills, motion will not save them.
- Add motion between poses, one shot at a time, in order: anticipation
before big moves, slow in/out instead of raw lerp, arcs, overlapping action
(eyes lead, body follows, appendages settle last), no twinning (offset left
and right, offset characters' phases), exaggeration.
- Review loop (below) on every shot. Fix, look again.
- Render the full film; verify with
ffprobe that duration and frame count
match the config.
Review loop
You cannot see motion by reading code. Render images and open them with Read.
| view |
what it shows |
catches |
| contact sheet |
first, middle, last frame of every shot |
missing events, small or lost characters, dead stretches |
| fixed-step sheet (every 0.1–0.15 s) |
one shot, read in order |
timing: where is the eye now, does the viewer get it yet |
| frame strip |
every frame of a 0.5 s stretch |
pops, snaps, missing anticipation, boil jitter on still parts |
| crop |
full-res detail |
faces, contacts (feet on ground, props in hands), muddy glows |
| crop following a world point |
the same detail through a moving camera |
contacts on camera moves |
Count frames per read (24 = 1 s). A read that gets a few frames, or shares its
frames with another read, will be missed. Budget: one sheet per shot, one strip
per key motion and per transition, one crop per face that carries the story.
Rules from the kit's guide
Defaults, overridden by whatever the person asks for.
- No text. No captions, labels, signs, or words on screens. Reactions are
painted marks (
!, ?, sweat, hearts, a bulb). A sign that restates the story
is the classic failure.
- Flat 2D, no projected 3D. Turns go through drawn key views (front, 3/4,
side, back 3/4, back) with smears. Depth from overlap, scale and paler, bluer
colour.
- Nothing still. Idle motion per emotion, drifting cameras, swaying grass. A
frozen frame reads as a bug.
- Faces act, never snap. Mood changes go squint, swap under the squint, take,
overshoot, settle.
- One beat. A single BPM drives idles and bounces even with no music.
- No pure black or white. Additive light for glows: pigment-mixing brushes
turn yellow-over-blue green.
The ClaudeAnimationBase route
https://github.com/JohnHeibel/ClaudeAnimationBase, MIT, verified at commit
0ac8bf2 (2026-09-24). Its ANIMATION_GUIDE.md (36 KB) is the full API: read it
whole before drawing. render.mjs provides the review views as flags
(--sheet=, --strip=a:b, --crop=x,y,w,h, --crop-at=, --stills=, --clip,
--frames --workers=N + --encode).
Recipe for a CCotw container, verified 2026-10-25 (4 CPUs, no GPU, Chromium at
/opt/pw-browsers/chromium-*/chrome-linux64/chrome):
SCRATCH=/path/outside/the/checkout # the session scratchpad
CHROME=$(ls -d /opt/pw-browsers/chromium-*/chrome-linux64/chrome | tail -1)
git clone --depth 1 https://github.com/JohnHeibel/ClaudeAnimationBase /tmp/jail/cab
# deps from the registry, outside the checkout, no install scripts; versions from package-lock.json
mkdir -p "$SCRATCH/cabdeps" && cd "$SCRATCH/cabdeps" && npm init -y >/dev/null \
&& npm install --ignore-scripts p5@2.3.3 p5.brush@2.2.3 puppeteer-core@25.11.0
cp -r "$SCRATCH/cabdeps/node_modules" /tmp/jail/cab/
sed -i '/fonts.googleapis.com/d' /tmp/jail/cab/studio.html # only letter() uses it
sed -i "s/{ waitUntil: 'networkidle0' }/{ waitUntil: 'networkidle0', timeout: 0 }/; s/{ timeout: 60000 }/{ timeout: 0 }/" /tmp/jail/cab/render.mjs
chown -R nobody:nogroup /tmp/jail/cab
sh scripts/jail.sh -C /tmp/jail/cab -- node render.mjs --soft-gl \
--chrome="$CHROME" \
--sheet=0.5,2,4,6,8,10 --cols=3 --w=480 --out=out/sheet.jpg
In claude-workspace, run the kit only inside scripts/jail.sh (hub rule for
code nobody here wrote). Elsewhere, drop the jail prefix.
Cost. Under SwiftShader the demo's six-frame sheet took 0.3, 0.2, 36, 47, 40
and 42 s per frame. At ~40 s, the 11 s demo (264 frames) is about 3 hours on one
worker. Before a full render, either ask the scene to avoid p5.brush watercolour
fill (the kit's README suggests this for machines without a GPU), split across
--frames --workers=N and run it as a background job, or render on a GPU host
(--gpu-angle=gl-egl|vulkan). The review loop stays cheap: sheets and strips
render a handful of frames.
Failure signals
| signal |
cause |
fix |
connect ENETUNREACH 127.0.0.1:<port> from puppeteer |
network namespace with lo down |
claude-workspace scripts/jail.sh raises lo since 711fac1; pull the hub |
Navigation timeout of 30000 ms exceeded, with ERR_INTERNET_DISCONNECTED |
page waits on Google Fonts with no network |
delete the fonts link |
| same timeout, no failed request |
p5.brush init takes ~20 s under SwiftShader |
timeout: 0 on goto and waitForFunction |
Failed to construct 'OffscreenCanvas': Value is not of type 'unsigned long' |
a NaN in a point list; the stack points at the scene, not the NaN |
guard degenerate geometry (Math.acos of a ratio > 1) |
| an outline collapses to a dot at zoom ≥ 2 |
stroke drawn far from the origin |
draw long edges as inkLines no bigger than the canvas |
| still parts flicker in a strip |
shared random stream behind a moving element |
boilSeed(key) before each element |
five WebGL: INVALID_OPERATION ... not from the associated program warnings |
p5.brush, once per page |
harmless; any other page error is real |
Verification
Open every sheet and strip with Read and look before calling a shot done. For the
final file, this must match the config's duration and fps:
ffprobe -v error -show_entries format=duration:stream=nb_frames,r_frame_rate -of default=nw=1 out/video.mp4
Report
the route used, the render time per frame, and anything the review loop found
that you did not fix.
1---2name: animating-with-code3description: "Make a short animated film by writing the drawing code yourself: every frame a pure function of time, rendered headlessly to MP4. Covers storyboarding with a per-shot timing sheet of viewer 'reads', blocking key poses as stills, the contact-sheet / frame-strip / crop review loop, and the hand-painted character kit JohnHeibel/ClaudeAnimationBase (p5.js + p5.brush, the Clawd mascot, 31 emotions). Use for 'animate', 'make a cartoon', 'animated short', 'motion graphic', 'Clawd video', 'p5 animation', or any video request where Claude draws the frames. Not for AI-generated footage (creating-video), transcoding or trimming existing video (processing-video), or a comic from footage (drawing-video)."4metadata:5 source: https://skillmd.com/skills/oaustegard/animating-with-code6 version: 0.1.07---89# Animating with code1011You write the drawing; a headless browser (or PIL, cairo, ffmpeg) renders it. The12method below comes from the ClaudeAnimationBase kit's guide and holds for any13renderer. The kit itself is the fastest route to a hand-painted character short.1415Before building, name the route and why (Oskar's standing steer, memory 06886186):16the kit, a CSS/HTML page captured frame by frame, a pure ffmpeg filtergraph, or17PIL/cairo frames.1819## The contract: frames are pure functions of t2021- A shot is `fn(t)`. Same `t`, same pixels. No counters, no state carried between22 frames, no integrated physics, no unseeded random. Then frames can23 render out of order, split across parallel workers, and resume after a crash.24- Stable per-object values come from a hash of an index. Deliberate wobble25 ("boil") comes from a seed that changes on a fixed clock (the kit uses 12 Hz,26 each drawing held two frames).27- Reseed per element. A moving element consumes a variable amount of randomness;28 without its own seed it shifts the stream for everything drawn after it and29 the still parts jitter every frame.3031## Procedure32331. **Storyboard in writing, before any scene code.** One logline (wants ___, but34 ___, so ___), a small palette with a colour arc, a motif that pays off, and35 the emotion keys across the whole film. Then per shot: time span, transition36 in, the event, the reaction, the camera, and the **reads**.372. **Write the reads.** A read is one thing the viewer must understand, with a38 start and end time. Each needs time for the eye to find it, to understand it,39 and to register before the next starts. No two important reads overlap. If40 they do not fit the shot, lengthen the shot or cut a read. Timing is where41 generated animation fails most: everything at one brisk speed, events stacked,42 moments gone before they land.433. **Check the storyboard:** an event in every shot, a transition at every seam44 (including in and out of the film), no text, the ending rhymes with the opening.45 If a person is waiting, show them the storyboard before building.464. **Block key poses as stills** at each shot's storytelling moments. If the47 poses do not read as stills, motion will not save them.485. **Add motion between poses**, one shot at a time, in order: anticipation49 before big moves, slow in/out instead of raw lerp, arcs, overlapping action50 (eyes lead, body follows, appendages settle last), no twinning (offset left51 and right, offset characters' phases), exaggeration.526. **Review loop** (below) on every shot. Fix, look again.537. **Render** the full film; verify with `ffprobe` that duration and frame count54 match the config.5556## Review loop5758You cannot see motion by reading code. Render images and open them with Read.5960| view | what it shows | catches |61|---|---|---|62| contact sheet | first, middle, last frame of every shot | missing events, small or lost characters, dead stretches |63| fixed-step sheet (every 0.1–0.15 s) | one shot, read in order | timing: where is the eye now, does the viewer get it yet |64| frame strip | every frame of a 0.5 s stretch | pops, snaps, missing anticipation, boil jitter on still parts |65| crop | full-res detail | faces, contacts (feet on ground, props in hands), muddy glows |66| crop following a world point | the same detail through a moving camera | contacts on camera moves |6768Count frames per read (24 = 1 s). A read that gets a few frames, or shares its69frames with another read, will be missed. Budget: one sheet per shot, one strip70per key motion and per transition, one crop per face that carries the story.7172## Rules from the kit's guide7374Defaults, overridden by whatever the person asks for.7576- **No text.** No captions, labels, signs, or words on screens. Reactions are77 painted marks (`!`, `?`, sweat, hearts, a bulb). A sign that restates the story78 is the classic failure.79- **Flat 2D, no projected 3D.** Turns go through drawn key views (front, 3/4,80 side, back 3/4, back) with smears. Depth from overlap, scale and paler, bluer81 colour.82- **Nothing still.** Idle motion per emotion, drifting cameras, swaying grass. A83 frozen frame reads as a bug.84- **Faces act, never snap.** Mood changes go squint, swap under the squint, take,85 overshoot, settle.86- **One beat.** A single BPM drives idles and bounces even with no music.87- **No pure black or white.** Additive light for glows: pigment-mixing brushes88 turn yellow-over-blue green.8990## The ClaudeAnimationBase route9192`https://github.com/JohnHeibel/ClaudeAnimationBase`, MIT, verified at commit93`0ac8bf2` (2026-09-24). Its `ANIMATION_GUIDE.md` (36 KB) is the full API: read it94whole before drawing. `render.mjs` provides the review views as flags95(`--sheet=`, `--strip=a:b`, `--crop=x,y,w,h`, `--crop-at=`, `--stills=`, `--clip`,96`--frames --workers=N` + `--encode`).9798Recipe for a CCotw container, verified 2026-10-25 (4 CPUs, no GPU, Chromium at99`/opt/pw-browsers/chromium-*/chrome-linux64/chrome`):100101```bash102SCRATCH=/path/outside/the/checkout # the session scratchpad103CHROME=$(ls -d /opt/pw-browsers/chromium-*/chrome-linux64/chrome | tail -1)104git clone --depth 1 https://github.com/JohnHeibel/ClaudeAnimationBase /tmp/jail/cab105# deps from the registry, outside the checkout, no install scripts; versions from package-lock.json106mkdir -p "$SCRATCH/cabdeps" && cd "$SCRATCH/cabdeps" && npm init -y >/dev/null \107 && npm install --ignore-scripts p5@2.3.3 p5.brush@2.2.3 puppeteer-core@25.11.0108cp -r "$SCRATCH/cabdeps/node_modules" /tmp/jail/cab/109sed -i '/fonts.googleapis.com/d' /tmp/jail/cab/studio.html # only letter() uses it110sed -i "s/{ waitUntil: 'networkidle0' }/{ waitUntil: 'networkidle0', timeout: 0 }/; s/{ timeout: 60000 }/{ timeout: 0 }/" /tmp/jail/cab/render.mjs111chown -R nobody:nogroup /tmp/jail/cab112sh scripts/jail.sh -C /tmp/jail/cab -- node render.mjs --soft-gl \113 --chrome="$CHROME" \114 --sheet=0.5,2,4,6,8,10 --cols=3 --w=480 --out=out/sheet.jpg115```116117In claude-workspace, run the kit only inside `scripts/jail.sh` (hub rule for118code nobody here wrote). Elsewhere, drop the jail prefix.119120**Cost.** Under SwiftShader the demo's six-frame sheet took 0.3, 0.2, 36, 47, 40121and 42 s per frame. At ~40 s, the 11 s demo (264 frames) is about 3 hours on one122worker. Before a full render, either ask the scene to avoid p5.brush watercolour123`fill` (the kit's README suggests this for machines without a GPU), split across124`--frames --workers=N` and run it as a background job, or render on a GPU host125(`--gpu-angle=gl-egl|vulkan`). The review loop stays cheap: sheets and strips126render a handful of frames.127128## Failure signals129130| signal | cause | fix |131|---|---|---|132| `connect ENETUNREACH 127.0.0.1:<port>` from puppeteer | network namespace with `lo` down | claude-workspace `scripts/jail.sh` raises `lo` since 711fac1; pull the hub |133| `Navigation timeout of 30000 ms exceeded`, with `ERR_INTERNET_DISCONNECTED` | page waits on Google Fonts with no network | delete the fonts link |134| same timeout, no failed request | p5.brush init takes ~20 s under SwiftShader | `timeout: 0` on `goto` and `waitForFunction` |135| `Failed to construct 'OffscreenCanvas': Value is not of type 'unsigned long'` | a NaN in a point list; the stack points at the scene, not the NaN | guard degenerate geometry (`Math.acos` of a ratio > 1) |136| an outline collapses to a dot at zoom ≥ 2 | stroke drawn far from the origin | draw long edges as `inkLine`s no bigger than the canvas |137| still parts flicker in a strip | shared random stream behind a moving element | `boilSeed(key)` before each element |138| five `WebGL: INVALID_OPERATION ... not from the associated program` warnings | p5.brush, once per page | harmless; any other page error is real |139140## Verification141142Open every sheet and strip with Read and look before calling a shot done. For the143final file, this must match the config's duration and fps:144145```bash146ffprobe -v error -show_entries format=duration:stream=nb_frames,r_frame_rate -of default=nw=1 out/video.mp4147```148 Report149the route used, the render time per frame, and anything the review loop found150that you did not fix.