paper-motion

Three things

three-things

Three traits, features or reasons, each with its own mechanic: one rises, two pushes, three flips; a card with words and the brand's material (or a picture), then the close, in 22 s.

Install
$ npx paper-motion add three-things

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

Tune it, then add it to your kit
Parameters
intro
action
background
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>three-things</title>
<!--
  Recipe · three things (22 s). Three traits, features or reasons.
  One idea: the three cards hang in a column in space, one under the other, each turned a little the other way.
  The camera starts on the name above them, then DESCENDS the column, orbiting as it goes (yaw swings left, right,
  left), so every card is met from its own angle and the previous one leaves above, out of focus. The close is the
  camera coming to rest under the last card, straight.
  Intro 0–2.5 s · One 2.5–8 s · Two 8–13.5 s · Three 13.5–19 s · Close 19–22 s.
  Look, fonts, pace and sound come from /brand (serve from the project root). Edit CONFIG first; put real material
  (a screenshot, a photo) in a card's `image` when there is some.
-->
<style>
  #stage { overflow: hidden; }
  .abs { position: absolute; box-sizing: border-box; }
  .place { display: flex; flex-direction: column; align-items: center; text-align: center; box-sizing: border-box; }
  .card { box-sizing: border-box; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
  .card .words { display: flex; flex-direction: column; justify-content: center; text-align: left; }
  .card .pic { position: relative; overflow: hidden; }
  .card .pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
</style>
</head>
<body>
<main id="stage">
  <div id="bg" class="abs" style="inset:0"></div>
  <div id="vig" class="abs" style="inset:0"></div>
  <div id="world">
    <div id="p-intro" class="place"><div id="name"></div><div id="intro"></div></div>
    <div id="p-close" class="place"><div id="mark"></div><div id="action"></div></div>
  </div>
</main>
<script type="module">
import { scene, progress, ease } from 'paper-motion';
import { wordRise, blurIn, popIn } from 'paper-motion/moves';
import { camera } from 'paper-motion/kit';
import { loadBrand } from 'paper-motion/brand';

const CONFIG = {
  background: null,
  backgroundOpacity: 0.5,
  intro: 'Three things to know.',
  things: [
    { label: '01', title: 'Fast', body: 'A real number, a real result.', image: '' },
    { label: '02', title: 'Simple', body: 'What it replaces, in one line.', image: '' },
    { label: '03', title: 'Yours', body: 'Who it is for, and why now.', image: '' },
  ],
  action: 'your.site',
  format: [1920, 1080],
};

const B = await loadBrand();
const [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 22, tall = H > W;
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);
const bg = document.querySelector('#bg'); bg.style.opacity = CONFIG.backgroundOpacity;
document.querySelector('#vig').style.background = 'radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.6) 100%)';
const $ = (id) => document.getElementById(id);

// the column: one place per beat, a step of STEP down; the camera reads each from DIST in front
const STEP = SHORT * 1.15, DIST = SHORT * 0.7, K = 1 + DIST / (SHORT * 1.7);
const cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });
const name = B.style($('name'), 'display', { short: SHORT * K }), intro = B.style($('intro'), 'title', { short: SHORT * K, color: 'muted' });
const mark = B.style($('mark'), 'display', { short: SHORT * K }), action = B.style($('action'), 'body', { short: SHORT * K, color: 'figure' });
Object.assign(action.style, { fontFamily: B.font('mono'), fontSize: `${SHORT * K * 0.028}px`, letterSpacing: '0em' });
intro.style.marginTop = action.style.marginTop = `${SHORT * 0.03}px`;
name.textContent = mark.textContent = B.name; intro.textContent = CONFIG.intro; action.textContent = CONFIG.action;
for (const id of ['p-intro', 'p-close']) $(id).style.width = `${W * 0.9}px`;
const Y = (i) => i * STEP;
cam.place($('p-intro'), { y: Y(0) });
const R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;
const cw = (tall ? W * 0.84 : SHORT * 1.1) * K, ch = (tall ? H * 0.5 : cw * 0.52);
const cards = CONFIG.things.map((p, i) => {
  const c = document.createElement('div');
  c.className = 'card';
  Object.assign(c.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: B.surface(), border: `1.5px solid ${B.color('muted')}55`, boxShadow: `0 ${SHORT * 0.03}px ${SHORT * 0.1}px rgba(0,0,0,0.5)`, gridTemplateColumns: tall ? '1fr' : '1fr 1fr', direction: i % 2 ? 'rtl' : 'ltr' });
  c.innerHTML = `<div class="words" style="direction:ltr;padding:${cw * 0.06}px"><div data-part="label"></div><div data-part="title"></div><div data-part="body"></div></div><div class="pic" data-part="pic"></div>`;
  const [label, title, body] = [...c.querySelector('.words').children];
  B.style(label, 'caption', { short: SHORT * K, color: 'muted' }).textContent = p.label;
  B.style(title, 'display', { short: SHORT * K * 0.7, color: 'figure' }).textContent = p.title;
  B.style(body, 'body', { short: SHORT * K, color: 'muted' }).textContent = p.body;
  title.style.marginTop = `${SHORT * 0.02}px`; body.style.marginTop = `${SHORT * 0.02}px`;
  Object.assign(body.style, { fontSize: `${SHORT * K * 0.03}px`, lineHeight: 1.35, maxWidth: '24ch' });
  const pic = c.querySelector('.pic');
  if (p.image) { const img = document.createElement('img'); img.src = p.image; pic.append(img); }
  else { pic.style.background = i === 1 ? B.color('accent', '#E9E4D8') : B.color('ground'); if (bgId && i !== 1) B.shader(s, pic, bgId); }
  if (tall) pic.style.display = 'none';
  $('world').append(c);
  // one under the other, each turned the other way and a touch nearer or farther
  cam.place(c, { y: Y(1 + i), x: [-1, 1, -1][i] * SHORT * 0.05, z: [0, -SHORT * 0.08, SHORT * 0.04][i], yaw: [12, -14, 10][i], pitch: [-3, 2, -2][i] });
  return c;
});
cam.place($('p-close'), { y: Y(4) });
await document.fonts.ready;
for (const el of [name, mark]) { el.style.whiteSpace = 'nowrap'; const k = (W * 0.84) / el.scrollWidth; if (k < 1) el.style.fontSize = `${parseFloat(el.style.fontSize) * k}px`; }

