paper-motion

Light sweep

light-sweep

A card turns in the light and a diagonal glint crosses its face in step with the turn, its edge catching a thin line.

Install
$ npx paper-motion add light-sweep

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

Tune it, then add it to your kit
Parameters
title
line
corner
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>light-sweep</title>
<!--
  Effect · light sweep (4.6 s). A card turns in the light: as it rotates, a diagonal glint crosses its face in step with
  the turn, its edge catches a thin line of light, and the shadow under it slides the other way. A second, fainter glint
  follows. Works on any surface: a card, a logo, a product shot.
  Turn 0.2–3.2 s · Glint 0.9–2.3 s · Second glint 2.2–3.2 s · Hold to 4.6 s.
  Square: a narrower, taller card. Vertical: a portrait card, the title set big (wraps if it must), the bottom line stacked.
-->
<style>
  #stage { overflow: hidden; }
  .abs { position: absolute; box-sizing: border-box; }
  #card { position: absolute; overflow: hidden; box-sizing: border-box; display: flex; flex-direction: column; justify-content: space-between; }
  .glint { position: absolute; inset: -50%; pointer-events: none; mix-blend-mode: screen; }
  #rim { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; }
</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="shadow"></div><div id="card"><div id="top"></div><div id="bot"></div><div id="g1" class="glint"></div><div id="g2" class="glint"></div><div id="rim"></div></div></div>
</main>
<script type="module">
import { scene, progress, ease } from 'paper-motion';
import { camera } from 'paper-motion/kit';
import { loadBrand } from 'paper-motion/brand';

const CONFIG = {
  background: null,
  title: null,
  line: 'Release 0.2.6',
  corner: 'paper-motion.app',
  format: [1920, 1080],
};

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

const DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);
const cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });
const muted = B.color('muted'), figure = '#F2EFE8';   // the card is always dark metal, so its type is always light, whatever the brand's mode
// 16:9 a wide card; square a narrower, taller one; vertical a portrait card whose title is set big and may wrap
const tall = H > W, square = W === H;
const card = $('card'), cw = (tall ? W * 0.72 : square ? W * 0.72 : SHORT * 1.05) * K, ch = cw * (tall ? 1.45 : square ? 0.75 : 0.62), R = cw * 0.05;
Object.assign(card.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, padding: `${cw * 0.06}px`, background: 'linear-gradient(140deg, #232323 0%, #0c0c0c 55%, #1a1a1a 100%)', border: '1px solid #ffffff22' });
const top = B.style($('top'), 'display', { short: SHORT * K, color: 'figure' }); top.style.color = figure; top.textContent = CONFIG.title || B.name; top.style.fontSize = `${tall ? cw * 0.2 : square ? cw * 0.13 : ch * 0.17}px`; if (tall) Object.assign(top.style, { overflowWrap: 'break-word', lineHeight: 1 });
$('bot').innerHTML = `<div style="display:flex;justify-content:space-between;${tall ? 'flex-direction:column;gap:0.5em' : 'align-items:flex-end'};font:400 ${tall ? cw * 0.058 : square ? cw * 0.042 : ch * 0.055}px ${B.font('mono')};color:${muted}"><span style="color:${figure}">${CONFIG.line}</span><span>${CONFIG.corner}</span></div>`;
const shadow = $('shadow');
Object.assign(shadow.style, { position: 'absolute', width: `${cw * 0.9}px`, height: `${ch * 0.25}px`, borderRadius: '50%', background: 'radial-gradient(ellipse, rgba(0,0,0,0.75), transparent 70%)', filter: `blur(${SHORT * 0.02}px)` });
const g1 = $('g1'), g2 = $('g2');
g1.style.background = 'linear-gradient(115deg, transparent 42%, rgba(255,255,255,0.05) 46%, rgba(255,255,255,0.32) 50%, rgba(255,255,255,0.05) 54%, transparent 58%)';
g2.style.background = 'linear-gradient(115deg, transparent 46%, rgba(255,255,255,0.12) 50%, transparent 54%)';
cam.place(card, { x: 0, y: 0, z: 0 });
cam.place(shadow, { x: 0, y: ch * 0.62, z: -SHORT * 0.05, pitch: 80 });
await document.fonts.ready;
// a title too long for the card shrinks until it fits
for (let i = 0; i < 40 && (top.scrollWidth > cw * 0.88 + 1 || top.scrollHeight > ch * 0.6); i++) top.style.fontSize = `${parseFloat(top.style.fontSize) * 0.95}px`;

const T = { turn: [0.2, 3.2], g1: [0.9, 2.3], g2: [2.2, 3.2] };
s.update((t) => {
  const p = progress(t, ...T.turn, ease.inOutCubic);
  const yaw = -30 + 42 * p, pitch = 8 - 10 * p;                     // the card turns through the light
  cam.place(card, { x: 0, y: -ch * 0.04, z: 0, yaw, pitch, roll: -2 + 3 * p });
  cam.place(shadow, { x: -yaw * cw * 0.004, y: ch * 0.6, z: -SHORT * 0.05, pitch: 80 });
  // the glints cross the face in step with the turn
  const a = progress(t, ...T.g1, ease.inOutSine), b = progress(t, ...T.g2, ease.inOutSine);
  g1.style.transform = `translateX(${(-0.6 + 1.2 * a) * cw}px)`; g1.style.opacity = String(Math.sin(a * Math.PI));
  g2.style.transform = `translateX(${(-0.6 + 1.2 * b) * cw}px)`; g2.style.opacity = String(Math.sin(b * Math.PI) * 0.8);
  // the rim catches a line of light on the edge facing it
  const rim = Math.max(0, Math.sin(a * Math.PI)) * 0.9;
  $('rim').style.boxShadow = `inset ${yaw > 0 ? -2 : 2}px 1px 0 rgba(255,255,255,${0.15 + 0.5 * rim})`;
  // the camera: an easy push
  const arrive = progress(t, 0, 0.9, ease.outCubic);
  cam.at({ x: 0, y: 0, z: DIST + SHORT * 0.35 * (1 - arrive) - SHORT * 0.32 * progress(t, 0.9, D, ease.inOutSine), yaw: 0, pitch: 0 });
  card.style.opacity = String(progress(t, 0, 0.3));
});
B.cue(s, 'transition', 0.2); B.cue(s, 'text', T.g1[0]); B.cue(s, 'land', T.turn[1]);
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults

Structure

Light sweep04 / 04
Hold
hold
0.0 / 4.6 s
01Turn
04Hold
02Glint
03Second glint
0 s4.6 s
  1. 010.2–3.2 sTurnturn
  2. 020.9–2.3 sGlintglint
  3. 032.2–3.2 sSecond glintsecond glint
  4. 043.2–4.6 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
light-sweep
Type
Blocks
Version
1.0.0
Engine
>=0.2.6
License
MIT

Related