Staging means directing attention, so the viewer looks at one thing at a time. Use contrast in color, light, motion and size to lead the eye, and give the important thing a clear silhouette and a moment to itself. In the demo, Loop performs under the spotlight while a crowd of gray Bricks stands still and watches.
Press Next performer or click anyone to give them the stage: they step up as the new Loop, and the spotlight follows on a spring.
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>03 · Staging — 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: 320px; margin-bottom: var(--space-sm); cursor: pointer; }</style></head><body><h1>Staging</h1><p>Present one idea at a time so it reads instantly. The performer (Loop) is colored, moving and lit; the crowd of Bricks is gray, still and in shadow, and every one of them looks at the performer.</p><canvas id="c" style="cursor:pointer" role="img" aria-label="A spotlit performer, Loop, hops in the middle of the stage while a crowd of dim, gray Bricks stands still and watches. Giving someone else the stage turns them into the performer and moves the spotlight to them."></canvas><p class="demo-try"><button type="button" class="demo-act" id="act">Next performer</button> Press <i>Next performer</i> or click anyone to give them the stage: they step up as the new Loop, and the spotlight follows on a spring.</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('03-staging', (document, Toon, DemoTheme) => { const T = DemoTheme; // design tokens, live (see demo-theme.js) const { createStage, ticker, noise, Spring, groundShadow } = Toon; const stage = createStage(document.getElementById('c')); const { ctx } = stage; const actors = Array.from({ length: 14 }, (_, i) => ({ seed: i * 9.3, bx: 0.07 + (i % 7) * 0.143, by: i < 7 ? 0.42 : 0.78 })); let hero = 10; const spring = { stiffness: 60, damping: 13 }; const spot = { x: new Spring(stage.width / 2, spring), y: new Spring(stage.height / 2, spring) }; const pos = (a, t) => ({ x: a.bx * stage.width + noise(t * 0.3 + a.seed) * 16, y: a.by * stage.height + noise(t * 0.3 + a.seed + 50) * 6 });
stage.canvas.addEventListener('click', e => { const r = stage.canvas.getBoundingClientRect(), mx = e.clientX - r.left, my = e.clientY - r.top; let best = 0, dist = Infinity; actors.forEach((a, i) => { const p = pos(a, ticker.time), d = Math.hypot(p.x - mx, p.y - my); if (d < dist) { dist = d; best = i; } }); hero = best; });
stage.loop((dt, t) => { stage.clear(T.stage); // the theatre stays dark in both modes const h = pos(actors[hero], t); actors.forEach((a, i) => { const p = pos(a, t), isHero = i === hero; if (isHero) { // Loop performs: hops, arms up, lit const hop = Math.abs(Math.sin(t * 4)) * 30; groundShadow(ctx, p.x, p.y + 22, 16, hop, { maxHeight: 90, alpha: 0.5 }); Cast.draw(ctx, 'loop', { x: p.x, y: p.y - 10 - hop, h: 62, fill: T.stageHero, ink: T.stageInk, bg: T.stage, mood: 'happy' }); } else { // the crowd: quiet Bricks, all watching the hero groundShadow(ctx, p.x, p.y + 22, 16, 0, { maxHeight: 90, alpha: 0.5 }); Cast.draw(ctx, 'brick', { x: p.x, y: p.y + 4, h: 34, fill: T.stageCrowd, ink: T.stageInk, look: { x: Math.sign(h.x - p.x), y: 0 } }); } }); spot.x.target = h.x; spot.y.target = h.y - 12; spot.x.step(dt); spot.y.step(dt); stage.spotlight(spot.x.value, spot.y.value, 55, { dim: 0.72 }); // [STAGING] light leads the eye });
document.getElementById('act').addEventListener('click', () => { hero = (hero + 1) % actors.length; });});</script></body></html>Staging in CSS
Section titled “Staging in CSS”To feature one item in a group, add .toon-stage to the container. This snippet runs as-is:
<link rel="stylesheet" href="toon.css">
<div class="toon-stage" role="group" aria-label="Cards" style="display:flex; flex-wrap:wrap; gap:10px"> <button aria-pressed="false" style="width:60px; height:80px"> Film</button> <button aria-pressed="true" class="is-featured" style="width:60px; height:80px">Art</button> <button aria-pressed="false" style="width:60px; height:80px"> Music</button> <button aria-pressed="false" style="width:60px; height:80px"> Dance</button></div>
<script>// Pressing a card pins it with .is-featured. Press it again// to unpin it.const cards = document.querySelector('.toon-stage');cards.addEventListener('click', (e) => { const card = e.target.closest('button'); if (!card) return; const pin = !card.classList.contains('is-featured'); for (const c of cards.children) { c.classList.remove('is-featured'); c.setAttribute('aria-pressed', 'false'); } card.classList.toggle('is-featured', pin); card.setAttribute('aria-pressed', String(pin));});</script>Below, Art starts pinned with .is-featured. Hover, tab to or press another card to give it the stage:
Hover or tab to a card to give it the stage. Press a card to pin it, and press it again to let go.
When one child is featured, hovered or focused, its siblings fade to 40% and shrink to 96% in 300 ms. Only opacity and scale change, so the browser can run it on the GPU; for a pointed light instead, lay a .toon-spotlight overlay over the group.
Staging in Canvas
Section titled “Staging in Canvas”Draw the scene, then call stage.spotlight() to darken everything outside a soft circle. The light’s position runs through a Spring, so it glides to each new performer instead of jumping. The performer also stands out by color, size and motion.
<script src="toon.js"></script><canvas style="width:100%; height:180px" role="img" aria-label="A row of balls. One is colored, larger and hops in a spotlight while the gray ones stand still and look at it. Every few seconds the stage passes to the next ball and the spotlight glides over"></canvas>
<script>const { createStage, Spring } = Toon;const stage = createStage(document.querySelector('canvas'));const COUNT = 5, TURN = 2.5; // performers, seconds eachconst xAt = (i) => stage.width * (i + 0.5) / COUNT;// The light follows on a spring, so it glides, not jumps.const glide = { stiffness: 60, damping: 13 };const spotX = new Spring(xAt(0), glide);4 collapsed lines
// Reduced motion: freeze the clock on the first performer.if (matchMedia('(prefers-reduced-motion: reduce)').matches) { Toon.ticker.timeScale = 0;}
stage.loop((dt, time) => { const ctx = stage.ctx, floor = stage.height - 24; const hero = Math.floor(time / TURN) % COUNT;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); for (let i = 0; i < COUNT; i++) { const star = i === hero; // Contrast in size, color and motion: only the star hops. const r = star ? 22 : 15; const hop = star ? Math.abs(Math.sin(time * 5)) * 24 : 0; const x = xAt(i), y = floor - r - hop; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.globalAlpha = star ? 1 : 0.3; // the crowd is gray ctx.fillStyle = star ? fill : ink; ctx.fill(); ctx.globalAlpha = 1; ctx.lineWidth = 2.5; ctx.strokeStyle = ink; ctx.stroke(); // Everyone looks at the star. const look = star ? 0 : Math.sign(xAt(hero) - x) * r * 0.4; ctx.beginPath(); ctx.arc(x + look, y - r * 0.2, 2.5, 0, 7); ctx.fillStyle = ink; ctx.fill(); } spotX.target = xAt(hero); spotX.step(dt); // Dim everything outside the light, inside a stage box. ctx.save(); ctx.beginPath(); ctx.roundRect(0, 8, stage.width, stage.height - 8, 8); ctx.clip(); stage.spotlight(spotX.value, floor - 26, 44, { dim: 0.4 }); ctx.restore();});</script>Staging: tuning tips
Section titled “Staging: tuning tips”- Animate one thing at a time. If everything moves, nothing stands out. Keep the crowd still or on slow idle motion.
- Use several kinds of contrast together. Color, brightness, motion and size reinforce each other. The Canvas snippet uses all four.
- Move focus smoothly. A sudden jump disorients the viewer. A short eased glide (300 ms in CSS, a soft spring in Canvas) keeps their place.
- Fade, don’t blur. Animating
filter: blur()on the background repaints every sibling on every frame. Fading and shrinking reads the same and stays smooth.
In the demo, the crowd drifts on slow noise, a secondary action that keeps the scene alive without pulling focus.
For every option, see the Canvas stage and spotlight and the CSS staging preset.