paper-motion

Dither dissolve

dither-dissolve

One shot breaks into an ordered dither, dot by dot, in a sweep across the frame; the edge lights in the accent and the next shot is under it.

Install
$ npx paper-motion add dither-dissolve

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

Tune it, then add it to your kit
Parameters
a
b
bLine
cell
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>dither-dissolve</title>
<!--
  Transition · dither dissolve (4.6 s). The first shot breaks into an ordered dither, dot by dot, in a sweep across the
  frame; the dissolving edge lights up in the accent as it passes, and the second shot is underneath. Both shots keep
  a slow push so the cut never feels still.
  Shot A 0–1.4 s · Dissolve 1.4–2.9 s · Shot B to 4.6 s.
  Square and vertical: type fits the width with a margin; vertical sets it bigger and breaks the name at its hyphen.
-->
<style>
  #stage { overflow: hidden; }
  .abs { position: absolute; box-sizing: border-box; }
  .shot { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
  #edge { position: absolute; left: 0; top: 0; }
</style>
</head>
<body>
<main id="stage">
  <div id="b" class="shot"><div id="bbg" class="abs" style="inset:0"></div><div id="bt" style="position:relative"></div><div id="bs" style="position:relative"></div></div>
  <div id="a" class="shot"><div id="at"></div></div>
  <canvas id="edge"></canvas>
</main>
<script type="module">
import { scene, progress, ease } from 'paper-motion';
import { wordRise, blurIn } from 'paper-motion/moves';
import { loadBrand } from 'paper-motion/brand';

const CONFIG = {
  background: null,
  a: 'Tools were made for hands.',
  b: null,
  bLine: 'Brand videos, made by your coding agent.',
  cell: 14,
  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, '#bbg', bgId);
const $ = (id) => document.getElementById(id);
const ground = B.color('ground'), accent = B.color('accent', '#E9E4D8');
$('a').style.background = ground;
const at = B.style($('at'), 'display', { short: SHORT, color: 'figure' }); at.textContent = CONFIG.a; at.style.fontSize = `${SHORT * 0.11}px`; at.style.maxWidth = '12ch';
const bt = B.style($('bt'), 'display', { short: SHORT, color: 'figure' }); bt.textContent = CONFIG.b || B.name; bt.style.fontSize = `${SHORT * 0.15}px`; bt.style.textShadow = '0 4px 40px rgba(0,0,0,0.5)';
const bs = B.style($('bs'), 'title', { short: SHORT, color: 'figure' }); bs.textContent = CONFIG.bLine; bs.style.marginTop = `${SHORT * 0.02}px`; bs.style.opacity = 0.85;
$('b').style.background = ground;
await document.fonts.ready;
// outside 16:9 the type is set from the width: vertical sets it bigger (the name may break at its hyphen), and anything
// wider than the frame minus a margin (and the push) shrinks until it fits
if (W <= H) {
  const tall = H > W, room = W * 0.78;
  if (tall) {
    at.style.fontSize = `${W * 0.15}px`; at.style.maxWidth = `${room}px`;
    Object.assign(bt.style, { fontSize: `${W * 0.21}px`, maxWidth: `${room}px`, lineHeight: 0.95 });
    Object.assign(bs.style, { fontSize: `${W * 0.08}px`, maxWidth: `${room}px`, marginTop: `${W * 0.05}px` });
  }
  if (!tall) bs.style.fontSize = `${W * 0.052}px`;
  Object.assign(bs.style, { whiteSpace: 'normal', textWrap: 'balance', maxWidth: `${room}px`, marginLeft: 'auto', marginRight: 'auto' });   // the line wraps rather than shrinks
  for (const el of [at, bt, bs]) for (let n = 0; n < 60 && el.scrollWidth > room + 1; n++) el.style.fontSize = `${parseFloat(el.style.fontSize) * 0.96}px`;
}

// the dither: an 8×8 Bayer matrix biased by a diagonal sweep; a cell is gone once the progress passes its threshold
const cell = CONFIG.cell * SHORT / 1080, cols = Math.ceil(W / cell), rows = Math.ceil(H / cell);
const bayer = [[0, 32, 8, 40, 2, 34, 10, 42], [48, 16, 56, 24, 50, 18, 58, 26], [12, 44, 4, 36, 14, 46, 6, 38], [60, 28, 52, 20, 62, 30, 54, 22], [3, 35, 11, 43, 1, 33, 9, 41], [51, 19, 59, 27, 49, 17, 57, 25], [15, 47, 7, 39, 13, 45, 5, 37], [63, 31, 55, 23, 61, 29, 53, 21]];
const thr = new Float32Array(cols * rows);
for (let y = 0; y < rows; y++) for (let x = 0; x < cols; x++) {
  const sweep = (x / cols) * 0.7 + (1 - y / rows) * 0.3;             // left-to-right, a little from the bottom
  thr[y * cols + x] = sweep * 0.62 + (bayer[y % 8][x % 8] / 64) * 0.38;
}
// the mask for shot A, drawn small and scaled up; and the edge canvas, drawn at full size
const mc = document.createElement('canvas'); mc.width = cols; mc.height = rows; const mx = mc.getContext('2d');
const edge = $('edge'); edge.width = W; edge.height = H; edge.style.width = `${W}px`; edge.style.height = `${H}px`; const ex = edge.getContext('2d');
const a = $('a');
Object.assign(a.style, { webkitMaskSize: '100% 100%', maskSize: '100% 100%', imageRendering: 'pixelated' });
const T = { dis: [1.4, 2.9] };
const band = 0.06;

s.update((t) => {
  // the shots: words in, a slow push on each
  wordRise(at, t, { start: 0.15, each: B.pace.stagger, duration: 0.8 });
  a.style.transform = `scale(${1 + 0.05 * progress(t, 0, T.dis[1])})`;
  $('b').style.transform = `scale(${1.08 - 0.08 * progress(t, T.dis[0], D, ease.outCubic)})`;
  wordRise(bt, t, { start: T.dis[0] + 0.7, each: B.pace.stagger, duration: 0.9 });
  blurIn(bs, t, { start: T.dis[0] + 1.3, duration: 0.8 });
  // the dissolve
  const p = progress(t, ...T.dis, ease.inOutSine) * (1 + band * 2) - band;
  ex.clearRect(0, 0, W, H);
  if (t < T.dis[0]) { a.style.webkitMaskImage = a.style.maskImage = 'none'; a.style.visibility = ''; return; }
  if (t >= T.dis[1]) { a.style.visibility = 'hidden'; return; }
  a.style.visibility = '';
  const img = mx.createImageData(cols, rows);
  ex.fillStyle = accent;
  for (let i = 0; i < thr.length; i++) {
    const v = thr[i] - p;                                           // > 0: still there
    img.data[i * 4 + 3] = v > 0 ? 255 : 0;
    if (v > -band && v < band) {                                    // the edge: dots that light up as they go
      const k = 1 - Math.abs(v) / band, x = (i % cols) * cell + cell / 2, y = Math.floor(i / cols) * cell + cell / 2;
      ex.globalAlpha = k * 0.9; ex.beginPath(); ex.arc(x, y, cell * 0.36 * k + cell * 0.08, 0, Math.PI * 2); ex.fill();
    }
  }
  ex.globalAlpha = 1;
  mx.putImageData(img, 0, 0);
  const url = `url(${mc.toDataURL()})`;
  a.style.webkitMaskImage = a.style.maskImage = url;
});
B.cue(s, 'text', 0.15); B.cue(s, 'transition', T.dis[0]); B.cue(s, 'land', T.dis[0] + 0.7);
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults

Structure

Dither dissolve01 / 03
Shot A
shot a
0.0 / 4.6 s
01Shot A
02Dissolve
03Shot B
0 s4.6 s
  1. 010–1.4 sShot Ashot a
  2. 021.4–2.9 sDissolvedissolve
  3. 032.9–4.6 sShot Bshot b

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
dither-dissolve
Type
Blocks
Version
1.0.0
Engine
>=0.2.6
License
MIT

Related