Straight ahead vs pose to pose
Simulate motion frame by frame, or plan it with keyframes.
Edit this pageStraight ahead means drawing frame 1, then frame 2 from frame 1, and so on. The result is spontaneous and fluid (fire, smoke, water, hair), but hard to control. Pose to pose means drawing the key poses first, then filling in the in-betweens (the frames between them). The result is planned and quick to retime, which suits acting and interfaces.
Straight ahead
Smoke drawn frame after frame at 24 fps: each frame grows out of the previous one. Spontaneous, fluid, hard to plan.
Pose to pose
Loop's wave, built from 5 key poses (ghosted). poses() draws every in-between. Planned, precise, easy to retime.
Show the demo's source
The complete page: it loads toon.css and toon.js, plus demo-theme.js (theme colors), demo-runtime.js (gives the demo its own clock) and, for the characters, cast.js.
<!doctype html><html lang="en" data-style="saturday"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>04 · Straight ahead vs pose to pose — toon</title><link rel="stylesheet" href="../src/toon.css"><link rel="stylesheet" href="demo.css"><style> body { font-size: 15px; line-height: 1.5; max-width: var(--demo-max-width); margin: 2rem auto; padding: 0 1rem; } .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; } canvas { display: block; width: 100%; height: 300px; } .pair h2 { font-size: 1.17em; } /* the two columns' labels: real h2s (no skipped level), sized as subheads */</style></head><body><h1>Straight ahead vs pose to pose</h1><div class="pair"> <div><h2>Straight ahead</h2><canvas id="sa" role="img" aria-label="Smoke drawn straight ahead: each puff grows from the frame before it, so the smoke drifts and curls unpredictably."></canvas> <p>Smoke drawn frame after frame at 24 fps: each frame grows out of the previous one. Spontaneous, fluid, hard to plan.</p></div> <div><h2>Pose to pose</h2><canvas id="pp" role="img" aria-label="Loop raises an arm through planned key poses, shown as faint ghost frames, with the frames in between filled in."></canvas> <p>Loop's wave, built from 5 key poses (ghosted). <code>poses()</code> draws every in-between. Planned, precise, easy to retime.</p></div></div>
<script src="../src/toon.js"></script><script src="demo-theme.js"></script><script src="cast-shapes.js"></script><script src="cast.js"></script><script src="demo-runtime.js"></script><script>ToonDemos.register('04-straight-ahead-vs-pose-to-pose', (document, Toon, DemoTheme) => { const T = DemoTheme; // design tokens, live (see demo-theme.js) const { createStage, ticker, straightAhead, poses, ease, noise } = Toon;
/* [STRAIGHT-AHEAD] smoke: state integrates forward one frame at a time */ const sa = createStage(document.getElementById('sa')); const puffs = []; const smoke = (h) => { if (!sa.visible) return; // frozen while scrolled away puffs.push({ x: sa.width / 2 + (Math.random() - 0.5) * 12, y: sa.height - 24, vx: 0, vy: -70, r: 6, life: 0, seed: Math.random() * 99 }); for (const p of puffs) { p.vx += noise(p.seed + p.life * 1.5) * 120 * h; // turbulence depends on where it already is p.x += p.vx * h; p.y += p.vy * h; p.r += 14 * h; p.life += h; } while (puffs.length && puffs[0].life > 3.2) puffs.shift(); sa.clear(); for (const p of puffs) { sa.ctx.fillStyle = T.alpha(T.muted, 0.2 * (1 - p.life / 3.2)); sa.ctx.beginPath(); sa.ctx.arc(p.x, p.y, p.r, 0, 7); sa.ctx.fill(); } }; for (let i = 0; i < 48; i++) smoke(1 / 24); // 2 s of smoke already drawn, so a paused frame shows it straightAhead(smoke, { fps: 24 });
/* [POSE-TO-POSE] arm: shoulder angle a, elbow bend b (degrees, 0 = hanging down) */ const pp = createStage(document.getElementById('pp')); const keys = [ { at: 0, pose: { a: 15, b: 10 } }, // rest { at: 0.15, pose: { a: 5, b: 35 } }, // anticipation dip { at: 0.4, pose: { a: 150, b: 30 }, ease: ease.outBack }, // arm up (overshoots) { at: 0.55, pose: { a: 155, b: -30 } }, // wave { at: 0.7, pose: { a: 150, b: 30 } }, { at: 0.85, pose: { a: 155, b: -30 } }, { at: 1, pose: { a: 15, b: 10 } }, // back to rest ]; let arm = keys[0].pose; poses(keys, { duration: 3000, repeat: Infinity, onUpdate: p => (arm = p) });
pp.loop(() => { const ctx = pp.ctx, at = { x: pp.width / 2 - 14, y: pp.height / 2 + 18, h: 170 }; pp.clear(); for (const k of new Set(keys.map(k => k.pose))) // the key poses, ghosted Cast.draw(ctx, 'loop', { ...at, only: 'arms', arms: { r: k }, ink: T.alpha(T.secondary, .3), bg: T.surface }); const waving = arm.a > 100; // happy while the arm is up Cast.draw(ctx, 'loop', { ...at, fill: T.secondary, ink: T.ink, bg: T.surface, arms: { r: arm }, mood: waving ? 'happy' : 'neutral', noWink: true, look: { x: 0.7, y: -0.4 } }); // the live in-between });});</script></body></html>Straight ahead vs pose to pose in CSS
Section titled “Straight ahead vs pose to pose in CSS”To play drawn frames straight ahead, add .toon-sprite. For pose to pose, write your own @keyframes. This snippet runs as-is:
<link rel="stylesheet" href="toon.css">
<style>/* Pose to pose: you write the key poses, the browser draws the in-betweens. 0deg is the arm hanging down. */@keyframes wave { 0%, 100% { rotate: -20deg; } /* rest */ 15% { rotate: -8deg; /* wind-up */ animation-timing-function: var(--toon-ease-overshoot); } 45%, 75% { rotate: -150deg; } /* arm up */ 60% { rotate: -115deg; } /* wave */}.wave { transform-origin: 50% 5px; animation: wave 3s var(--toon-ease-in-out) infinite; }@media (prefers-reduced-motion: reduce) { /* Hold the arm-up pose instead of moving. */ .wave { animation-play-state: paused; animation-delay: -1.5s; }}</style>
<div style="display:flex; gap:40px; align-items:end; height:130px"> <!-- Straight ahead: 8 drawn frames, played in order. --> <div class="toon-sprite" id="flame" style="--toon-frames:8; --toon-fps:12; --toon-frame-w:64px; height:96px"></div> <!-- Pose to pose: a body with a waving arm. --> <div class="body" style="position:relative; width:56px; height:56px; border-radius:50%; background:var(--toon-color)"> <div class="wave" style="position:absolute; left:42px; top:12px; width:10px; height:44px; border-radius:5px; background:var(--toon-color)"></div> </div></div>
<script>// Straight ahead: draw 8 flame frames into one sprite sheet,// each frame grown from the one before. .toon-sprite plays// them with steps(), so there are no in-betweens.function drawFlames() { const F = 8, W = 64, H = 96; // frames, frame size (px) const sheet = document.createElement('canvas'); sheet.width = F * W; sheet.height = H; const g = sheet.getContext('2d'); g.fillStyle = getComputedStyle(document.documentElement) .getPropertyValue('--toon-color'); g.strokeStyle = getComputedStyle(document.body).color; g.lineWidth = 2.5; let lobes = Array(10).fill(1); // the size of each lobe for (let f = 0; f < F; f++) { // Nudge every lobe from where the last frame left it. lobes = lobes.map((v) => Math.min(1.3, Math.max(0.75, v + Math.random() * 0.4 - 0.2))); const pts = lobes.map((v, i) => { const a = (i / lobes.length) * Math.PI * 2; const up = Math.max(0, -Math.sin(a)); // taller on top return { x: f * W + 32 + Math.cos(a) * 16 * v * (1 - up/2), y: 70 + Math.sin(a) * 16 * v * (1 + up * 2) }; }); g.beginPath(); pts.forEach((p, i) => { const n = pts[(i + 1) % pts.length]; g.quadraticCurveTo(p.x, p.y, (p.x + n.x) / 2, (p.y + n.y) / 2); }); g.closePath(); g.fill(); g.stroke(); } document.getElementById('flame').style.backgroundImage = `url(${sheet.toDataURL()})`;}drawFlames();</script>Below, the flame on the left is the flipbook and the waving arm on the right is the keyframes:
The script draws each flame frame by nudging the one before, and .toon-sprite plays them with steps(), so there are no in-betweens. toon.css has no pose-to-pose preset because every @keyframes block already is one: you write the key poses and the browser draws the rest.
Straight ahead vs pose to pose in Canvas
Section titled “Straight ahead vs pose to pose in Canvas”straightAhead runs a step function at a fixed frame rate, and each step moves the smoke on from where the last one left it. poses takes key poses on a timeline from 0 to 1, and each key’s ease shapes the move into that pose. samplePoses does the same interpolation as a plain function, for scrubbing or ghost frames.
<script src="toon.js"></script><canvas style="width:100%; height:180px" role="img" aria-label="Left: smoke rises and curls, each frame grown from the one before. Right: a ball raises its arm, waves and lowers it, through key poses drawn faintly behind it"></canvas>
<script>const { createStage, straightAhead, poses, ease, noise } = Toon;const stage = createStage(document.querySelector('canvas'));const ctx = stage.ctx;
// Straight ahead: each frame updates what the last one left.const puffs = [];let seed = 0;function step(h) { // h: seconds per frame puffs.push({ x: stage.width / 4, y: stage.height - 30, vx: 0, r: 5, life: 0, seed: (seed += 7.3) }); for (const p of puffs) { p.vx += noise(p.seed + p.life * 1.5) * 80 * h; // drift p.x += p.vx * h; p.y -= 45 * h; // rise p.r += 10 * h; p.life += h; // spread } while (puffs.length && puffs[0].life > 2.4) puffs.shift();}for (let i = 0; i < 48; i++) step(1 / 24); // start mid-plumestraightAhead(step, { fps: 24 });
// Pose to pose: shoulder angle a and elbow bend b, in degrees// (0 hangs down). Each key's ease shapes the move into it.const up = { a: 150, b: 30 }, wave = { a: 155, b: -30 };const rest = { a: 40, b: 20 }, windUp = { a: 30, b: 45 };const keys = [ { at: 0, pose: up }, { at: 0.15, pose: wave }, { at: 0.3, pose: up }, { at: 0.55, pose: rest }, { at: 0.7, pose: windUp }, // anticipation { at: 1, pose: up, ease: ease.outBack }, // overshoot];let arm = { ...up };poses(keys, { duration: 3000, repeat: Infinity, onUpdate: (pose) => (arm = pose) });4 collapsed lines
// Reduced motion: freeze the clock with the arm up.if (matchMedia('(prefers-reduced-motion: reduce)').matches) { Toon.ticker.timeScale = 0;}
function drawArm(sx, sy, { a, b }, width) { const rad = Math.PI / 180; const ex = sx - Math.sin(a * rad) * 26; const ey = sy + Math.cos(a * rad) * 26; ctx.lineWidth = width; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(sx, sy); ctx.lineTo(ex, ey); ctx.lineTo(ex - Math.sin((a + b) * rad) * 22, ey + Math.cos((a + b) * rad) * 22); ctx.stroke();}
stage.loop(() => { const w = stage.width, floor = stage.height - 24;3 collapsed lines
const fill = getComputedStyle(document.documentElement) .getPropertyValue('--toon-color').trim() || '#ff6b4a'; const ink = getComputedStyle(document.body).color; stage.clear(); ctx.fillStyle = ink; ctx.fillRect(0, floor, w, 2); ctx.fillRect(w / 2 - 1, 16, 2, floor - 16); // divider
ctx.save(); // smoke stays in the left half ctx.beginPath(); ctx.rect(0, 8, w / 2 - 6, floor - 8); ctx.clip(); ctx.fillStyle = ink; for (const p of puffs) { ctx.globalAlpha = 0.25 * (1 - p.life / 2.4); ctx.beginPath(); ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2); ctx.fill(); } ctx.restore();
const cx = w * 0.78, r = 30, sx = cx - r, sy = floor - r - 6; ctx.strokeStyle = ink; ctx.globalAlpha = 0.2; // key poses for (const k of [up, wave, rest, windUp]) drawArm(sx, sy, k, 3); ctx.globalAlpha = 1; ctx.beginPath(); ctx.arc(cx, floor - r, r, 0, Math.PI * 2); ctx.fillStyle = fill; ctx.fill(); ctx.lineWidth = 2.5; ctx.stroke(); drawArm(sx, sy, arm, 9); // the in-between ctx.strokeStyle = fill; drawArm(sx, sy, arm, 4);});</script>Straight ahead vs pose to pose: tuning tips
Section titled “Straight ahead vs pose to pose: tuning tips”- Mix the two approaches. Pose the main body, then simulate hair, cloth and tails straight ahead on top (see follow-through).
- Use a lower frame rate for a hand-made feel. Straight-ahead motion at 12 or 24 fps looks more drawn than at 60 fps.
- Retime by moving keys, not frames. With pose to pose, a slower wave means changing a few
atvalues. The in-betweens follow on their own. - Show the key poses while you work. Drawing them faintly behind the figure, as the Canvas snippet does, shows at a glance whether the in-betweens travel where you meant.
The demo’s wave also shows anticipation (the arm dips before it rises) and exaggeration (it overshoots the top pose).
For every option, see the Canvas timing and sequencing functions and the CSS sprite preset.