Before / after
before-afterTwo states of the same thing in one panel: the old one muted, a wipe, the new one in the brand's colors, then the close, in 16 s.
Install
$ npx paper-motion add before-afterWrites a scene to pieces/, wired to your brand folder.
Tune it, then add it to your kit
Parameters
beforeTag
beforeLine
afterTag
afterLine
action
background
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>before-after</title>
<!--
Recipe · before / after (16 s). Two states of the same thing, one wipe between them.
One idea: the panel is a slab standing in space. The camera meets the BEFORE from the side, flat and grey, almost
in profile; as a plane sweeps across the slab the camera swings around to face it, and the AFTER arrives with depth:
its label and its line float in front of the slab and parallax as the camera keeps turning slowly. The close is the
camera leaving past the edge of the slab toward the name.
Before 0–6 s · Wipe 6–7.5 s · After 7.5–13 s · Close 13–16 s.
Look, fonts, pace and sound come from /brand (serve from the project root). Edit CONFIG first: a real picture of each
state (`image`) beats any panel; without one, each state is a panel with its line.
-->
<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; }
.state { position: absolute; inset: 0; overflow: hidden; }
.state 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="panel"></div>
<div id="tag-before"></div><div id="line-before"></div>
<div id="tag-after"></div><div id="line-after"></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, wipe } from 'paper-motion/moves';
import { camera } from 'paper-motion/kit';
import { loadBrand } from 'paper-motion/brand';
const CONFIG = {
background: null,
before: { tag: 'Before', line: 'Forty minutes, three tools, one guess.', image: '' },
after: { tag: 'After', line: 'One command. Every frame on purpose.', image: '' },
action: 'your.site',
format: [1920, 1080],
};
const B = await loadBrand();
const [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 16;
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 = 0.45;
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);
const DIST = SHORT * 0.7, K = 1 + DIST / (SHORT * 1.7), STEP = SHORT * 1.6;
const cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });
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', marginTop: `${SHORT * 0.03}px` });
mark.textContent = B.name; action.textContent = CONFIG.action;
$('p-close').style.width = `${W * 0.9}px`;
cam.place($('p-close'), { x: STEP, yaw: -8 });
// the slab: both states fill it; the wipe runs inside
const R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;
const panel = $('panel'), pw = W * 0.6 * K, ph = pw * 0.56;
Object.assign(panel.style, { width: `${pw}px`, height: `${ph}px`, borderRadius: `${R}px`, overflow: 'hidden', border: `1.5px solid ${B.color('muted')}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)` });
cam.place(panel, { x: 0, y: 0, z: 0 });
const state = (cfg, after) => {
const el = document.createElement('div');
el.className = 'state';
el.style.background = after ? B.surface() : '#262626';
if (cfg.image) { const img = document.createElement('img'); img.src = cfg.image; if (!after) img.style.filter = 'grayscale(1) contrast(0.9) brightness(0.7)'; el.append(img); }
else if (after && bgId) { const f = document.createElement('div'); Object.assign(f.style, { position: 'absolute', inset: 0, opacity: 0.85 }); el.append(f); B.shader(s, f, bgId); }
else { el.style.background = 'linear-gradient(160deg, #2c2c2c, #1a1a1a)'; }
const band = document.createElement('div'); Object.assign(band.style, { position: 'absolute', left: 0, right: 0, bottom: 0, height: '55%', background: `linear-gradient(to top, ${after ? B.color('ground') : '#000000'}dd 0%, transparent 100%)` }); el.append(band);
panel.append(el);
return el;
};
const before = state(CONFIG.before, false), after = state(CONFIG.after, true);
// the words float in front of the slab: the before ones flat on it, the after ones a step closer (they parallax)
const tagOf = (id, cfg, after) => {
const tag = B.style($(id), 'caption', { short: SHORT * K, color: after ? 'ground' : 'figure' });
Object.assign(tag.style, { fontFamily: B.font('mono'), padding: `${SHORT * 0.007 * K}px ${SHORT * 0.014 * K}px`, borderRadius: `${R * 0.5}px`, background: after ? B.color('accent', '#E9E4D8') : '#ffffff22', color: after ? B.color('ground') : '#ddd', whiteSpace: 'nowrap' });
tag.textContent = cfg.tag;
cam.place(tag, { x: -pw / 2 + pw * 0.08 + tag.offsetWidth / 2, y: -ph / 2 + ph * 0.1, z: after ? SHORT * 0.12 : SHORT * 0.01 });
return tag;
};
const lineOf = (id, cfg, after) => {
const line = B.style($(id), 'title', { short: SHORT * K, color: 'figure' });
Object.assign(line.style, { width: `${pw * 0.9}px`, textAlign: 'left', color: after ? B.color('figure') : '#cfcfcf', textShadow: '0 2px 24px rgba(0,0,0,0.6)' });
line.textContent = cfg.line;
cam.place(line, { x: 0, y: ph / 2 - ph * 0.2, z: after ? SHORT * 0.16 : SHORT * 0.01 });
return line;
};
await document.fonts.ready;
const tagB = tagOf('tag-before', CONFIG.before, false), lineB = lineOf('line-before', CONFIG.before, false);
const tagA = tagOf('tag-after', CONFIG.after, true), lineA = lineOf('line-after', CONFIG.after, true);
for (const el of [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 camera: in profile on the before, swinging to face the after as the plane crosses, then slowly on, then away
const T = { wipe: [6, 7.5], close: [12.8, 13.8] };
const path = [
[0, { x: -SHORT * 0.5, y: SHORT * 0.02, z: DIST * 1.05, yaw: -34, pitch: 3 }],
[1.0, { x: -SHORT * 0.42, yaw: -30 }, ease.outCubic],
[T.wipe[0] - 0.4, { x: -SHORT * 0.3, yaw: -24 }],
[T.wipe[1] + 0.3, { x: 0, y: 0, z: DIST, yaw: 0, pitch: 0 }, ease.inOutCubic], // the swing: face on with the after
[T.close[0] - 0.4, { x: SHORT * 0.08, yaw: 7, pitch: -1, z: DIST * 0.96 }, ease.inOutSine], // a slow turn the other way
[T.close[1] + 0.3, { x: STEP, y: 0, z: DIST, yaw: 0, pitch: 0 }, ease.inOutQuart],
[D, { x: STEP, z: DIST * 0.92 }, ease.inOutSine],
];
const RESET = ['transform', 'opacity', 'filter', 'clipPath', 'zIndex'];
s.update((t) => {
cam.travel(t, path);
cam.focus(DIST, SHORT * 1.1, 8);
bg.style.transform = `scale(${1.1 + 0.06 * progress(t, 0, D)}) translateX(${SHORT * 0.05 * progress(t, 0, D)}px)`;
// the plane crosses the slab; the before words leave with it, the after words arrive just behind it
RESET.forEach((k) => { before.style[k] = ''; after.style[k] = ''; });
before.style.zIndex = 1; after.style.zIndex = 2;
if (t < T.wipe[0]) { before.style.opacity = 1; after.style.opacity = 0; }
else if (t < T.wipe[1]) wipe(before, after, progress(t, ...T.wipe));
else { before.style.opacity = 0; after.style.opacity = 1; }
blurIn(tagB, t, { start: 0.6, duration: 0.6 }); wordRise(lineB, t, { start: 1.0, each: B.pace.stagger, duration: 0.8 });
const outB = progress(t, T.wipe[0], T.wipe[0] + 0.6, ease.inCubic);
if (outB > 0) { tagB.style.opacity = String(Math.min(Number(tagB.style.opacity || 1), 1 - outB)); lineB.style.opacity = String(Math.min(Number(lineB.style.opacity || 1), 1 - outB)); }
blurIn(tagA, t, { start: T.wipe[1] - 0.1, duration: 0.6 }); wordRise(lineA, t, { start: T.wipe[1] + 0.1, each: B.pace.stagger, duration: 0.8 });
wordRise(mark, t, { start: T.close[0] + 0.25, each: B.pace.stagger, duration: 0.9 });
blurIn(action, t, { start: T.close[1] + 0.5, duration: 0.8 });
});
B.cue(s, 'land', 1.0); B.cue(s, 'transition', T.wipe[0]); B.cue(s, 'land', T.wipe[1] + 0.1); B.cue(s, 'transition', T.close[0]); B.cue(s, 'land', T.close[1] + 0.3);
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults
Structure
Before / after01 / 04
Before
the old state: muted panel, its line
0.0 / 16 s
01Before
03After
04Close
0 s16 s
- 010–6 sBeforethe old state: muted panel, its line
- 026–7.5 sWipethe new state sweeps in
- 037.5–13 sAfterthe brand's state, the accent, its line
- 0413–16 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).
- A real picture of each state beats any panel; the before picture is shown desaturated.
- Uses these moves from the engine: wipe, word-rise, blur-in, crossfade.
Spec
- Id
- before-after
- Type
- Recipes
- Version
- 1.0.0
- Engine
- >=0.2.1
- License
- MIT