The primary action is what a character is doing, such as walking. Secondary actions support it: arms swinging against the step, eyes glancing around, an occasional blink. They make the main action richer, but they never compete with it.
Toggle the secondary actions to see how flat the walk gets without them.
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>08 · Secondary action — 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: 300px; margin: var(--space-sm) 0; }</style></head><body><h1>Secondary action</h1><p>The primary action is Loop's walk: the bob and the feet. Secondary actions — swinging arms, idle glances, the odd blink — add personality without stealing focus.</p><label><input id="sec" type="checkbox" checked> Secondary action</label><canvas id="c" role="img" aria-label="Loop walks in place. Its arms swing, its eyes glance around and it blinks now and then. One switch turns all of these secondary actions off, leaving only the walk."></canvas><p class="demo-try">Toggle the secondary actions to see how flat the walk gets without them.</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('08-secondary-action', (document, Toon, DemoTheme) => { const T = DemoTheme; // design tokens, live (see demo-theme.js) const { createStage, ticker, noise, blink } = Toon; const stage = createStage(document.getElementById('c')); const { ctx } = stage; const sec = document.getElementById('sec'); let x = null; // starts mid-stage, so a paused first frame shows the walk
stage.loop((dt, t) => { const ground = stage.height - 40, H = 110, speed = 110; if (x === null) x = stage.width * 0.45; x += speed * dt; if (x > stage.width + 80) x = -80; const phase = t * Math.PI * 2 * 1.6; const bob = Math.abs(Math.cos(phase)) * 8; // primary: walk bounce, highest as the feet pass const cy = ground - H / 2 - 12 - bob;
stage.clear(); ctx.fillStyle = T.ground; ctx.fillRect(0, ground, stage.width, 40); ctx.fillStyle = T.groundLine; ctx.fillRect(0, ground, stage.width, 2); for (const side of [0, 1]) { // feet, alternating // A foot swings forward (f rising, cos > 0) in the air, then plants and slides back under the moving body. // Stride 17px: at 1.6 steps/s a planted foot then moves back as fast as the body moves on (no net skating). const f = Math.sin(phase + side * Math.PI), lift = Math.max(0, Math.cos(phase + side * Math.PI)) * 8; ctx.fillStyle = T.ink; ctx.beginPath(); ctx.ellipse(x + f * 17, ground - 5 - lift, 11, 5, 0, 0, 7); ctx.fill(); } const on = sec.checked, swing = Math.sin(phase) * 28; Cast.draw(ctx, 'loop', { x, y: cy, h: H, fill: T.secondary, ink: T.ink, bg: T.surface, feet: false, noWink: true, arms: on ? { r: { a: 15 + swing, b: 25 }, l: { a: 15 - swing, b: 25 } } // [SECONDARY] arms swing against the legs : { r: { a: 8, b: 4 }, l: { a: 8, b: 4 } }, look: on ? { x: 0.4 + noise(t * 0.6) * 0.8, y: noise(t * 0.4 + 9) * 0.6 } : { x: 0.6, y: 0 }, // idle glances blink: on ? blink(t, { every: 2.8 }) : 0 }); });});</script></body></html>Secondary action in CSS
Section titled “Secondary action in CSS”Add .toon-sway, .toon-bob or .toon-blink to small parts of something that already has a main action. This snippet runs as-is:
<link rel="stylesheet" href="toon.css">
<!-- Primary: the card settles in. Secondary: sway, blink, bob --><div id="card" class="toon-settle" style="display:flex; align-items:center; gap:16px; max-width:300px; padding:16px; border:2px solid; border-radius:16px"> <span class="toon-sway" style="display:grid; justify-items:center; flex:none"> <span style="display:grid; place-items:center; width:34px; height:34px; border-radius:50%; border:2.5px solid; background:var(--toon-color)"> <span class="toon-blink" style="display:flex; gap:6px"><b style="width:4px; height:7px; border-radius:2px; background:currentColor"></b><b style="width:4px; height:7px; border-radius:2px; background:currentColor"></b></span> </span> <span style="width:3px; height:26px; background:currentColor"></span> </span> <p style="margin:0">Your garden is growing <span class="toon-bob" style="display:inline-block; padding:0 8px; border:2px solid; border-radius:99px; font-weight:600">3 new</span></p></div><button id="replay" type="button">Replay</button>
<script>// Replay a one-shot preset: remove it, force a reflow, add it.document.getElementById('replay').onclick = () => { const card = document.getElementById('card'); card.classList.remove('toon-settle'); void card.offsetWidth; card.classList.add('toon-settle');};</script>Below, the card’s entrance is the primary action. Press Replay to watch it again while the flower and badge keep moving:
Your garden is growing 3 new
.toon-sway tilts 4 degrees each way from the bottom edge, .toon-bob floats up 5px and back, and .toon-blink squashes to a line about once every 4 seconds. Each runs on a multiple of --toon-duration, so they drift in and out of step instead of pulsing together.
Secondary action in Canvas
Section titled “Secondary action in Canvas”This character runs as-is. The arms swing from the walk’s own phase, so they stay in step. noise() moves the eyes in smooth, random glances, and blink() closes them at a slightly irregular rhythm.
<script src="toon.js"></script><canvas style="width:100%; height:180px" role="img" aria-label="A round character walks in place. Its arms swing against its steps, its eyes glance around and it blinks now and then"></canvas><label><input id="extras" type="checkbox" checked> Secondary action</label>
<script>const { createStage, noise, blink } = Toon;const stage = createStage(document.querySelector('canvas'));const extras = document.getElementById('extras');const r = 34, steps = 1.6; // body radius px, steps per second// Start mid-stride, eyes to one side.let t = 0.15;4 collapsed lines
// Reduced motion: freeze the clock on that frame.if (matchMedia('(prefers-reduced-motion: reduce)').matches) { Toon.ticker.timeScale = 0;}
stage.loop((dt) => { t += dt; const on = extras.checked; const phase = t * Math.PI * 2 * steps; // Primary action: the walk. Feet alternate, body bobs. const bob = Math.abs(Math.sin(phase)) * 6; // Secondary, driven by the walk: arms swing against it. const swing = on ? Math.sin(phase) : 0; // Secondary, on their own clocks: glances and blinks. const look = on ? noise(t * 0.6) * 6 : 0; // px const shut = on ? blink(t, { every: 2.8 }) : 0; // 0 to 1
const ctx = stage.ctx, x = stage.width / 2; const floor = stage.height - 24, y = floor - 16 - r - bob;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, stage.width, 2); ctx.strokeStyle = ink; ctx.fillStyle = ink; ctx.lineWidth = 2.5; ctx.lineCap = 'round'; for (const side of [-1, 1]) { // Feet take turns lifting: the walk, marching in place. const lift = Math.max(0, Math.sin(phase) * side) * 8; ctx.beginPath(); ctx.ellipse(x + side * 13, floor - 5 - lift, 10, 5, 0, 0, Math.PI * 2); ctx.fill(); // Each arm swings out as the opposite foot lifts. const a = 0.35 + Math.max(0, -swing * side) * 1.4; const sx = x + side * r * 0.85, sy = y + 6; ctx.beginPath(); ctx.moveTo(sx, sy); ctx.lineTo(sx + side * Math.sin(a) * 26, sy + Math.cos(a) * 26); ctx.stroke(); } ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fillStyle = fill; ctx.fill(); ctx.stroke(); ctx.fillStyle = ink; for (const side of [-1, 1]) { // eyes squash to a line ctx.beginPath(); ctx.ellipse(x + side * 11 + look, y - 6, 4, Math.max(0.8, 7 * (1 - shut)), 0, 0, Math.PI * 2); ctx.fill(); } ctx.beginPath(); // mouth ctx.arc(x + look, y + 8, 7, 0.2 * Math.PI, 0.8 * Math.PI); ctx.stroke();});</script>Secondary action: tuning tips
Section titled “Secondary action: tuning tips”- Keep amplitudes small. If people notice the secondary action first, it’s too big. The arms here swing about 80 degrees; the eyes move 6px at most.
- Drive it from the primary motion. Arms that read the walk’s phase stay in step for free, while an independent loop can feel disconnected.
- Give idle motion its own clock. Glances and blinks that follow the walk look mechanical. A slow
noise()and an irregular blink feel like a mind at work. - Turn it off and compare. Untick Secondary action in the demos: the walk still works, but the character looks lifeless.
For every option, see the Canvas secondary action functions and the CSS secondary action presets.