Building a Deterministic Stick Figure Animation Pipeline with Code
This article explains how to build a deterministic stick figure animation pipeline using code instead of generative video models. It covers a four-layer architecture, an immutable rig baseline, single-joint angle animation with keyframe interpolation, packaging the workflow as a reusable skill, local headless rendering and MP4 export, and a cost comparison showing why code-based animation scales better for high-frequency explainer content. It also outlines when this approach is not the right fit.
1. The Problem: Structural Tension Between Output Volume and Cost in Explainer Videos
Creators producing explainer-style short videos usually face three pressures at once: a limited budget per video, a high publishing frequency, and the need for characters and visuals to stay continuous and consistent across episodes. The traditional approach relies on generative video models. It looks like it removes the barrier to animation production, but in practice it introduces uncertainty into the production stage: the same character drifts in proportion from shot to shot, facial structure breaks down, and motion timing is hard to reproduce. Adjusting a single line of dialogue means resampling and paying again.
More importantly, the cost of a generative approach is tightly coupled to the number of reworks. Change one line of copy and you rerun the generation; the more trial and error, the higher the marginal cost. For teams that publish daily or distribute in multiple languages, this cost structure cannot support production at scale.
Code-driven animation offers a different path: treat the frame as a computable geometric result rather than a probabilistic sampling result. Characters are built from a skeleton and polylines, motion is driven by joint angles, and the frame sequence is determined by a function of time. As long as the parameters are fixed, the output is fixed. Rework involves only code changes and re-rendering, with no sampling fees.
2. Solution Overview: A Deterministic Pipeline Built from Four Layers
A practical code animation pipeline can be split into four layers, each with a single responsibility and a clear boundary:
- Rig baseline layer: defines skeleton proportions, joint hierarchy, default pose, and view parameters as the single global source of truth.
- Motion rules layer: defines a single-angle control model per joint, keyframe interpolation, easing curves, and shot transition rules.
- Rendering and recording layer: draws frame by frame in a browser environment, captures frames in batch through a headless setup, then hands them to a local encoding tool to compose the video.
- Skill packaging layer: bundles the specifications above into a reusable capability package so that AI coding tools can recognize them automatically in a conversation and produce pages and scripts according to the spec, avoiding improvisation.
The relationship between these four layers converges from the bottom up: the lower the layer, the more deterministic; the higher the layer, the more intelligent. Pushing determinism down to the base and keeping flexibility at the top is the fundamental reason the whole approach does not fall apart.
3. Rig Baseline: Why the Mathematical Baseline Must Be Locked First
The most common failure when writing code from scratch is not that the character cannot be drawn, but that proportions differ in every generation round. The cause is the absence of a unified baseline: the model reimagines the character each time.
The fix is to establish an immutable rig description, for example a configuration that fixes bone lengths, joint hierarchy, and the default view:
// Rig baseline: single global source of truth, no motion may modify itconst RIG = {bone: { torso: 120, upperArm: 70, foreArm: 65, thigh: 85, shin: 80 },joint: { neck: 0, shoulderL: 0, elbowL: 0, hipL: 0, kneeL: 0 },view: { scale: 1.0, fov: 45, groundY: 520 }};
Once the baseline is locked, the character’s height, limb proportions, and camera perspective stay consistent across every scene and every motion. Changing a motion only changes angles; changing a shot only changes view parameters; body proportions never distort. This is also the technical source of fully stable character consistency: consistency does not come from the model’s memory but from configuration constraints.
4. Motion Rules: Single-Joint Angles and Frame-by-Frame Interpolation
A stick figure’s torso and limbs are essentially polylines, and each joint is controlled by exactly one angle. This makes motion expressible as a single-variable function of time. For per-frame computation, interpolate the keyframe angles first, then derive coordinates forward from the bone lengths in the rig:
function framePose(t) {// 1. Keyframe interpolation (with easing)const a = lerpKeyframes(ACTIONS.walk, t, easeInOutCubic);// 2. Forward kinematics: solve coordinates from angles and bone lengthsconst p = forwardKinematics(RIG, a);// 3. Output the polyline point set to the drawing layerreturn p;}
Three engineering points are worth emphasizing:
- Single control variable: one angle per joint avoids the jitter and mesh clipping caused by coupling multiple parameters.
- Explicit easing curves: motion timing is determined by easing functions rather than randomness, which makes it reproducible and easy to fine-tune.
- Frame rate decoupled from time: driving by timestamp rather than frame count keeps 60 fps output stable and prevents motion speed from changing with machine performance.
5. Skill Packaging: Making AI Coding Tools Follow the Spec
Organizing the rig library, motion rules, and export script into a local capability package is the key step toward stable output. A typical structure looks like this:
stickman-animator/├── SKILL.md # Capability description: when to invoke, inputs/outputs, constraints├── engine.js # Rig rendering and interpolation library└── export-mp4.js # Calls the local browser for frame-by-frame recording and encoding
SKILL.md needs to state three things clearly: the applicable scenario (2D explainer animation), the constraints that must be followed (never modify the rig baseline; always output bilingual Chinese-English subtitle tracks), and the deliverable format (a single-page web page plus an export script). That way, when a new conversation asks for something like “generate a 15-second, three-scene animation,” the AI coding tool loads the spec before acting and produces pages with a unified structure, well-proportioned characters, and stable high frame rates.
Incremental changes benefit just as much. For example, adding floating-text effects in the second scene and a frame rate and cost badge in the third scene requires changing only the corresponding layers and copy data; the protagonist’s rig and motion data are completely unaffected. Such a change typically takes on the order of one or two minutes.
6. Local Rendering and Export: No Cloud Compute Required
The export stage uses a local headless browser to capture frames, then hands them to an encoding tool:
node export-mp4.js --html ./v2.html --fps 60 --duration 15 --out ./out.mp4
Its engineering value lies in:
- Zero cloud rendering cost: compute comes from the local machine, so cost is limited to text inference and minor debugging overhead.
- Reproducible builds: the same code exports identical results any number of times, which helps with version management and regression verification.
- Parameters as configuration: resolution, frame rate, duration, and subtitle language are all explicit parameters; you change configuration, not logic.
7. Cost Structure Comparison: From Gacha-Style Sampling to Deterministic Production
| Approach | Cost per 15-second video | 30 videos per month | Changing one line of dialogue | Character consistency |
|---|---|---|---|---|
| Code-based animation pipeline | Around 0.5 CNY | Around a dozen CNY | Change two lines of code, re-export in about 1 minute | Configuration-constrained, stable |
| General generative video (low tier) | Slightly higher than the code approach | Around twenty CNY | Resample and pay again | Prone to shot drift |
| General generative video (high tier) | Several times the code approach | Tens of CNY | Resample and pay again | Prone to structural breakdown |
The conclusion is not complicated: the cost of a generative approach rises linearly with rework, while the cost of a code approach is almost entirely a function of how many videos are produced. As publishing frequency increases and dialogue needs repeated adjustment across languages, the gap widens quickly.
8. Applicability Boundaries and Implementation Advice
This approach is not universal. Creators who want photorealistic live-action quality, need complex physics and lighting, or have no development and runtime environment at all are better served by general generative solutions or professional animation tools. Conversely, if your content centers on concept explanation, process demonstration, or data storytelling, the advantages of code-driven animation are pronounced.
Proceed in three steps: first lock down the rig and view baseline; then accumulate common motions into a reusable motion library; finally package the spec and export script into a capability package that AI coding tools can invoke in a conversation. If batch distribution is needed later, you can connect general cloud capabilities such as object storage, media processing, and log monitoring to close the loop from generation to distribution.
Turning uncertain sampling into deterministic builds and pushing variable costs close to zero is the most practical value code-driven animation offers high-frequency content production.
