Paper-cutout stop-motion animation
Reference implementation (copy, then change the world / timeline / text):
| File | What it is |
|---|---|
paper_cutout/papercut.py | engine: shapes, hand-cut edges, paper texture, shadows, labels, camera, encoder |
paper_cutout/puppet.py | realistic human puppet (front view): FK skeleton + ~45 paper pieces, poses, blinking |
paper_cutout/rain_story.py | 31 s Thai water-cycle story: title -> evaporation -> condensation -> rain (kid opens umbrella) -> river run-off -> rainbow |
Run with python3 rain_story.py out.mp4, or --preview DIR to dump 12 stills first.
Full render ≈ 1.5 s per unique frame (≈ 9 min for 31 s at 12 poses/s).
The look, and where each part comes from
- Everything is a
piece= list of closed polygons + colour +z. Painted in list order (first = bottom). Union shapes (cloud = circles + a rounded rect) are just several polygons in one piece, so they share one outline, one shadow, one colour. - Hand-cut edge (
cut): resample the outline every ~6 px and offset it along the normal by a few low-frequency sines + tiny noise, seeded by the piece name, so the wobble is stable across frames (it's the same sheet). Userough=Falsefor tiny punched dots (eyes, mouths). - Shadow: mask shifted down-right by
z*(0.55, 1.0), Gaussian blur1.5+0.9z, multiply by1-0.38*s. Biggerz= sheet lifted on foam tape. Background bands z 0-3, scenery 4-8, characters 4-7, clouds 12, HUD 12-14. - White cut margin (
border=px): polygon drawn again with a thick outline in cream under the colour — the "cut around a printed sticker" look. Use on hero objects (sun, cloud, umbrella, drops, river), not on everything. - Paper texture: one 2x-canvas multiplicative map (mottling + grain +
short fibre strokes) sampled at a per-piece offset so neighbours don't
share grain.
shade>0darkens the inner edge (slightly curled paper). - Masks are 2x supersampled and drawn only in each piece's bbox crop — that's what keeps it fast at full 1080x1920.
- Stop-motion:
encoderenders atANIM_FPS=12and holds each pose for 2 frames;boilre-places each piece by ±0.7 px / ±0.25° per pose; global light flicker ±1 %, warm vignette.
Building scenes
- Shape helpers:
circle, ellipse(…, a0, a1)(half-ellipse = umbrella/hair),rect, rrect, band(rainbow stripes / arcs),wave_strip(layered sea/sky, animatephasein opposite directions per layer),ribbon(path, w, taper)(river, steam curls, heat waves, stick),teardrop, star_burst(sun rays, grass tufts),xform(pts, tx, ty, rot, s, pivot). - People: use
puppet.py, not blobs.P = puppet.pose(x, y, height), set fields,pieces, J = puppet.draw("kid", P, fi). What makes it read as a real person rather than a chibi:- proportions ≈ 8-year-old: head ≈ 1/5.5 of height, legs ≈ half;
- two-segment limbs (
capsuletapered thigh/shin, upper arm/forearm) with elbows and knees; angles 0 = down, 90 = screen right, 180 = up; - hands = palm + finger mitten + darker thumb; socks, shoes with a white sole;
- clothes as separate sheets: shorts with two legs, T-shirt, sleeves over the upper arm with a darker cuff, collar ribbon, pocket;
- egg-shaped face (narrow chin), ears with inner ear, back hair + jagged fringe + shine, darker "shadow paper" under the fringe and the chin;
- eyes = white + iris + pupil + glint + lash line; eyebrows; nose; blush;
mouths
smile | open | o | flat | frown; - life:
breath,sway,lean, weight shift on the legs,blink_at(t),look(pupils),face_up(features slide up when looking up),head_tilt,brows(-1 worried .. +1 happy). - Props in the hand: use
J["rwr"] + puppet.d(J["rfdir"])*11(palm centre) and insert the prop beforekid.rhandso the fingers wrap over it. - Layer order matters for the face: face -> shadow paper -> eyes/brows/ nose/mouth -> fringe. A shadow piece added after the eyes hides them.
- Growing things: grow scale (cloud), sweep angle (rainbow
banda1), truncate a path (riverribbonover the first n samples). - Colour changes over time with
lerp_col(sky and cloud greying in rain). - Camera (
Camera.apply(piece, par)): pan/zoom per beat from a key list;par< 1 for far layers gives parallax; HUD labels skip the camera. - Text =
label(): a cream paper strip with antialiased Loma Bold text, rotated a few degrees; headline drops in withback_out, flies off tilted at the end of the beat; caption rises from the bottom. Loma has Thai; keep captions to 2 short lines (≈ 20 Thai chars) at 40 px, headlines 50-78 px.
Gotchas
piecenames seed the cut shape and the boil: give every piece a unique, stable name (drop{j}, not a random one) or edges will flicker.- Teardrop / thin ribbons with width < 4 px vanish after supersampling — fade
them out by scaling width to ~0 and then skip (
if sz > 0.05). - Keep particles born after their start time (rain uses a phase check) or the first frame of a beat shows them mid-air.
- A flat polygon bottom edge that meets another layer shows a hard shelf; extend layers past each other (sea starts at x=150, under the mountain).
- Check the contact sheet before a full render:
ffmpeg -pattern_type glob -i 'dir/f_*.png' -vf "scale=270:-1,tile=6x2" sheet.png. - Audio: none in the reference; mux narration with
encode(..., audio=wav)(seetools/tts_omnivoice.pyfor Thai voice-over).