Lights Out
Five lights go out and a heavy italic headline slams in, with a blue period.
Source
components/kuchi/lights-out.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/Unbounded";4import type React from "react";5import { useId } from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 useCurrentFrame,11 useVideoConfig,12} from "remotion";1314const { fontFamily: display } = loadFont("normal", {15 weights: ["500"],16 subsets: ["latin"],17});1819export interface LightsOutProps {20 /** Headline that slams in the instant the lights go out. Set in caps. */21 title?: string;22 /** Frames between two lights coming on. */23 beat?: number;24 /** Frames all five lights stay lit before they go out together. */25 hold?: number;26 /** Oblique slant of the headline, in degrees. */27 slant?: number;28 /** Warm glow that rises from below as the lamps come on. */29 glow?: boolean;30 accent?: string;31 /** Text color of the headline; overrides the theme ink. */32 ink?: string;33 /** Background fill; "transparent" drops it. */34 background?: string;35 /** Typeface for the headline. Spacing is measured for Unbounded 500; load it yourself. */36 fontFamily?: string;37 /** Size of the lights and headline, around the frame's center. */38 scale?: number;39 /** Frames to hold the first frame before anything moves. */40 delay?: number;41 theme?: "dark" | "light";42 speed?: number;43}4445// Unbounded 500, per 1000 em, chars 32–126 then ’ “ ” … – — (harfbuzz): advance,46// left and right side bearing, and the caps/punctuation kerning pairs.47const ADV = [48 256, 302, 464, 842, 788, 1252, 909, 252, 361, 361, 528, 620, 282, 361, 279,49 440, 909, 495, 812, 821, 832, 791, 841, 728, 873, 841, 311, 316, 620, 620,50 620, 679, 1031, 928, 865, 923, 911, 780, 755, 955, 924, 323, 792, 851, 751,51 1206, 954, 956, 796, 957, 830, 823, 801, 870, 910, 1338, 832, 897, 791, 407,52 440, 407, 620, 482, 346, 806, 799, 743, 808, 722, 563, 796, 757, 293, 293,53 714, 293, 1182, 766, 778, 800, 800, 530, 719, 579, 754, 742, 1120, 682, 746,54 672, 440, 298, 440, 620, 277, 510, 514, 783, 652, 1182,55];56const LSB = [57 0, 54, 43, 44, 38, 25, 33, 43, 39, 23, 38, 30, 38, 57, 41, 15, 46, 11, 38, 32,58 24, 32, 47, 11, 46, 44, 58, 57, 29, 30, 31, 17, 36, 4, 53, 41, 77, 53, 77, 41,59 77, 77, 21, 77, 77, 77, 77, 40, 77, 40, 77, 37, 17, 67, 4, 12, -8, 11, 41, 72,60 15, 31, 35, -26, 29, 36, 63, 33, 36, 33, 19, 34, 63, 44, 44, 63, 63, 36, 36,61 33, 63, 35, 36, 27, 5, 55, 5, 7, -9, 9, 38, 33, 77, 32, 30, 52, 34, 52, 41,62 56, 56,63];64const RSB = [65 256, 54, 44, 44, 39, 24, -10, 43, 23, 39, 38, 30, 43, 57, 41, 15, 46, 81, 43,66 47, 31, 39, 44, 27, 46, 46, 58, 60, 31, 30, 29, 24, 32, 4, 36, 34, 40, 52, 37,67 59, 77, 76, 67, -3, 18, 76, 76, 40, 22, 41, 28, 37, 18, 67, 4, 12, -8, 12, 41,68 31, 15, 72, 34, -26, 29, 49, 35, 27, 26, 35, 0, 60, 55, 45, 45, -5, 63, 55,69 55, 34, 35, 62, 14, 33, 26, 36, 5, 8, -10, 4, 38, 32, 76, 32, 30, 29, 42, 28,70 41, 56, 56,71];72const KERN = new Map(73 [74 "AC-43 AG-43 AJ-26 AO-43 AQ-43 AS-37 AT-126 AU-44 AV-125 AW-65 AY-156",75 "AZ-7 A0-40 A1-77 A2-10 A3-22 A4-20 A5-22 A6-38 A7-56 A8-22 A9-31",76 "A:-16 A?-78 A--58 A'-101 A’-94 A–-58 A—-58 BA-36 BC-1 BG-1 BO-1 BQ-1",77 "BT-29 BV-38 BW-25 BX-34 BY-65 BZ-6 B1-8 B7-10 B?-5 CA-37 CB-2 CE-2",78 "CT-32 CV-37 CW-22 CX-57 CY-72 CZ-14 C1-4 C7-10 C.-27 C,-27 C…-27",79 "DA-45 DB-8 DE-8 DT-35 DV-45 DW-25 DX-66 DY-93 DZ-21 D1-12 D7-22 D.-37",80 "D,-37 D…-37 EA-15 EC-12 EG-12 EJ-8 EO-12 EQ-12 ET-11 EV-18 EW-8 EY-27",81 "E4-4 FA-65 FC-8 FG-8 FJ-6 FO-8 FQ-8 FS-9 FV-1 FX-12 FY-15 F2-6 F4-14",82 "F.-103 F,-103 F…-103 GA-14 GT-33 GV-50 GW-28 GY-94 G1-14 G7-19 G'-11",83 "G’-10 JA-40 JX-2 J.-29 J,-29 J…-29 KC-47 KG-47 KJ-41 KO-47 KQ-47",84 "KS-27 KX3 K0-30 K3-7 K4-17 K5-4 K6-28 K78 K8-7 K9-14 K!5 K?-22 K--69",85 "K'5 K–-69 K—-69 LC-39 LG-39 LJ-17 LO-39 LQ-39 LS-25 LT-153 LU-34",86 "LV-137 LW-89 LX7 LY-167 L0-25 L1-82 L3-4 L4-7 L5-5 L6-23 L7-52 L8-4",87 "L9-13 L?-84 L--89 L'-119 L’-120 L–-89 L—-89 OA-43 OB-8 OE-8 OT-35",88 "OV-43 OW-24 OX-61 OY-87 OZ-19 O1-10 O7-20 O.-35 O,-35 O…-35 PA-90",89 "PB-1 PE-1 PJ-6 PT-10 PV-25 PW-12 PX-62 PY-41 PZ-11 P4-35 P.-114",90 "P,-114 P?24 P&-18 P…-114 QA-43 QB-8 QE-8 QT-35 QV-43 QW-24 QX-55",91 "QY-87 QZ-19 Q1-10 Q7-20 Q.-35 Q,-33 Q…-35 RA-16 RC-7 RG-7 RJ-23 RO-7",92 "RQ-7 RS-2 RT-24 RU-2 RV-37 RW-24 RX-5 RY-58 R0-1 R4-36 R5-7 R6-1 R8-5",93 "R&-5 R--15 R–-15 R—-15 SA-36 SB-1 SE-1 ST-28 SV-38 SW-27 SX-44 SY-63",94 "SZ-6 S7-4 TA-126 TC-35 TG-35 TJ-134 TO-35 TQ-35 TS-21 T0-24 T17 T2-7",95 "T3-8 T4-102 T5-14 T6-23 T78 T8-10 T9-5 T.-128 T,-128 T:-79 T?4 T&-35",96 "T--112 T…-128 T–-112 T—-112 UA-44 UX-2 U.-33 U,-33 U…-33 VA-125 VC-43",97 "VG-43 VJ-84 VO-43 VQ-43 VS-37 VZ-9 V0-40 V1-2 V2-24 V3-29 V4-87 V5-29",98 "V6-39 V712 V8-30 V9-24 V.-122 V,-122 V:-56 V!6 V?-15 V&-51 V--73 V'6",99 "V’-5 V…-122 V–-73 V—-73 WA-65 WC-24 WG-24 WJ-25 WO-24 WQ-24 WS-26",100 "W0-22 W2-9 W3-15 W4-54 W5-19 W6-21 W74 W8-17 W9-13 W.-86 W,-86 W:-32",101 "W!3 W&-37 W--43 W'3 W…-86 W–-43 W—-43 XC-61 XG-61 XJ-57 XO-61 XQ-61",102 "XS-44 XU-2 XX1 XY-5 X0-37 X3-12 X4-28 X5-10 X6-34 X8-10 X9-17 X!4",103 "X?-23 X&-4 X--77 X'4 X–-77 X—-77 YA-157 YC-88 YG-88 YJ-136 YO-88",104 "YQ-88 YS-51 YT-1 YX-5 YY-6 YZ-20 Y0-76 Y1-11 Y2-48 Y3-60 Y4-134 Y5-47",105 "Y6-74 Y72 Y8-58 Y9-50 Y.-136 Y,-136 Y:-101 Y!5 Y?-31 Y&-72 Y--128",106 "Y'-3 Y’-29 Y…-136 Y–-128 Y—-128 ZA-7 ZC-19 ZG-19 ZJ-18 ZO-19 ZQ-19",107 "ZS-5 ZV-9 ZY-19 Z0-14 Z4-4 Z6-13 Z--43 Z–-43 Z—-43 0A-42 0B-6 0E-6",108 "0T-28 0V-43 0W-23 0X-38 0Y-75 0Z-16 01-8 07-16 0.-31 0,-31 0…-31 1A-4",109 "1V-5 1Y-17 2A-4 2C-1 2G-1 2J-4 2O-1 2Q-1 2T-9 2V-32 2W-19 2Y-62 2--17",110 "2–-17 2—-17 3A-24 3T-9 3V-28 3W-16 3X-13 3Y-55 4A-20 4T-45 4V-57",111 "4W-43 4X-17 4Y-73 41-35 42-6 47-35 4'-40 4’-37 5A-23 5T-14 5V-25",112 "5W-16 5X-9 5Y-37 51-7 52-4 57-6 6A-24 6T-13 6V-33 6W-18 6X-17 6Y-63",113 "67-4 7A-95 7C-16 7G-16 7J-58 7O-16 7Q-16 70-9 74-75 75-8 76-8 7.-122",114 "7,-122 7--55 7…-122 7–-55 7—-55 8A-22 8T-11 8V-32 8W-18 8X-12 8Y-61",115 "87-4 9A-41 9B-6 9E-6 9T-25 9V-41 9W-23 9X-37 9Y-73 9Z-15 91-7 97-14",116 "9.-25 9,-25 9…-25 .C-35 .G-35 .J-8 .O-35 .Q-35 .S-8 .T-128 .U-33",117 ".V-122 .W-86 .Y-135 .0-31 .1-92 .6-25 .7-57 .9-16 .?-88 .--77 .'-126",118 ".’-127 .–-77 .—-77 ,C-35 ,G-35 ,J-8 ,O-35 ,Q-35 ,S-8 ,T-128 ,U-33",119 ",V-122 ,W-86 ,Y-135 ,0-31 ,1-92 ,6-25 ,7-57 ,9-16 ,?-88 ,--77 ,'-126",120 ",’-127 ,–-77 ,—-77 :A-16 :T-79 :V-56 :W-32 :Y-101 ??15 &A19 &J-5",121 "&S-17 &T-67 &U-16 &V-55 &W-28 &X32 &Y-81 &'-56 &’-55 -A-58 -B-17",122 "-E-17 -T-112 -V-73 -W-43 -X-77 -Y-128 -Z-45 -1-64 -2-18 -7-46 -.-77",123 "-,-77 -'-13 -…-77 'A-101 'J-76 'V6 'W3 'X4 'Y5 '4-79 '.-126 ',-126",124 "'&-30 '--13 '…-126 '–-13 '—-13 ’A-107 ’C-11 ’G-11 ’J-99 ’O-11 ’Q-11",125 "’T2 ’Y-15 ’112 ’4-92 ’712 ’.-138 ’,-138 ’:-24 ’?4 ’&-28 ’--38 ’…-138",126 "’–-38 ’—-38 …C-35 …G-35 …J-8 …O-35 …Q-35 …S-8 …T-128 …U-33 …V-122",127 "…W-86 …Y-135 …0-31 …1-92 …6-25 …7-57 …9-16 …?-88 …--77 …'-126 …’-127",128 "…–-77 …—-77 –A-58 –B-17 –E-17 –T-112 –V-73 –W-43 –X-77 –Y-128 –Z-45",129 "–1-64 –2-18 –7-46 –.-77 –,-77 –'-13 –…-77 —A-58 —B-17 —E-17 —T-112",130 "—V-73 —W-43 —X-77 —Y-128 —Z-45 —1-64 —2-18 —7-46 —.-77 —,-77 —'-13",131 "—…-77",132 ]133 .join(" ")134 .split(" ")135 .map((p) => [p.slice(0, 2), Number(p.slice(2)) / 1000] as const),136);137const CAP = 0.75;138/** Oblique slant, degrees: Unbounded has no italic, so the word is sheared. */139const SLANT = 11;140141// Beat sheet (30fps, speed 1, beat 10, hold 24):142// 0–10 five dim discs on a thin rail, the row creeping closer (slow push)143// 10–50 the lamps come on one by one, one every 10 frames, hard on; each144// one warms the "rise" ground glow from below a step more145// 50–74 all five lit, the push keeps tightening146// 74 lights out: all five go dark and the glow dies on the same frame;147// the headline is already halfway in from the left, cut into lagging148// bands that drag solid extrusions of themselves (a flat smear frame)149// 74–78 the headline brakes to a hard stop and the bands line up; the dark150// row snaps up and shrinks to sit above it151// 78– poster hold, the ground glow comes back low under the headline152const FIRST_LIGHT = 10;153const SLAM_LEN = 5;154const RISE_LEN = 9;155156const SLAM = Easing.bezier(0.22, 1, 0.36, 1);157const RISE = Easing.bezier(0.2, 0.9, 0.3, 1);158const PUSH = Easing.bezier(0.5, 0, 0.75, 0.4);159const CLAMP = {160 extrapolateLeft: "clamp",161 extrapolateRight: "clamp",162} as const;163164const THEMES = {165 dark: {166 stage: "#0A0A0B",167 ink: "#F3F2EF",168 off: "#26262B",169 rail: "#1B1B1F",170 glow: ["#FF8A3D", "#A3301A", "#2A0D0A"],171 },172 light: {173 stage: "#F5F4F0",174 ink: "#121214",175 off: "#DCDAD3",176 rail: "#E6E4DE",177 glow: ["#FF9F5E", "#FFC9A3", "#FBE6D6"],178 },179} as const;180181const EXTRA = "’“”…–—";182function code(ch: string) {183 const c = ch.charCodeAt(0);184 if (c >= 32 && c < 127) return c - 32;185 const x = EXTRA.indexOf(ch);186 return x >= 0 ? 95 + x : 46;187}188189function advance(text: string) {190 let adv = 0;191 for (let i = 0; i < text.length; i++) {192 adv += ADV[code(text[i])] / 1000;193 if (i > 0) adv += KERN.get(text[i - 1] + text[i]) ?? 0;194 }195 return adv;196}197198/** Pen offsets of each glyph, in em, kerned. */199function penOffsets(text: string) {200 const out: number[] = [];201 let pen = 0;202 for (let i = 0; i < text.length; i++) {203 if (i > 0) pen += KERN.get(text[i - 1] + text[i]) ?? 0;204 out.push(pen);205 pen += ADV[code(text[i])] / 1000;206 }207 return out;208}209210const BANDS = 12;211// Lag of each band, 0–1: tuned by eye so the bands read as streaks, not noise.212const LAGS = [0.55, 0.15, 0.85, 0.4, 1, 0.25, 0.7, 0.05, 0.9, 0.35, 0.6, 0.2];213214/** The foreground at `scale`, around the frame's center; nothing extra at 1. */215function ScaleLayer({216 scale,217 children,218}: {219 scale: number;220 children: React.ReactNode;221}) {222 if (scale === 1) return children;223 return (224 <AbsoluteFill style={{ transform: `scale(${scale})` }}>225 {children}226 </AbsoluteFill>227 );228}229230export function LightsOut({231 title = "SHIP IT.",232 beat = 10,233 hold = 24,234 slant = SLANT,235 glow: showGlow = true,236 accent = "#3B5BFD",237 ink,238 background,239 fontFamily = display,240 scale = 1,241 delay = 0,242 theme = "dark",243 speed = 1,244}: LightsOutProps) {245 const t = Math.max(0, useCurrentFrame() - delay) * speed;246 const { width: W, height: H } = useVideoConfig();247 const c = THEMES[theme];248 const fg = ink ?? c.ink;249 const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");250251 const text = title.trim().toUpperCase() || "GO";252 const lastLight = FIRST_LIGHT + 4 * beat;253 const outAt = lastLight + hold;254 const out = t >= outAt;255256 // Headline metrics: sized so its ink spans ~86% of the width.257 const adv = advance(text);258 const lsb = LSB[code(text[0])] / 1000;259 const rsb = RSB[code(text[text.length - 1])] / 1000;260 const inkEm = Math.max(0.5, adv - lsb - rsb);261 const fs = Math.min((0.86 * W) / inkEm, (0.34 * H) / CAP);262 const cap = CAP * fs;263 const inkW = inkEm * fs;264265 // Lights: big row centered, small row parked above the headline.266 const d = 0.105 * W;267 const gap = 0.04 * W;268 const rowW = 5 * d + 4 * gap;269 const small = Math.min(0.36, (0.34 * inkW) / rowW);270 const blockGap = 0.075 * H;271 const blockH = d * small + blockGap + cap;272 const top = (H - blockH) / 2;273 const smallCy = top + (d * small) / 2;274 const baseline = top + d * small + blockGap + cap;275276 const push = 1 + 0.06 * PUSH(interpolate(t, [0, outAt], [0, 1], CLAMP));277 const rise = RISE(interpolate(t, [outAt, outAt + RISE_LEN], [0, 1], CLAMP));278 const rowScale = push + (small - push) * rise;279 const rowCy = H / 2 + (smallCy - H / 2) * rise;280281 // Slam: its clock starts a frame early, so on the out frame the headline is282 // already halfway across, then it brakes hard.283 const slamStart = outAt - 1;284 // The shear pushes the cap line right; center the sheared ink, not the285 // upright one.286 const shear = Math.tan((slant * Math.PI) / 180);287 const restX = (W - inkW) / 2 - lsb * fs - (shear * cap) / 2;288 const from = restX - 0.62 * inkW - 0.12 * W;289 const xAt = (f: number) =>290 from +291 (restX - from) *292 SLAM(interpolate(f, [slamStart, slamStart + SLAM_LEN], [0, 1], CLAMP));293 const x = xAt(t);294 const velocity = x - xAt(t - 1);295 const smear = Math.min(velocity * 1.15, 0.9 * W);296297 const pens = penOffsets(text);298 const lastIsDot = /[.!]$/.test(text);299 const glyphs = text.split("").map((ch, i) => ({300 ch,301 dx: pens[i] * fs,302 fill: lastIsDot && i === text.length - 1 ? accent : fg,303 }));304305 const renderWord = (ox: number, key: string) => (306 <g key={key}>307 {glyphs.map((g, i) =>308 g.ch === " " ? null : (309 <text310 key={i}311 x={ox + g.dx}312 y={baseline}313 fill={g.fill}314 fontFamily={fontFamily}315 fontWeight={500}316 fontSize={fs}317 style={{ fontKerning: "none" }}318 >319 {g.ch}320 </text>321 ),322 )}323 </g>324 );325326 // While it moves the word is cut into horizontal bands. Each band lags by327 // its own amount and drags a solid extrusion of itself behind it: a flat328 // smear frame, no blur. Once the velocity is gone the bands line up.329 const bandTop = baseline - cap * 1.08;330 const bandH = (cap * 1.16) / BANDS;331 const moving = out && smear > 0.025 * W;332 const step = 0.07 * fs;333 const lights = Array.from({ length: 5 }, (_, i) => {334 const on = !out && t >= FIRST_LIGHT + i * beat;335 const cx = W / 2 + (i - 2) * (d + gap) * rowScale;336 return { cx, on };337 });338 const r = (d / 2) * rowScale;339 const slantT = `translate(0 ${baseline}) skewX(${-slant}) translate(0 ${-baseline})`;340341 // Ground: a warm "rise" glow from below that builds with every lamp, dies342 // on lights out, and comes back low under the landed headline.343 const lit = lights.reduce(344 (acc, _, i) =>345 acc +346 RISE(347 interpolate(348 t,349 [FIRST_LIGHT + i * beat, FIRST_LIGHT + i * beat + 6],350 [0, 1],351 CLAMP,352 ),353 ),354 0,355 );356 const after = interpolate(t, [outAt + 4, outAt + 30], [0, 0.42], {357 ...CLAMP,358 easing: Easing.bezier(0.3, 0, 0.2, 1),359 });360 const glow = out ? after : lit / 5;361 const g = c.glow;362363 return (364 <AbsoluteFill365 style={{366 background:367 background === "transparent" ? undefined : (background ?? c.stage),368 }}369 >370 {showGlow ? (371 <div372 style={{373 position: "absolute",374 inset: 0,375 opacity: glow,376 background: `radial-gradient(75% 62% at 50% 122%, ${g[0]} 0%, ${g[1]} 30%, ${g[2]} 56%, transparent 82%)`,377 }}378 />379 ) : null}380 <ScaleLayer scale={scale}>381 <svg382 width={W}383 height={H}384 viewBox={`0 0 ${W} ${H}`}385 style={{ position: "absolute", inset: 0 }}386 role="img"387 aria-label={text}388 >389 <rect390 x={W / 2 - (rowW / 2 + gap * 0.9) * rowScale}391 y={rowCy - 0.05 * d * rowScale}392 width={(rowW + gap * 1.8) * rowScale}393 height={0.1 * d * rowScale}394 fill={c.rail}395 />396 {lights.map((l, i) => (397 <circle398 key={i}399 cx={l.cx}400 cy={rowCy}401 r={r}402 fill={l.on ? `url(#${uid}-lamp)` : c.off}403 />404 ))}405 <defs>406 {/* Lamp lens: concentric, centered, so it reads as a flat light and407 not a lit sphere. */}408 <radialGradient id={`${uid}-lamp`} cx="0.5" cy="0.5" r="0.5">409 <stop offset="0" stopColor="#FFF1E2" />410 <stop offset="0.22" stopColor="#FFC08A" />411 <stop offset="0.55" stopColor="#FF8A3D" />412 <stop offset="0.92" stopColor="#D2502A" />413 <stop offset="1" stopColor="#A3301A" />414 </radialGradient>415 {Array.from({ length: BANDS }, (_, k) => (416 <clipPath key={k} id={`${uid}-b${k}`}>417 <rect418 x={0}419 y={bandTop + k * bandH}420 width={W}421 height={bandH + 0.5}422 />423 </clipPath>424 ))}425 </defs>426 <g transform={slantT}>427 {moving428 ? Array.from({ length: BANDS }, (_, k) => {429 const lag = LAGS[k % LAGS.length];430 // Only the long-lag bands streak; the rest just slip, so the431 // letterforms still read through the smear.432 const head = x - smear * lag * 0.3;433 const tail = lag > 0.5 ? smear * lag * 0.85 : 0;434 const n = Math.min(18, Math.ceil(tail / step));435 return (436 <g key={k} clipPath={`url(#${uid}-b${k})`}>437 {Array.from({ length: n + 1 }, (_, j) =>438 renderWord(439 head - (n ? (tail * (n - j)) / n : 0),440 `c${j}`,441 ),442 )}443 </g>444 );445 })446 : null}447 {out && !moving ? renderWord(x, "w") : null}448 </g>449 </svg>450 </ScaleLayer>451 </AbsoluteFill>452 );453}









