Skip to content

Arcs

Move along curves, not straight lines: throws, swings, paths.

Edit this page

Almost nothing in nature moves in a straight line. A thrown ball traces a curve (a parabola), a turning head sweeps an arc, and a waving hand follows a curve. Straight-line motion reads as robotic.

Now showing: ArcsOpen the Arcs 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>07 · Arcs — 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: 360px; margin: var(--space-sm) 0; cursor: crosshair; }
</style>
</head>
<body>
<h1>Arcs</h1>
<p>Living things and thrown objects move on curves. The comet follows <code>path()</code>, a smooth curve through a few points.</p>
<label><input id="useArc" type="checkbox" checked> Use an arc</label>
<canvas id="c" style="cursor:pointer" role="img" aria-label="Dot is thrown along a curved path and leaves a dotted trail, while a comet follows a wavy path above. With arcs switched off, Dot travels in a straight line instead."></canvas>
<p class="demo-try"><button type="button" class="demo-act" id="act">Throw</button> Press <i>Throw</i> or click the canvas to throw Dot there. Untick <i>Use an arc</i> to see the same throw as a straight, mechanical line.</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('07-arcs', (document, Toon, DemoTheme) => {
const T = DemoTheme; // design tokens, live (see demo-theme.js)
const { createStage, ticker, tween, ease, arc, path, squash, withSquash, lerp } = Toon;
const stage = createStage(document.getElementById('c'));
const { ctx } = stage;
const useArc = document.getElementById('useArc');
const DUR = 900;
let flight = null, lastThrow = -9;
function throwTo(p1) {
const p0 = { x: 50, y: stage.height - 50 };
const fn = useArc.checked
? arc(p0, p1, { height: 90 + Math.random() * 60 }) // [ARCS] ballistic parabola
: t => ({ x: lerp(p0.x, p1.x, t), y: lerp(p0.y, p1.y, t) });
const f = (flight = { fn, t: 0 });
tween({ duration: DUR, ease: ease.linear, onUpdate: v => (f.t = v) });
lastThrow = ticker.time;
}
stage.canvas.addEventListener('click', e => {
const r = stage.canvas.getBoundingClientRect(); throwTo({ x: e.clientX - r.left, y: e.clientY - r.top });
});
const W = () => stage.width, H = () => stage.height;
const comet = path([0.08, 0.3, 0.5, 0.7, 0.92].map((x, i) => ({ x, y: i % 2 ? 0.12 : 0.3 })));
let cometT = 0;
tween({ duration: 3200, ease: ease.inOutSine, repeat: Infinity, yoyo: true, onUpdate: v => (cometT = v) });
stage.loop(() => {
if (ticker.time - lastThrow > 2) throwTo({ x: W() * (0.45 + Math.random() * 0.45), y: H() * (0.45 + Math.random() * 0.4) });
stage.clear();
// comet on a spline, with a fading tail sampled behind it
ctx.strokeStyle = T.faint; ctx.lineWidth = 2; ctx.beginPath();
for (let i = 0; i <= 60; i++) { const p = comet(i / 60); ctx.lineTo(p.x * W(), p.y * H()); } ctx.stroke();
for (let i = 10; i >= 0; i--) {
const p = comet(Math.max(0, cometT - i * 0.008));
ctx.fillStyle = T.alpha(T.tertiary, 1 - i / 11); ctx.beginPath(); ctx.arc(p.x * W(), p.y * H(), 8 - i * 0.5, 0, 7); ctx.fill();
}
// hand
ctx.fillStyle = T.ground; ctx.strokeStyle = T.groundLine; ctx.lineWidth = 2;
ctx.beginPath(); ctx.arc(50, H() - 50, 18, 0, 7); ctx.fill(); ctx.stroke();
if (!flight) return;
const { fn, t: ft } = flight;
ctx.setLineDash([4, 6]); ctx.strokeStyle = T.faint; ctx.beginPath(); // planned path
for (let i = 0; i <= 40; i++) { const p = fn(i / 40); ctx.lineTo(p.x, p.y); } ctx.stroke(); ctx.setLineDash([]);
for (let i = 0; i < ft * 14; i++) { // spacing ghosts
const p = fn(i / 14); ctx.fillStyle = T.alpha(T.secondary, .4); ctx.beginPath(); ctx.arc(p.x, p.y, 4, 0, 7); ctx.fill();
}
const a = fn(ft), b = fn(Math.min(1, ft + 0.01)), k = 1000 / (0.01 * DUR); // velocity in px/s
const s = ft < 1 ? squash((b.x - a.x) * k, (b.y - a.y) * k, { amount: 0.0006 }) : { };
const look = { x: Math.sign(b.x - a.x), y: Math.max(-1, Math.min(1, (b.y - a.y) * k / 600)) }; // eyes on the landing spot
withSquash(ctx, a.x, a.y, s, c => Cast.draw(c, 'dot', { x: 0, y: 0, h: 34, fill: T.primary, ink: T.ink, look,
mood: ft < 1 ? 'happy' : 'neutral' }));
});
document.getElementById('act').addEventListener('click', () => throwTo({ x: stage.width * 0.75, y: stage.height * 0.55 }));
});
</script>
</body>
</html>

Wrap an element in .toon-arc to make it hop --toon-distance along a parabola. This snippet runs as-is:

<link rel="stylesheet" href="toon.css">
<!-- The ball rises 100px: leave room above it. -->
<div style="padding-top:110px">
<div class="toon-arc toon-loop toon-yoyo" style="width:32px;
--toon-distance:200px; --toon-height:100px">
<div style="width:32px; height:32px; border-radius:50%;
background:var(--toon-color)"></div>
</div>
</div>

Below, the same hop over a dashed line that traces its path:

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

The wrapper moves sideways at a steady speed while its child rises and falls on gravity easing, and together they trace a real parabola. .toon-loop and .toon-yoyo on the wrapper make it hop back and forth, and its child follows along.

This throw runs as-is. arc() returns a curve from one point to another, and moving along it at a steady speed (linear timing) gives a real throw. tangent() gives the direction of travel, so the bean faces where it’s going.

  • Keep the timing linear. Easing the progress along arc() makes the throw float or slam. A tween with ease.linear does the same job as the steady clock in the snippet.
  • Curve through more points with path(). It draws a smooth curve through every point you give it (a Catmull-Rom curve), and tangent() works on it too.
  • Check your arcs with ghosts. Plot past positions, as the demos do. Kinks and flat spots show up immediately.
  • Curve interface paths too. A slight curve on a card flying to a cart, or a dialog swooping in, feels more natural than a straight slide.

The arcs demo also shows squash and stretch: Dot stretches along the direction of travel. The throwing recipe adds that to an arc.

For every option, see the Canvas motion paths and the CSS .toon-arc preset.