Skip to content

Timing

Duration sets weight and mood: fast is light, slow is heavy.

Edit this page

Timing is how long an action takes; spacing is how the motion is spread across that time. Together they tell the viewer how heavy something is: a bowling ball drops hard and barely bounces, a rubber ball rebounds fast, and a balloon drifts. In the demo, Brick plays the bowling ball, Dot the rubber ball and Zip the balloon.

Now showing: Timing and weightOpen the Timing and weight demo on its own page (opens in a new tab)
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>09 · Timing — 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; }
canvas { display: block; width: 100%; height: 340px; margin: var(--space-sm) 0; }
.controls { display: flex; gap: 1.5rem; flex-wrap: wrap; }
</style>
</head>
<body>
<h1>Timing</h1>
<p>The number of frames an action takes tells us how heavy something is. Same drop, three weights:
Brick (heavy as a bowling ball), Dot (a rubber ball) and Zip (light as a balloon).</p>
<div class="controls">
<label><input id="twos" type="checkbox"> On twos (12 fps)</label>
<label>Time scale <input id="scale" type="range" min="0.1" max="2" step="0.05" value="1"> <output id="out">1×</output></label>
</div>
<canvas id="c" role="img" aria-label="Brick, Dot and Zip drop side by side. Brick falls hard and barely bounces, Dot rebounds quickly, and Zip drifts down slowly like a balloon."></canvas>
<p class="demo-try">Switch on "on twos" (12 drawings/s) or slow motion.</p>
<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('09-timing', (document, Toon, DemoTheme) => {
const T = DemoTheme; // design tokens, live (see demo-theme.js)
const { createStage, ticker, quantize, impact, squash, withSquash, groundShadow } = Toon;
const stage = createStage(document.getElementById('c'));
const { ctx } = stage;
const twos = document.getElementById('twos'), scale = document.getElementById('scale'), out = document.getElementById('out');
// [TIMING] global clock. setSpeed = ticker.timeScale, except it leaves a reduced-motion pause in place (demo-theme.js).
scale.oninput = () => { T.setSpeed(+scale.value); out.textContent = scale.value + '×'; };
// [TIMING] weight lives in gravity, restitution, drag and how much it deforms
const things = [
{ name: 'Brick · heavy', who: 'brick', color: 'neutral', r: 32, g: 2600, e: 0.2, drag: 0, squash: 0.05 },
{ name: 'Dot · bouncy', who: 'dot', color: 'primary', r: 26, g: 1800, e: 0.78, drag: 0, squash: 0.4 },
{ name: 'Zip · light', who: 'zip', color: 'tertiary', r: 30, g: 300, e: 0.45, drag: 1.6, squash: 0.25 },
].map(o => ({ ...o, y: 0, vy: 0, hold: 0, out: 0 }));
const HOLD = 0.07;
let since = 99, lastDrawn = -1;
stage.loop((dt, t) => {
const ground = stage.height - 50;
since += dt;
if (since > 4.5) { since = 0; things.forEach(o => Object.assign(o, { y: 40, vy: 0, hold: 0 })); }
for (const o of things) {
const floor = ground - o.r;
if (o.hold > 0) { o.hold -= dt; if (o.hold <= 0) o.vy = -o.out; continue; }
o.vy += o.g * dt; o.vy *= 1 - o.drag * dt; o.y += o.vy * dt;
if (o.y >= floor) { o.y = floor; o.out = o.vy * o.e; o.vy = 0; o.hold = o.out > 40 ? HOLD : 0; o.hit = o.out; }
}
if (twos.checked) { const q = quantize(t, 12); if (q === lastDrawn) return; lastDrawn = q; } // hold drawings
stage.clear();
ctx.fillStyle = T.ground; ctx.fillRect(0, ground, stage.width, 50);
ctx.fillStyle = T.groundLine; ctx.fillRect(0, ground, stage.width, 2);
things.forEach((o, i) => {
const x = stage.width * (i + 1) / 4;
const s = o.hold > 0
? impact(Math.sin((1 - o.hold / HOLD) * Math.PI) * o.squash * Math.min(1, o.hit / 500))
: squash(0, o.vy, { amount: o.squash * 0.0015 });
groundShadow(ctx, x, ground, o.r, ground - o.r - o.y, { maxHeight: 280 });
const mood = o.who === 'brick' ? 'neutral' : o.hold > 0 || o.who === 'zip' ? 'happy' : 'neutral'; // Brick stays unflappable
withSquash(ctx, x, o.y, s, c => Cast.draw(c, o.who, { x: 0, y: 0, h: o.r * 2, fill: T[o.color], ink: T.ink, trail: false, mood,
look: { x: 0, y: Math.max(-1, Math.min(1, o.vy / 800)) } }), o.hold > 0 ? { x: 0, y: o.r } : undefined);
ctx.fillStyle = T.muted; ctx.font = '13px system-ui'; ctx.textAlign = 'center'; ctx.fillText(stage.width < 480 ? o.name.split(' · ')[0] : o.name, x, ground + 30); // phones: names only, so labels don't collide
});
});
});
</script>
</body>
</html>

Set --toon-tempo on a container to retime every preset inside it. Higher is slower. This snippet runs as-is:

<link rel="stylesheet" href="toon.css">
<!-- --toon-tempo on a container retimes everything in it. -->
<div id="scene" style="--toon-tempo:1; display:grid;
justify-items:center; padding-top:110px">
<div class="toon-bounce" style="--toon-height:100px;
width:48px; height:48px; border-radius:50%;
background:var(--toon-color)"></div>
<div class="toon-shadow toon-bounce-shadow"
style="width:56px; height:12px"></div>
</div>
<label>Tempo <input id="tempo" type="range" min="0.5"
max="2" step="0.1" value="1"
aria-valuetext="1, 800 ms per bounce">
<output id="out">800 ms</output></label>
<script>
// Higher tempo is slower: each bounce takes 800 ms × tempo.
const tempo = document.getElementById('tempo');
tempo.oninput = () => {
const ms = Math.round(800 * tempo.value);
document.getElementById('scene').style
.setProperty('--toon-tempo', tempo.value);
document.getElementById('out').textContent = `${ms} ms`;
tempo.setAttribute('aria-valuetext',
`${tempo.value}, ${ms} ms per bounce`);
};
</script>

Drag the slider below: the ball and its shadow change speed together, because both read the tempo from the container:

Now showing: CSS tempoOpen the CSS tempo demo on its own page (opens in a new tab)

Every preset lasts --toon-duration (800 ms) times --toon-tempo. The .toon-heavy and .toon-light modifiers set the tempo to 1.6 and 0.6, and change the squash to match.

Weight comes from gravity, bounciness and drag, so this snippet gives each object its own values. quantize() holds time on 12 drawings per second. Tick On twos to animate on twos (holding each drawing for two frames), the hand-drawn rhythm of 24 fps film.

  • Make heavy things slow to start and quick to stop. A bowling ball takes a while to get going, lands abruptly, deforms little and barely rebounds.
  • Let light things react at once. A balloon or a leaf floats, flutters and overshoots, so give it low gravity and plenty of drag.
  • Keep interface timing short. Use 150–250 ms for small feedback and 300–500 ms for larger moves across the screen. Anything longer starts to feel slow.
  • Check timing in slow motion. Set Toon.ticker.timeScale to 0.25 to slow every animation on the clock, like the demo’s Time scale slider. In CSS, a --toon-tempo of 4 on :root does the same.

The demo also shows squash and stretch: each object deforms as much as its material allows.

For every option, see the Canvas timing functions and the CSS custom properties.