Low-Cost Code-Driven Stick Figure Animation: A Deterministic Alternative to Generative Video

    This article explains how to replace generative video workflows with a low-cost, code-driven stick figure animation pipeline. It covers why character consistency and rework—not visual quality—drive the real cost of short-form explainer videos, and how packaging rig definitions, rendering logic, and export scripts into a reusable skill directory keeps output reproducible. You will find the core forward-kinematics math, single-joint angle constraints, keyframe and easing interpolation, layered subtitle and graphic design, a headless-browser frame-by-frame export flow, and a practical cost comparison across iteration counts. The piece also outlines a typical production workflow and the scenarios where this approach fits or does not.

    1. Why Character Consistency Costs More Than Visual Quality

    In short-form explainer videos, the real hidden cost is usually not image quality but the rework caused by inconsistent characters. Many teams have lived through this loop: submit a prompt to a generative video tool, get roughly ten seconds of footage, notice the protagonist’s face starting to drift around the fifth second and an extra arm segment appearing at the seventh, roll the dice three more times before accepting a take—and quietly burn through the budget. When a single line of narration needs to change, the camera language, lighting mood, and character motion all have to be re-rolled. Every small tweak is another pull of the gacha machine, and cost grows linearly with the number of iterations.

    This model has three structural flaws:

    • Non-determinism: results cannot be reproduced. The same prompt can produce very different output twice, so a stable character asset can never be established.
    • No local editing: changes to a line of dialogue, a subtitle, or a single motion cannot be applied to the existing cut; the whole segment must be recomputed.
    • Cost scales with revisions: one finished clip may look cheap, but once multiple rounds of feedback and rework stack up, the real expense is typically several times the quoted unit price.

    So for explainer content with a limited budget + high output frequency + narration that needs repeated polishing, the right engineering choice is to replace stochastic generation with deterministic rendering: the character is no longer “guessed” by a probability model but computed precisely from parameters, coordinates, and interpolation functions.

    2. Overall Approach: A Bindable “Animation Skill” Package

    The key to a deterministic pipeline is letting the animation spec accumulate as a reusable asset instead of being re-described in natural language every session. The core practice here is to package the rig definition, rendering logic, and export flow into a local skill directory with documentation, so that an agent recognizes a task like “make a stick figure animation” and automatically loads the existing rules rather than improvising.

    A typical directory structure looks like this:

    1. stickman-animator/
    2. ├── SKILL.md # Skill spec: trigger scenarios, rig parameter table, motion vocabulary, subtitle rules
    3. ├── engine.js # Rig rendering engine: RIG definition, joint interpolation, coordinate solving, frame drawing
    4. └── export-mp4.js # Export script: drives a local browser to render frame by frame, then hands off to a video encoder

    The value of SKILL.md is often underestimated. It is not a comment but a constraint layer: it defines character height, upper/lower limb proportions, line width, head radius, the ratio between camera and canvas, and the joint-angle ranges for common motions (waving, turning, walking, pointing at a chart). Once the constraints are written into a file and loaded automatically, the model outputs “parameters that comply with the spec” rather than “pixels that look like a stick figure.” This eliminates drift problems such as “the legs got longer in this version” at the source.

    It is worth noting that this idea of “encapsulating a domain spec as a loadable skill” is becoming a mainstream way to use AI coding tools. It is essentially about constraining a probability model’s tendency to diverge with file-based knowledge—a general engineering practice, not a capability unique to any single vendor.

    3. Core Principle: Polyline Skeleton and Single-Joint Angle Control

    A stick figure looks crude, but its geometry is extremely well suited to procedural generation—the torso and limbs are all polyline segments, and each joint is governed by a single angle parameter. This simplification yields two direct benefits: coordinates can be solved in closed form, and motion can vary continuously frame by frame.

    Assume the character rig (RIG) contains the following fixed values, which are never modified anywhere in the project:

    1. // Rig baseline: once locked, no motion or camera change alters the body proportions
    2. const RIG = {
    3. torso: 90, // Torso length (pixels, base coordinate system)
    4. upperArm: 55, // Upper arm
    5. foreArm: 50, // Forearm
    6. thigh: 60, // Thigh
    7. shin: 58, // Shin
    8. headR: 22, // Head radius
    9. lineWidth: 6, // Line width, stays crisp when scaled to 720P
    10. shoulderW: 26, // Shoulder width (offset of each shoulder from the center axis)
    11. hipW: 14 // Hip width
    12. };

    Forward kinematics solves the world coordinates of each joint in a very intuitive form:

    1. // From a parent joint, derive the child position using "length + relative angle"
    2. function joint(origin, length, angleDeg) {
    3. const rad = angleDeg * Math.PI / 180;
    4. return {
    5. x: origin.x + length * Math.cos(rad),
    6. y: origin.y + length * Math.sin(rad)
    7. };
    8. }
    9. function solvePose(pose, root) {
    10. const neck = joint(root, RIG.torso, pose.spine);
    11. const lShoulder = { x: neck.x - RIG.shoulderW / 2, y: neck.y };
    12. const rShoulder = { x: neck.x + RIG.shoulderW / 2, y: neck.y };
    13. const elbow = joint(lShoulder, RIG.upperArm, pose.leftArm);
    14. const wrist = joint(elbow, RIG.foreArm, pose.leftArm + pose.leftElbow);
    15. const knee = joint(root, RIG.thigh, pose.leftLeg);
    16. const ankle = joint(knee, RIG.shin, pose.leftLeg + pose.leftKnee);
    17. return { neck, elbow, wrist, knee, ankle, /* …right arm and right leg follow the same pattern */ };
    18. }

    What actually guarantees the character “never breaks shape” is the constraint design below:

    1. Hard-coded lengths and proportions: bone lengths are not part of generation and the model has no authority to change them, so body proportions are a constant rather than a guess.
    2. Single degree of freedom per joint: each joint exposes only one angle, compressing the search space into a very small range, so the model can hardly produce an illegal pose like a twisted-off arm.
    3. Legal angle-range validation: upper and lower limits are set for the shoulders, elbows, knees, and spine; anything out of range is clamped back to the boundary, avoiding self-intersection and reverse folding.
    4. Fixed canvas and camera mapping: world-to-canvas coordinates use a uniform scale and offset; changing the shot only changes the scale factor, not the rig data, so the “character goes out of shape when the camera changes” problem is eliminated entirely.

    Motion is expressed with keyframes + eased interpolation. Each joint’s angle is given at a number of keyframes, and the remaining frames are solved continuously by an easing function (such as easeInOutCubic):

    1. const FPS = 60, DURATION = 15, TOTAL = FPS * DURATION; // 900 frames
    2. function poseAt(frame, keyframes) {
    3. const t = frame / (TOTAL - 1) * (keyframes.length - 1);
    4. const i = Math.min(Math.floor(t), keyframes.length - 2);
    5. const u = easeInOutCubic(t - i);
    6. const out = {};
    7. for (const k in keyframes[i]) {
    8. out[k] = keyframes[i][k] + (keyframes[i + 1][k] - keyframes[i][k]) * u;
    9. }
    10. return out; // every frame is a set of legal angles, varying continuously per joint
    11. }

    Precisely because motion is “a function of angle over time,” any adjustment affects only one variable and never disturbs other body parts. This is the most fundamental advantage of a code-driven flow over generative video: local editability, precise rollback, and version control.

    4. Subtitles and Graphic Elements: Decoupling the Information Layer from the Character Layer

    The real protagonist of an explainer video is the information; the stick figure is just a symbol that guides attention. So the architecture must be layered: the skeletal character layer, the subtitle layer, and the decorative graphic layer are rendered independently and do not interfere with each other.

    • Subtitle layer: bilingual (English/Chinese) text is sliced along the timeline, with each segment labeled with start and end frame numbers to avoid the reading pressure of “one long sentence for the whole segment”; text layout stays within a safe area and long lines wrap automatically.
    • Decoration layer: emphasis symbols (amounts, upward arrows, percentages) are drawn on separate layers, with positions expressed as canvas percentages rather than absolute pixels, so they do not misalign at different resolutions.
    • Background layer: a solid color or low-saturation gradient ensures high contrast and readability while avoiding visual noise that would interfere with subtitles.

    Once layered, a change often touches only a few lines of configuration in one layer. For example, adding floating amount text to the second act or a corner badge to the third act requires no change to the character rig data at all—this is exactly the engineering payoff of “change one place, take effect locally.”

    5. Export Pipeline: Local Frame-by-Frame Rendering + Video Encoding

    The last link in deterministic rendering is export. A feasible, cost-controlled path is: use a script to drive a local headless browser for frame-by-frame rendering, output every frame as an image sequence, then hand it to a video encoder to compress into an mp4. The whole pipeline consumes only the local CPU, does not occupy cloud graphics compute, and does not require separate billing for rendering time.

    The skeleton of the export script is roughly as follows (pseudocode, emphasizing the flow rather than specific command details):

    1. const TOTAL = 900, FPS = 60, W = 1280, H = 720;
    2. async function exportVideo() {
    3. await launchHeadlessBrowser({ width: W, height: H, deviceScaleFactor: 1 });
    4. await page.goto('file://' + resolve('v2.html'));
    5. for (let f = 0; f < TOTAL; f++) {
    6. await page.evaluate((frame) => window.renderFrame(frame), f); // render frame f exactly
    7. await page.screenshot({ path: `frames/f_${String(f).padStart(5, '0')}.png` });
    8. }
    9. await encodeToMp4(`frames/f_%05d.png`, { fps: FPS, out: 'output.mp4' });
    10. }

    A few engineering points to keep in mind:

    1. Determinism first: rendering must be driven frame by frame; do not rely on the real-time cadence of requestAnimationFrame, otherwise dropped frames will desynchronize duration and audio/video.
    2. Headless browser launch flags: depending on the implementation, some compatibility switches may be needed to render canvas and custom fonts stably on the local machine; this is general debugging experience, varies across implementations, and needs to be verified on your own.
    3. Encoding parameters and quality: resolution, frame rate, and compression factor together determine file size; pure vector line animation has very low bitrate requirements, usually far below same-length live-action footage.
    4. Audio alignment: voiceover and sound effects are arranged independently on the timeline, and rendering is only responsible for the visuals; if the voiceover is replaced later, the visuals do not need to be recomputed—this is the biggest payoff of this approach in the “change the dialogue” scenario.

    6. Performance and Cost Accounting Method

    Using “15 seconds, 60fps, 720P, 900 frames total” as the baseline, local export usually completes in tens of seconds and produces a tiny file. What really needs to be accounted for—to the team or to yourself—is the total cost of a whole iteration round, not the nominal price of a single export. Accounting along the following lines is recommended:

    Approach Direct cost per 15-second clip Cost at 30 clips/month Cost to change one line of narration Character consistency
    Code-driven deterministic rendering Very low (mainly local compute and time) Roughly around ten yuan Close to zero, only re-export time Constant rig, stable reproduction
    Generative video gacha Billed per clip by credits or duration Tens to over a hundred yuan Requires regeneration, billed per attempt Prone to camera drift
    High-end generative model Highest unit price, several times the former Hundreds of yuan Requires regeneration, billed per attempt Prone to deformation and character mix-ups

    It should be emphasized that the table above is a cost-structure comparison, not a precise quote: vendors and billing models differ enormously, so refer to the actual settlement rules in use. But the conclusion is robust—as the number of iterations rises, per-attempt billing grows linearly or even super-linearly, while the marginal cost of the code approach is almost just one local export.

    Two non-monetary benefits stack on top:

    • Version control: scripts and keyframe configurations can go into a code repository, and any historical version can be rebuilt with one click—very valuable for compliance records and team collaboration.
    • Batch production: once the script is parsed into structured per-act data, the same engine can produce videos in batches, with no need to re-communicate and re-debug for each clip.

    7. Typical Workflow and Implementation Advice

    A smooth production loop is roughly:

    1. Prepare the environment: a Node.js runtime, an available video encoding tool, and a local browser—once all three are in place you can start, with no cloud compute request needed.
    2. Build the skill package: write the rig parameters, motion vocabulary, and subtitle and color specs into a documentation file to form a shared team asset.
    3. Structure the script: cut the narration into several acts, giving each act a duration, shot size, key motions, and subtitles, forming a machine-readable intermediate format.
    4. Generate and fine-tune: have an AI coding tool read the spec and generate the page, then proofread poses and pacing one by one, with changes landing only on specific parameters.
    5. Export and publish: batch render and encode locally, mount audio independently, and produce a finished cut ready for distribution.

    The boundaries of what fits and what does not should also be stated clearly. This approach suits symbolic, information-dense scenarios that need frequent changes and have no requirement for photorealistic humans, such as knowledge explainers, process demonstrations, data narration, and feature walkthroughs. If the goal is realistic people, complex physical interaction, or cinematic lighting, generative video or other professional production means should still be chosen; this approach has no advantage in those dimensions and should not be forced into them.

    8. Conclusion

    Demoting “generation” to “computation” is the most memorable idea in this approach. When a character is uniquely determined by a fixed rig and single-joint angles, consistency stops being a matter of luck and becomes a matter of mathematics; when narration and visuals are decoupled and a change touches only a few parameters, iteration cost is decoupled from output volume. For budget-sensitive, frequently updated explainer content whose script needs repeated polishing, building a deterministic animation engine locally first is often more worthwhile than continuing to pay for one gacha pull after another.