paper-motion

Bar grow

bar-grow

Bars grow with a short overshoot as the camera passes low along the chart; the winner takes the accent and its number counts up.

Install
$ npx paper-motion add bar-grow

Writes a scene to pieces/, wired to your brand folder.

Tune it, then add it to your kit
Parameters
title
winner
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>bar-grow</title>
<!--
  Data · bar grow (5.5 s). A bar chart stands in space. The baseline draws, the bars grow one after another with a
  short overshoot, and the one that matters takes the accent while its number counts up above it. The camera passes
  along the chart at a low angle and comes round to face the winner, close.
  Arrive 0–0.8 s · Baseline 0.5–1.0 s · Bars 0.9–2.4 s · Winner 2.5 s · Hold to 5.5 s.
  Vertical/square: the chart takes most of the frame width (square: a deeper card; vertical: a tall card with tall
  bars), type is floored from the short side, and the same pass-and-land camera is re-aimed for the taller plot.
-->
<style>
  #stage { overflow: hidden; }
  .abs { position: absolute; box-sizing: border-box; }
  #chart { position: absolute; box-sizing: border-box; }
  #plot { position: absolute; display: flex; align-items: flex-end; }
  .col { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
  .bar { width: 62%; transform-origin: 50% 100%; }
  .val { position: absolute; white-space: nowrap; }
  .lab { position: absolute; bottom: -2.2em; white-space: nowrap; }
  .grid { position: absolute; left: 0; right: 0; height: 1px; }
  #base { position: absolute; left: 0; right: 0; height: 2px; transform-origin: 0 50%; }
</style>
</head>
<body>
<main id="stage">
  <div id="bg" class="abs" style="inset:0"></div>
  <div id="world"><div id="chart"><div id="title"></div><div id="plot"><div id="base"></div></div></div></div>
</main>
<script type="module">
import { scene, progress, ease, spring } from 'paper-motion';
import { blurIn } from 'paper-motion/moves';
import { camera } from 'paper-motion/kit';
import { loadBrand } from 'paper-motion/brand';

const CONFIG = {
  background: null,
  title: 'Renders per week',
  bars: [['W1', 120], ['W2', 180], ['W3', 160], ['W4', 260], ['W5', 310], ['W6', 290], ['W7', 540]],
  winner: 6,
  format: [1920, 1080],
};

const B = await loadBrand();
const [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.5;
const s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });
const bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;
if (bgId) B.shader(s, '#bg', bgId);
document.querySelector('#bg').style.opacity = 0.35;
const $ = (id) => document.getElementById(id);

const DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);
const cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });
const wide = W / H > 1.2, tall = H > W;
const chart = $('chart'), cw = wide ? W * 0.7 * K : W * (tall ? 0.86 : 0.84) * K, ch = cw * (wide ? 0.5 : tall ? 1.55 : 0.66), R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;
const ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');
Object.assign(chart.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: B.surface(0.16), border: `1.5px solid ${muted}44`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${wide ? cw * 0.016 : SHORT * K * 0.024}px` });
const title = B.style($('title'), 'title', { short: SHORT * K, color: 'figure' });
Object.assign(title.style, { position: 'absolute', left: `${cw * 0.05}px`, top: `${ch * 0.07}px`, fontSize: `${wide ? ch * 0.065 : SHORT * K * 0.05}px` });
title.textContent = CONFIG.title;
const plot = $('plot'), px = cw * 0.06, pw = cw * 0.88, py = ch * (wide ? 0.27 : tall ? 0.17 : 0.25), ph = ch * (wide ? 0.56 : tall ? 0.72 : 0.6);
Object.assign(plot.style, { left: `${px}px`, top: `${py}px`, width: `${pw}px`, height: `${ph}px`, gap: `${pw * 0.015}px` });
const max = Math.max(...CONFIG.bars.map(([, v]) => v)) * 1.12;
for (let g = 1; g <= 3; g++) { const l = document.createElement('div'); l.className = 'grid'; l.style.bottom = `${(g / 3) * 100}%`; l.style.background = `${muted}22`; plot.append(l); }
$('base').style.bottom = '0'; $('base').style.background = `${muted}88`;
const cols = CONFIG.bars.map(([lab, v], i) => {
  const c = document.createElement('div'); c.className = 'col';
  const win = i === CONFIG.winner;
  c.innerHTML = `<div class="val" style="font:500 1.15em ${B.font('mono')};color:${win ? accent : muted}"></div><div class="bar" style="height:${(v / max) * 100}%;border-radius:${R * 0.4}px ${R * 0.4}px 0 0;background:${win ? `${muted}55` : `${muted}55`}"></div><div class="lab" style="font:400 0.95em ${B.font('mono')};color:${muted}">${lab}</div>`;
  plot.append(c);
  return { c, bar: c.querySelector('.bar'), val: c.querySelector('.val'), v, win };
});
cam.place(chart, { x: 0, y: 0, z: 0 });
await document.fonts.ready;

const T = { base: [0.5, 1.0], bars: 0.9, each: 0.16, win: 2.5 };
const wi = CONFIG.winner, wx = px + (pw / CONFIG.bars.length) * (wi + 0.5) - cw / 2;
const wTop = py + ph * (1 - CONFIG.bars[wi][1] / max) - ch / 2;
s.update((t) => {
  $('base').style.transform = `scaleX(${progress(t, ...T.base, ease.inOutCubic)})`;
  blurIn(title, t, { start: 0.4, duration: 0.6 });
  cols.forEach(({ bar, val, v, win }, i) => {
    const a = T.bars + i * T.each, g = t >= a ? spring(t - a, { stiffness: 150, damping: 11 }) : 0;
    bar.style.transform = `scaleY(${Math.max(0, g)})`;
    // the winner turns to the accent and grows a glow; its number counts up; the others show theirs quietly
    const w = win ? progress(t, T.win, T.win + 0.5, ease.outCubic) : 0;
    bar.style.background = win && w ? accent : `${muted}55`;
    bar.style.opacity = win ? String(0.75 + 0.25 * w) : String(1 - 0.35 * progress(t, T.win, T.win + 0.5));
    bar.style.boxShadow = w ? `0 0 ${SHORT * 0.06 * w}px ${accent}55` : 'none';
    const shown = win ? Math.round(v * progress(Math.round(t * 30) / 30, T.win, T.win + 0.9, ease.outCubic)) : v;   // one value per frame
    val.textContent = String(shown);
    const vin = win ? progress(t, T.win, T.win + 0.3) : progress(t, a + 0.25, a + 0.5) * (1 - 0.5 * progress(t, T.win, T.win + 0.5));
    val.style.opacity = String(vin);
    val.style.bottom = `calc(${(v / max) * 100 * Math.max(0, Math.min(1.05, g))}% + 0.6em)`;
    if (win) val.style.fontSize = `${1.15 + 1.4 * w}em`;
  });
  // the camera: low and from the side, travelling along the chart, then round to face the winner, close
  const arrive = progress(t, 0, 0.8, ease.outCubic), pass = progress(t, 0.3, T.win + 0.2, ease.inOutCubic), land = progress(t, T.win - 0.4, D - 0.4, ease.inOutCubic);
  if (!wide) {
    // the same pass at a low angle, re-aimed: the land frames the winner's bar and its number, close
    const wMid = py + ph * (1 - CONFIG.bars[wi][1] / max * 0.5) - ch / 2;
    cam.at({
      x: -cw * 0.3 + (wx * 0.75 + cw * 0.3) * pass,
      y: ch * 0.1 * (1 - pass) + (tall ? (wTop * 0.15 + wMid * 0.85) : wTop * 0.55) * land,
      z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.12 * pass - SHORT * (tall ? 0.42 : 0.45) * land,
      yaw: -24 * (1 - pass) + 4 * (1 - land) * pass, pitch: -10 * (1 - pass) - 2 * pass,
    });
  } else
  cam.at({
    x: -cw * 0.3 + (wx * 0.82 + cw * 0.3) * pass,
    y: ch * 0.12 * (1 - pass) + (wTop * 0.55) * land,
    z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.15 * pass - SHORT * 0.5 * land,
    yaw: -26 * (1 - pass) + 4 * (1 - land) * pass, pitch: -10 * (1 - pass) - 2 * pass,
  });
  chart.style.opacity = String(progress(t, 0, 0.3));
});
B.cue(s, 'transition', 0); B.cue(s, 'text', T.bars); B.cue(s, 'land', T.win);
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults

Structure

Bar grow01 / 05
Arrive
arrive
0.0 / 5.5 s
01Arrive
03Bars
04Winner
05Hold
0 s5.5 s
  1. 010–0.8 sArrivearrive
  2. 020.5–1 sBaselinebaseline
  3. 030.9–2.4 sBarsbars
  4. 042.5–3.1 sWinnerwinner
  5. 053.1–5.5 sHoldhold

The script, sketched: the beats in order and their length, in the brand's colors and type. The clip above is the engine's render of the same recipe.

Notes

  • Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work) and, for the field, a shader-set entry.
  • Recomposes for 16:9, 9:16 and 1:1: set format and the layout and camera follow.

Spec

Id
bar-grow
Type
Blocks
Version
1.0.0
Engine
>=0.2.6
License
MIT

Related