An AI skill that turns books into animated, narrated, interactive web experiences
Paper puppets and the stop-motion look
The actors are paper puppets drawn in code: pieces of coloured paper pinned at the joints, moved a little each frame, like a cut-out film shot by hand. A pose is only a set of numbers, so any action the story needs (ducking, swinging an axe, diving through a window, shoving a thought bubble) costs a few lines, never a new drawing, and a puppet looks the same in every shot. The kit is in assets/templates/picture-book/ (paper.js, cast.js, shared.js, chapter.html); new_book.py picture copies it into site/<book>/lib/ and the first episode folder.
The kit's cast.js holds three kinds of puppet, all on paper.js, each with a working example; its header lists every pose key, and a book keeps the kinds its story needs:
- Round-headed figures that face us, in the spirit of South Park (Joke Collection):
kidPuppet; add a character by copying an entry ofSHAPES. Quickest to build and to act with. - Storybook figures seen mostly in profile, a side set and a front set of pieces per figure (Little Red Riding Hood: Red, Mother, Grandma, the woodcutter, the wolf):
figurePuppet, a child in a coat and a hat whose colours make other characters, on the sharedpuppet()andcommon(). Beyond the common keys it can look (look, the pupils), worry or frown (brow), blink (shut), bend at the waist (lean), duck or bend to pick something up with the feet kept on the ground (crouch, the far armfua/ffa), take its hat off (hat; the hair is drawn under the hat, so the head is never bald) and hold a thing upright in its hand (hold). - Four-legged animals in profile (The Little Horse Crosses the River: the horses, the water buffalo):
beast(), a two-bone leg rig whose walk and trot come from the distance covered, withcatPuppetas the example; another animal is another drawing and itsgeo(the pins and leg lengths), as Little Horse'slib/cast.jsshows for a foal, a mare and a buffalo.
Pick with the user. The two reference books' own cast.js files show the second and third kinds carried through a whole episode (site/little-red-riding-hood/ and site/little-horse/ in the Papermorph repository).
Contents
- What makes it read as stop motion
- Acting
- Cameras
- Performance
- Seeing your own work
What makes it read as stop motion
- Twelve frames a second, on twos.
stopClocksamples every movement into steps; the slight jerk is the style, not a defect. Big moves still ease in and out across the steps. It draws through the beat's 0.6 s hold after the clip too (clockRun's tail: core/engine.md), so a scene's pose functions run to aboutD + 0.6and the frame the next scene cuts from is still alive. - The animator's hand. Each frame nudges every puppet by a tiny random amount (
jit(frame, k), the same nudge for the same frame, so pause, seek and?beat=N&t=Sshow exactly what playback shows), and the picture flickers faintly. At full strength it reads as shaking; about a third of a pixel, held for two frames, felt hand-made. - Paper you can feel. Grain, torn edges and a soft drop shadow on every piece (the
#paperfilter), brass pins at the joints, and a soft contact shadow under the feet so a puppet stands on the ground, leaning the way the set's light falls. - Replacement, not morphing. Mouths are swapped shapes timed to the words; a blink is two closed frames; a door opens through a few boards of different widths; a bitten bun is a different picture.
Acting
- Nobody freezes. Whoever speaks lip-syncs; everyone blinks at their own moments, never in unison; listeners' eyes follow the speaker; reactions get a small head turn or a lid drop. A crowd glances about on its own and turns as one only when something happens (a staggered snap, a frame or two apart).
- Turning round. A round-headed puppet turns by sliding its face across the head (
look), as South Park does. A storybook figure turns as a whole-body swap: tweenturnfrom 1 to −1 and the side view squashes, the whole front figure shows while|turn|is under .55, and it comes out mirrored;head: 'F'shows the front figure outright. A front head on a side body looked wrong every time. A four-legged animal has no front figure: it squashes as a card turned over on the table, never thinner than a third of its width. On Little Horse reviewers still flagged such turns inside medium shots, and a turn on a cut read best (the next shot simply has the otherturn); when it has to happen on screen,flipTurn(q, t0, 1, -1)turns it over in four frames on twos, in a wide shot. - Feet don't slide. A walk keeps the planted foot still while the hip rides over it, and the puppet's x comes from the distance the walk returns (
d, in the puppet's units, times its scale), never from a separate tween. A profile figure uses the compass stepwalk()(paper.js):dgrows as it goes forward, so one built facing right goesx0 + d·sand a mirrored onex0 − d·s; itsnear/farangles go to the near and far leg as they are. A figure that faces us while crossing the frame side-steps withspStep()(cast.js): step out, close, both legs leaning outward,x0 ± d·sby direction, a step every 2/3 s by default (keep the period a whole number of 1/3 s, so a drawn frame lands on the widest stance and only one foot moves at a time; the template'sscene1.jswalks the kid this way);walk()'s angles on a front figure cross the ankles every other step.spWalk()is the show's quick shuffle on the spot, for short moves where nobody watches the feet. A storybook figure's feet are at y 170 (hipOn(gy, s)puts them on the ground atgy);walker(x0, s, opts, dir, steps)walks it and stops cleanly, the lifted foot set down beside the other, andbigStep(u)is one deliberate step (off a path onto the grass). A four-legged animal takes the distance itself:route(q, [[t, x], …], s)gives itsx, the distancedforpose({ d })andstandfor setting off and stopping, so its feet stay planted at any speed (gait: 'walk'one foot at a time,'trot'in diagonal pairs). Runs are on twos with a bigger bob. Check a walk on a strip at 1/12 s: the planted shoe should not move between frames. - Hands touch what they hold. A held prop belongs to the hand's piece (
holdis the screen-right hand, onarmR;holdLthe screen-left one, onarmL); when something is handed over, both hands meet it. To put a hand on a point, ask the puppet:aim(pose, 'R', [x, y])gives thearmR/reachRvalues for that pose (spread straight into the pose, or tweenarmandreachfrom rest for a gesture), andpoint(pose, 'mouth' | 'chin' | 'capL' | 'capR')says where that place of the face is in the same pose, so a cup, a scratch or a chin on a hand lands right through a lean, a head tilt or a seat. A held thing hangs from the mitten's centre, so aim at the point less the thing's own offset (a cup's rim above the hand). A hand raised above the chin and in towards the face (a cup at the lips, a hand on the chin, a reach across the head) is drawn in front of the head; an arm raised out to the side (a wave, a cheer) stays behind it, and so does a hand at its own side of the head, so a scratch there wantsarmFrontR: true(orarmFrontL;falsekeeps a hand behind).farabove 1.25 means the point is out of reach: lean in, step closer or move the point. A storybook figure'sholdputs a thing in its near hand and its front right hand at once, kept upright through any bend. A four-legged animal answersat(name)with a drawn point of the current pose ('mouth','eye', a hip, knee or foot such as'nfk'or'nfHoof', and any mark its drawing places), so on Little Horse the sack went from Mother's mouth onto the foal's back (at('mouth'),at('back')) and the ripples sat at the buffalo's hooves (at('nfHoof')). Look at a full-size still of the moment the hand arrives. - Sitting reads from the knees. A figure that faces us looks seated only when its thighs come towards us:
sit: Hsits on a seat H units above the feet (up to the shape'slegH − 12, 34 on the kid; a higher seat counts as that), the lap and knees towards us and the shins down to the ground at the pose'sy.sit: trueonly hides the legs and the shadow, for a seat whose front comes up to the coat (a desk row). A still beside the standing pose should read sitting without the set. - Whatever says where something is follows what is drawn. A helper a scene asks for a position (
point(),aim(), a board's square, the top of a piece the kit adds) works from the same state the drawing uses this frame, a piece being lifted or carried included, and draw order comes from the pose alone, so a seek to any frame shows what playback showed (compare a playback frame with the same?beat=N&t=S). - Things behind things. A counter, a cart, a desk row or a lectern sits on its own layer between puppets, so the person behind shows from the chest up.
cam.stage, where puppets go, is drawn just after one set layer:afternames it, else the set's layer markedstage: trueinsets.js, else its first layer with k 1.stages: [layers]adds a plane after each of those too (cam.stageAt[name]), for things that stand further back than the puppets. On Little Horse the river set needed its puppets in front of the tree and behind the water and the near bank (after: 'tree'), and the ducks swam onstages: ['pond'], in front of the pond's water; on Little Red Riding Hood the house front hides whoever is inside ({ after: 'house', stages: ['inside'] }). When a set always wants the same place, mark that layerstage: trueonce insets.jsrather than passingafterin every scene.
Cameras
paperCam(parent, set, view, { after, stages }) is one camera on one set: layers slide with parallax, to/cut move it on the scene's clock, soft swaps in the blurred copy of the set for close-ups, shake(t0, dur, amp = 10) jolts it (the engine's cam.shake takes the amplitude first), show(layer, on) swaps a layer (rain and snow versions of the same street). A scene can hold several cameras; cut between places by showing one cam.root and hiding the others. Close-ups zoom the same set and blur it, so the speaker stays sharp.
Performance
Paper filters are expensive live, so every finished piece is baked to a bitmap; only what changes every frame (eyes, mouths, brows, fingers) stays live.
- Sets:
bake_sets.py(SVG sketches) orpainted.py(painted pictures). - Puppet and prop pieces:
bake_puppets.pyseeks every episode to its end, in Chromium and Firefox, so each piece is asked for once, and writesimg/puppets/<hash>.webpwithbaked.js. - A series shares one folder for every episode's pieces.
bake_puppets.pyencodes only pieces it has not baked before;--clean(after changing the paper filter itself) re-encodes them all and removes only what no episode asks for any more. Leave the folder to it: a hand-written prune once deleted a published episode's pieces. - Rebake after changing any piece or adding an episode. A piece missing from
baked.jsis baked in the browser and stalls;shot.pysays how many pieces a chapter still bakes live. - Full-frame effects that change every frame (the flicker) live outside the SVG, so the picture isn't redrawn each frame.
Seeing your own work
Use core/review.md's tools on an uncached preview (serve.py); here, strip times are on the beat clock, so a scene's speech starts at its pre, and a joined scene's marks are named clip.mark (strip.py chNN OUT scene1/0.5 --url http://localhost:8765/<book>/); scene1:2..5/0.1@o@c onion-skins one shot with the camera held still, for feet and hands. Look at full-size frames of the key moments (shot.py, beats counted from 0 or named), at each scene's last frame beside the next one's first (shot.py --cuts), at the sounds against the picture (playlog.py), and play the whole episode through once at speed: some faults appear only in continuous playback (a camera layer shown once and never hidden again), not in ?t= jumps.