// the descent: the camera swings around the column as it drops from card to card
const T = { one: 2.5, two: 8, three: 13.5, close: 19 };
const at = (i, extra = {}) => ({ y: Y(i), z: DIST, ...extra });
const path = [
  [0, at(0, { x: 0, yaw: 0, pitch: 0 })],
  [T.one - 0.5, at(0, { pitch: 3 })],
  [T.one + 1.0, at(1, { x: -SHORT * 0.04, yaw: 14, pitch: -2 }), ease.inOutCubic],
  [T.two - 0.6, at(1, { yaw: 17 })],
  [T.two + 1.0, at(2, { x: SHORT * 0.05, z: DIST - SHORT * 0.08, yaw: -16, pitch: 2 }), ease.inOutCubic],
  [T.three - 0.6, at(2, { z: DIST - SHORT * 0.08, yaw: -19 })],
  [T.three + 1.0, at(3, { x: -SHORT * 0.04, z: DIST + SHORT * 0.04, yaw: 12, pitch: -2 }), ease.inOutCubic],
  [T.close - 0.6, at(3, { z: DIST + SHORT * 0.04, yaw: 15 })],
  [T.close + 1.1, at(4, { x: 0, yaw: 0, pitch: 0 }), ease.inOutQuart],
  [D, at(4, { z: DIST * 0.92 }), ease.inOutSine],
];
const words = cards.map((c) => [...c.querySelector('.words').children]);
s.update((t) => {
  cam.travel(t, path);
  cam.focus(DIST, SHORT * 0.9, 10, { fade: SHORT * 0.62 });   // a column: places leave through the top and bottom edges, so they fade sooner
  bg.style.transform = `scale(${1.08 + 0.08 * progress(t, 0, D)}) translateY(${-SHORT * 0.05 * progress(t, 0, D)}px)`;
  wordRise(name, t, { start: 0.2, each: B.pace.stagger, duration: 0.9 });
  blurIn(intro, t, { start: 0.9, duration: 0.9 });
  // three ways in for three things: words rise, pop, rise again with a longer stagger
  const starts = [T.one, T.two, T.three];
  wordRise(words[0][1], t, { start: starts[0], each: B.pace.stagger, duration: 0.8 }); blurIn(words[0][2], t, { start: starts[0] + 0.5, duration: 0.7 });
  popIn(words[1][1], t, { start: starts[1] }); blurIn(words[1][2], t, { start: starts[1] + 0.5, duration: 0.7 });
  wordRise(words[2][1], t, { start: starts[2], each: B.pace.stagger * 2, duration: 1.0 }); blurIn(words[2][2], t, { start: starts[2] + 0.6, duration: 0.7 });
  wordRise(mark, t, { start: T.close - 0.1, each: B.pace.stagger, duration: 0.9 });
  blurIn(action, t, { start: T.close + 0.7, duration: 0.8 });
});
B.cue(s, 'land', 0.2); B.cue(s, 'transition', T.one); B.cue(s, 'land', T.one + 0.6); B.cue(s, 'transition', T.two); B.cue(s, 'land', T.two + 0.6);
B.cue(s, 'transition', T.three); B.cue(s, 'land', T.three + 0.6); B.cue(s, 'transition', T.close); B.cue(s, 'land', T.close + 0.8);
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults

Structure

Three things01 / 05
Intro
the name and the line
0.0 / 22 s
01Intro
02One
03Two
04Three
05Close
0 s22 s
  1. 010–2.5 sIntrothe name and the line
  2. 022.5–8 sOnethe card rises in, its words follow
  3. 038–13.5 sTwopushes the first up
  4. 0413.5–19 sThreeflips in
  5. 0519–22 sClosethe wordmark and the action

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: pamo add sage-night instrument) and, for the background, a shader-set entry (pamo add mesh-sage).
  • Three mechanics for three things (rise, push, flip): swap any of them for the moves the user chose.
  • Uses these moves from the engine: word-rise, pop-in, blur-in, push, flip-3d, crossfade.

Spec

Id
three-things
Type
Recipes
Version
1.0.0
Engine
>=0.2.1
License
MIT

Related