Producing Stickman Animation
Render with Python + Pillow/NumPy (frames) + edge-tts (Russian voice) + ffmpeg (mux). Don't generate still images and slideshow them: every frame is drawn from a skeleton, so motion is real.
Bashpip install pillow numpy edge-tts # ffmpeg must be installed (check: ffmpeg -version) mkdir -p build/frames build/audio build/scenes
Minimal character rig (define ONCE in rig.py, reuse everywhere so appearance never drifts):
Python# rig.py import math from PIL import Image, ImageDraw, ImageFilter W, H, FPS = 1080, 1920, 24 CHARS = { "max": dict(body=(245,245,245), eye=(20,20,20), glow=None), "nol": dict(body=(8,8,8), eye=(255,30,30), glow=(255,0,0)), "creator": dict(body=(250,250,250), eye=(255,200,40), glow=(255,190,0)), } def lerp(a, b, t): return a + (b - a) * t def ease(t): return t*t*(3-2*t) # smoothstep def pose_walk(t): s = math.sin(t * 2 * math.pi) return dict(torso=0, head=0, l_arm=-35*s, r_arm=35*s, l_leg=30*s, r_leg=-30*s, bob=abs(s)*6) def draw_stick(img, name, x, y, pose, scale=1.0, flip=False, alpha=255): """x,y = hip position. Angles in degrees from straight down.""" c = CHARS[name]; d = ImageDraw.Draw(img, "RGBA") k = scale * (-1 if flip else 1) def pt(px, py): return (x + px * k, y + py * scale) def limb(origin, ang, length): a = math.radians(ang) return (origin[0] + math.sin(a)*length*k, origin[1] + math.cos(a)*length*scale) hip = pt(0, -pose.get("bob", 0)) neck = (hip[0] + math.sin(math.radians(pose["torso"]))*110*k, hip[1] - math.cos(math.radians(pose["torso"]))*110*scale) head = (neck[0], neck[1] - 42*scale) col = c["body"] + (alpha,) w = int(9*scale) d.line([hip, neck], fill=col, width=w) for ang in (pose["l_arm"], pose["r_arm"]): elbow = limb(neck, ang, 55); hand = limb(elbow, ang*0.6, 50) d.line([neck, elbow, hand], fill=col, width=w, joint="curve") for ang in (pose["l_leg"], pose["r_leg"]): knee = limb(hip, ang, 65); foot = limb(knee, ang*0.4, 65) d.line([hip, knee, foot], fill=col, width=w, joint="curve") r = 34*scale d.ellipse([head[0]-r, head[1]-r, head[0]+r, head[1]+r], fill=col) # eyes ex = 12*scale*(1 if not flip else -1) for sx in (-1, 1): ep = (head[0] + sx*ex*0.9 + 6*k, head[1] - 3*scale) er = 6*scale d.ellipse([ep[0]-er, ep[1]-er, ep[0]+er, ep[1]+er], fill=c["eye"]+(alpha,)) if c["glow"]: glow_eyes(img, head, c["glow"], scale) return head def glow_eyes(img, head, color, scale): layer = Image.new("RGBA", img.size, (0,0,0,0)) ld = ImageDraw.Draw(layer) for sx in (-1, 1): ex, ey = head[0] + sx*11*scale, head[1] - 3*scale ld.ellipse([ex-16*scale, ey-16*scale, ex+16*scale, ey+16*scale], fill=color+(200,)) layer = layer.filter(ImageFilter.GaussianBlur(14*scale)) img.alpha_composite(layer)
Render a scene to frames, then encode:
Bashffmpeg -y -framerate 24 -i build/frames/s01_%04d.png -c:v libx264 -pix_fmt yuv420p build/scenes/s01.mp4
Progress:
- [ ] 1. Lock the style bible (palette, rig, fonts, resolution)
- [ ] 2. Write the shot list (scenes -> shots, with duration, camera, SFX, lines)
- [ ] 3. Generate Russian voiceover per line (measure real durations)
- [ ] 4. Build reusable layers: backgrounds, props, rig, effects
- [ ] 5. Render each scene to frames, time-locked to audio durations
- [ ] 6. Encode scene MP4s, build subtitles, mix audio per scene
- [ ] 7. Concatenate scenes, final mux, verify specs
- [ ] 8. QA pass (consistency, sync, loudness, duration 120-180 s)
1. Style bible
- Canvas 1080x1920, 24 fps, background near-black (
#07080d) with blue-grey fog and a faint film-grain overlay. - Palette: white
#f5f5f5, black#080808, red glow#ff1e1e, gold glow#ffbe00, cold blue ambient#1b2a4a. - Stick width 9 px at scale 1.0. Head radius 34 px. Never change proportions between scenes: all characters import
rig.py. - Font for subtitles/titles: a Cyrillic-capable font (DejaVu Sans Bold, or Montserrat/PT Sans if installed). Verify Cyrillic renders before rendering anything.
2. Shot list
Plan duration up front. Target ~150 s:
| Scene | Content | Target |
|---|---|---|
| 1 | Empty city, flyover, posters, Nol silhouette | 22 s |
| 2 | Max walking, lamps die, rooftop figure | 18 s |
| 3 | Phone message, photo from behind, whisper | 22 s |
| 4 | Old photo, back-side text | 16 s |
| 5 | Lab, "УДАЛЁН" photos, Nol reveal dialogue | 32 s |
| 6 | Screen text, portal, Creator | 20 s |
| 7 | Finale, symbol, white flash, title card | 20 s |
Each shot = camera move + character action + SFX cue + subtitle text. Record these in a shots.json (scene, start, duration, camera keyframes, lines).
3. Voiceover (Russian)
Use distinct voices so characters are readable by ear:
Python# voices.py import asyncio, edge_tts VOICES = { "narrator": ("ru-RU-DmitryNeural", "-5%", "-2Hz"), "max": ("ru-RU-DmitryNeural", "+8%", "+4Hz"), "nol": ("ru-RU-DmitryNeural", "-18%", "-14Hz"), "creator": ("ru-RU-SvetlanaNeural", "-15%", "-12Hz"), } async def tts(who, text, out): v, rate, pitch = VOICES[who] await edge_tts.Communicate(text, v, rate=rate, pitch=pitch).save(out)
Then run ffprobe -v error -show_entries format=duration -of csv=p=0 file.mp3 on every line and store the real duration. Scene length = sum of line durations + pauses, not the other way around. Add a low-pass + light reverb on Nol and Creator for menace:
Bashffmpeg -i nol.mp3 -af "lowpass=f=3200,aecho=0.8:0.7:60:0.3,volume=1.2" nol_fx.mp3
If edge-tts is unavailable offline, fall back to pyttsx3/espeak-ng -v ru, and say so in the summary.
4. Reusable layers
- City background: layered parallax silhouettes (3 depths) as pre-rendered tall PNGs; far layer moves slowest. Add lit windows that flicker.
- Posters: small rectangles with text "ПРОПАЛ" and a mini stick icon; slight sway via sine on rotation.
- Fog: two scrolling noise layers at 8% and 14% opacity.
- Grain + vignette: a single post-pass applied to every frame (see Camera and FX).
- Lamps: state machine
on -> flicker (6-10 frames random) -> off; light cone drawn as a blurred polygon, removed when off.
5. Render loop pattern
Every scene is a function render(t) -> Image with t in seconds. Compose back to front: background -> props -> characters -> glow/FX -> camera transform -> vignette/grain -> subtitle.
Pythondef render_scene(scene_fn, duration, name): n = int(duration * FPS) for i in range(n): img = scene_fn(i / FPS) img.convert("RGB").save(f"build/frames/{name}_{i:04d}.png")
Render at full 1080x1920 directly. Use multiprocessing.Pool over frame indices; frames are independent, so this scales with CPU cores.
6. Subtitles
Burn in during rendering (not as a separate track) so they are guaranteed visible in any player:
- Bottom third, centered, max 2 lines, max ~28 characters per line (vertical format).
- White text, 4 px black stroke, semi-transparent dark box at 55% opacity.
- Narrator in light grey italic style; Max white; Nol red-tinted
#ff5a5a; Creator gold#ffd24a. Prefix with speaker only when ambiguous. - Also export
final.srtas a bonus.
7. Audio mix and final mux
Build per scene: voice + sfx + music, then concat. Target levels: voice -14 LUFS peak-clear, music -28 to -22 dB under voice (duck with sidechain), SFX -18 dB.
Bash# duck music under voice ffmpeg -i music.wav -i voice.wav -filter_complex \ "[0][1]sidechaincompress=threshold=0.04:ratio=8:attack=20:release=400[m];[m][1]amix=inputs=2:duration=longest" mix.wav # final ffmpeg -y -i video_all.mp4 -i mix_all.wav -c:v copy -c:a aac -b:a 192k -shortest STICKMAN_LAST.mp4
Music and SFX are synthesized, not downloaded (avoids licensing issues and offline failures):
Python# synth.py (numpy -> wav) import numpy as np, wave SR = 44100 def save(path, x): x = np.int16(np.clip(x, -1, 1) * 32767) with wave.open(path, "wb") as w: w.setnchannels(1); w.setsampwidth(2); w.setframerate(SR); w.writeframes(x.tobytes()) def drone(dur, f0=55): t = np.linspace(0, dur, int(SR*dur), endpoint=False) x = 0.5*np.sin(2*np.pi*f0*t) + 0.3*np.sin(2*np.pi*f0*1.5*t + 0.5*np.sin(2*np.pi*0.1*t)) x += 0.15*np.sin(2*np.pi*f0*2.01*t) return x * (0.6 + 0.4*np.sin(2*np.pi*0.07*t)) # slow swell def heartbeat(dur, bpm=60): out = np.zeros(int(SR*dur)) for beat in np.arange(0, dur, 60/bpm): for off, amp in ((0, 1.0), (0.22, 0.6)): i = int((beat+off)*SR); n = int(0.12*SR) if i+n < len(out): tt = np.arange(n)/SR out[i:i+n] += amp*np.sin(2*np.pi*48*tt)*np.exp(-tt*28) return out def whoosh(dur=0.8): n = int(SR*dur); noise = np.random.randn(n) env = np.sin(np.linspace(0, np.pi, n))**2 return noise*env*0.4 # then lowpass sweep via ffmpeg if desired def impact(dur=1.2): t = np.linspace(0, dur, int(SR*dur)) return np.sin(2*np.pi*(90*np.exp(-t*5))*t)*np.exp(-t*4) def glitch(dur=0.3): n = int(SR*dur); x = np.sign(np.random.randn(n)) * (np.random.rand(n) > 0.6) return x*0.3
SFX cue map: flyover = drone + wind noise; lamp off = electrical buzz + impact low; message = phone buzz (two 180 Hz pulses) + glitch; "оборачивайся" = heartbeat ramps from 60 to 110 bpm; portal = rising sweep 40 -> 400 Hz + choir pad (stacked detuned sines); white flash = riser then total silence for 1.0 s before Creator's final line.
Implement the camera as a transform of the composed world image (crop + resize), driven by keyframes with easing:
Pythondef camera(img, cx, cy, zoom, rot=0): w, h = int(W/zoom), int(H/zoom) box = (int(cx-w/2), int(cy-h/2), int(cx+w/2), int(cy+h/2)) out = img.crop(box).resize((W, H), Image.LANCZOS) return out.rotate(rot, resample=Image.BICUBIC) if rot else out
Render the world on an oversized canvas (e.g., 1400x2400) so pans and zooms never reveal edges.
Required motion vocabulary (use varied shots, never a static frame longer than ~2 s):
- Flyover: horizontal pan 400 px over 8 s with parallax; slight downward tilt.
- Push-in: zoom 1.0 -> 1.25 on Max's face when he sees the message.
- Whip pan: 6-frame fast pan with motion blur (average 3 offset copies).
- Handheld shake: sum of two sines (3 Hz, 7 Hz), amplitude 4-8 px on tension beats.
- Dolly zoom on "Ты наконец-то меня вспомнил": zoom in while background scales out.
- Body acting (no faces): fear = torso leans back, arms rise, head shakes; shock = freeze 6 frames then step back; resolve = fists clench, torso straightens, chin up; Nol menace = slow still posture with head tilt.
FX stack (applied last, every frame): vignette (radial multiply 0.55 at corners), film grain (gaussian sigma 6, new each frame), chromatic aberration (shift R and B channels +/-2 px, +/-8 px during glitch beats), glow bloom on red/gold elements, scanline flicker only inside lab/phone/screen shots.
- City: posters read "ПРОПАЛ" with stick icons; narrator timing ends exactly when Nol appears on a rooftop CCTV frame (add a green-tinted CCTV overlay with "REC 847" timestamp, then a glitch cut). Nol's red eyes are the first saturated color in the film.
- Max walks: walk cycle at 1.2 cycles/sec, camera follows from behind at low angle. Lamps die in sequence down the street (staggered 0.4 s), ambient drops to near-black, Max's white body becomes the only light source. Nol on rooftop: red eyes appear first, then body fades in from the dark. Cut: he is gone, only a red afterimage.
- Message: phone UI is drawn, not an image: dark rounded rect, bright text "НЕ ОБОРАЧИВАЙСЯ" with typewriter reveal. The "photo from behind" is a mini-render of Max seen from the back, then the real camera pushes in on the same view. Voice from behind is whisper-processed (high-pass + reverb), panned slightly right. Max turns slowly (flip over 20 frames), empty room, lamp swinging.
- Photo: close-up, photo flips (horizontal scale -1 -> 1 with easing); the back shows handwriting font, text appears stroke by stroke.
- Lab: cold white-green lighting, grid floor, walls covered in hundreds of tiny photo rectangles with red "УДАЛЁН" stamps (generate procedurally, slow parallax). Nol steps into frame from the left; Max backs up. Nol's exposition ("весь мир эксперимент") is visualized: background dissolves to a wireframe city, then to code rain.
- Creator: screen text with glitch scramble reveal; portal = rotating concentric rings with additive blending and gold particle spray; Creator descends slowly, stays perfectly symmetrical and still (contrast with the jittery others).
- Finale: palm symbol drawn as an animated glowing glyph (stroke draw-on over 12 frames), city-wide white flash (full-frame white 4 frames with blur ramp), Creator line over silence, cut to black for 1.5 s, then title card with slow letter-spacing expansion, then "ПРОДОЛЖЕНИЕ СЛЕДУЕТ…" fade in.
Example 1: Input: Narrator line "847 дней назад в нашем городе начали исчезать люди…" measured at 6.8 s, followed by 0.6 s pause. Output: Shot 1.1 runs 7.4 s: camera pans 400 px right with 3-layer parallax; subtitle splits into 2 chunks (0-3.9 s, 3.9-6.8 s); drone SFX at -20 dB; fade-in from black over first 12 frames.
Example 2:
Input: "Лампы выключаются, Макс останавливается."
Output: Walk cycle blends to idle via lerp over 8 frames; lamps go off at t=2.0, 2.4, 2.8, 3.2 s each with 6-frame flicker; background luminance eases to 15%; electrical buzz SFX per lamp; camera zooms 1.0 -> 1.12.
Example 3: Input: Dialogue "Я — это ты." (Nol) / "Почему мы одинаковые?!" (Max). Output: Nol's audio gets low-pass + echo; subtitle in red-tinted color; during Nol's line the camera does a slow push on him, during Max's line cuts to Max with 3 px handheld shake and rear-arm flail pose; 0.4 s of room tone silence between lines.
- Time-lock to audio: generate voice first, measure durations, then derive scene lengths. Hitting 2-3 minutes is arithmetic: sum all lines + pauses + non-dialogue beats; adjust beats, not speech speed.
- One rig, one palette: all characters import from
rig.py; change body style once and every scene updates. Check consistency by exporting a contact sheet (one frame per scene) and comparing. - Render and review per scene (
s01.mp4...s07.mp4) before the full concat; fix one scene without re-rendering all. - Test cheap first: render at 540x960, 12 fps for sync and timing review, then do the final 1080x1920, 24 fps pass.
- Ease everything: use
ease()on every transition; linear motion reads as robotic. - Contrast for horror: long quiet holds before reveals; silence is an SFX. Make the Creator's motion calmer than everyone else's.
- Always verify the output:
Expect 1080, 1920, 24/1, h264 + aac, duration 120-180 s.Bashffprobe -v error -show_entries stream=width,height,r_frame_rate,codec_name -show_entries format=duration -of default=nw=1 STICKMAN_LAST.mp4 - If the full render is too slow or an environment limit is hit, deliver the 7 scene MP4s plus a
concat.txtand the exactffmpeg -f concat -safe 0 -i concat.txt -c copy final.mp4command, and state what was and wasn't completed.
- Slideshow trap: panning a single static picture isn't animation. Characters must change pose between frames (walk cycle, lean, turn, gestures).
- Character drift: redrawing characters ad hoc per scene changes proportions and eye colors. Never inline-draw a stickman outside
draw_stick. - Missing Cyrillic glyphs: default PIL font renders boxes. Load a TTF with
ImageFont.truetype(path, size)and test with "ЁЙЩЪЫ" first. - Audio/video drift: don't guess durations. Use
ffprobevalues, and mux with-shortestonly after confirming both streams are equal length. - Odd resolution: non-even dimensions or
yuv444break players. Always-pix_fmt yuv420p, 1080x1920. - Edge reveal on camera moves: rendering at exactly 1080x1920 then zooming out shows empty borders. Render oversized world, crop down.
- Wall of subtitles: more than 2 lines or tiny text is unreadable on phones. Split long lines into timed chunks.
- Overdone effects: constant shake/glitch exhausts tension. Reserve strong FX for the 4-5 key beats (lamp blackout, "не оборачивайся", Nol reveal, portal, white flash).
- Muddy mix: music at voice level hides dialogue. Duck music under speech and keep the drone mostly sub-bass.
- Silent failures: if edge-tts, ffmpeg, or a font is missing, say so and use the documented fallback instead of delivering a video without voice or subtitles unannounced.
- Single giant script: keep
rig.py,voices.py,synth.py,scenes/sNN.py,assemble.shseparate so each scene can be re-rendered independently (if this skill grows past ~500 lines, split rig, audio and scene notes into separate reference files).