Strobe Words
Big words strobe in at a set rhythm over a dark horizon glow, ending on the logo.
Source
components/kuchi/strobe-words.tsx
1"use client";23import { loadFont as loadManrope } from "@remotion/google-fonts/Manrope";4import { loadFont as loadDisplay } from "@remotion/google-fonts/Sora";5import type React from "react";6import { useId } from "react";7import {8 AbsoluteFill,9 Easing,10 interpolate,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";1415const manrope = loadManrope("normal", {16 weights: ["500", "600"],17 subsets: ["latin"],18});19const { fontFamily: display } = loadDisplay("normal", {20 weights: ["500"],21 subsets: ["latin"],22});2324// gradients.sh "radial-glow" palette (bg #020204): #f3f1ff, #9db4ff, #5a46cb, #1d1240.25const GLOW = ["#f3f1ff", "#9db4ff", "#5a46cb", "#1d1240", "#020204"] as const;2627// Sora 500 advances (1/1000 em), ASCII 32–126, measured with HarfBuzz.28const SORA_500 = [29 222, 303, 452, 702, 652, 864, 702, 264, 382, 382, 568, 592, 266, 506, 266,30 365, 750, 423, 623, 620, 652, 630, 668, 585, 647, 668, 266, 266, 592, 590,31 592, 556, 1124, 765, 684, 797, 788, 598, 560, 832, 803, 320, 641, 703, 549,32 937, 858, 865, 649, 865, 710, 682, 602, 785, 719, 1052, 705, 654, 652, 382,33 365, 382, 587, 581, 300, 581, 694, 608, 694, 616, 380, 679, 644, 317, 324,34 595, 296, 973, 644, 678, 694, 694, 414, 543, 429, 634, 572, 873, 574, 555,35 493, 382, 375, 382, 511,36];37const TRACK = -0.045;383940/** Full logo as on acme.dev: R mark (0.76em tall, baseline-aligned) + "Acme" in Manrope 600, tracking-tight. */41function KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {42 return (43 <div44 style={{45 display: "flex",46 alignItems: "baseline",47 color,48 fontFamily: manrope.fontFamily,49 fontWeight: 600,50 fontSize,51 letterSpacing: "-0.025em",52 lineHeight: 1,53 }}54 >55 <span>Acme</span>56 </div>57 );58}5960export interface StrobeWordsProps {61 words?: string[];62 rhythm?: number[];63 /** Frames of the first strobe cut when `rhythm` is unset; cuts speed up to half that. */64 beat?: number;65 /** Fewest strobe cuts before the poster when `rhythm` is unset. */66 cuts?: number;67 logo?: React.ReactNode;68 accent?: string;69 /** Typeface for the words. Load it yourself; Sora by default. */70 fontFamily?: string;71 /** Film grain over the scene. */72 grain?: boolean;73 /** Size of the words and logo, around the frame's center. */74 scale?: number;75 /** Frames to hold the first frame before anything moves. */76 delay?: number;77 theme?: "dark" | "light";78 speed?: number;79}8081const CAP = 0.73;82const BASE = 0.84;83const INK = "#0A0A0B";84const PAPER = "#F5F4F0";85const PAPER_INK = "#121214";8687type Field = "accent" | "ink" | "paper";88const CYCLE: Field[] = ["accent", "ink", "paper"];8990function widthEm(text: string) {91 let w = 0;92 for (const ch of text) {93 const code = ch.charCodeAt(0);94 const adv = code >= 32 && code < 127 ? SORA_500[code - 32] : 600;95 w += adv / 1000 + TRACK;96 }97 return Math.max(w, 0.5);98}99100function defaultRhythm(count: number, beat: number, cuts: number) {101 let n = count - 1;102 while (n < cuts) n += count;103 return Array.from({ length: n }, (_, i) =>104 Math.round(beat - ((beat / 2) * i) / Math.max(1, n - 1)),105 );106}107108function Grain({ opacity }: { opacity: number }) {109 const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;110 return (111 <svg112 width="100%"113 height="100%"114 style={{ position: "absolute", inset: 0, opacity, pointerEvents: "none" }}115 aria-hidden116 >117 <filter id={id}>118 <feTurbulence119 type="fractalNoise"120 baseFrequency="0.9"121 numOctaves={2}122 seed={3}123 stitchTiles="stitch"124 />125 <feColorMatrix values="0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.9 0" />126 </filter>127 <rect width="100%" height="100%" filter={`url(#${id})`} />128 </svg>129 );130}131132function Word({133 text,134 size,135 color,136 stop,137 fill,138 fontFamily,139}: {140 text: string;141 size: number;142 color: string;143 stop: string;144 fill?: string;145 fontFamily: string;146}) {147 const { height: H } = useVideoConfig();148 const baseline = H / 2 + (CAP * size) / 2;149 const tail = text.match(/[.!?]$/) ? text.slice(-1) : "";150 const body = tail ? text.slice(0, -1) : text;151 return (152 <div153 style={{154 position: "absolute",155 left: 0,156 right: 0,157 top: baseline - BASE * size,158 display: "flex",159 justifyContent: "center",160 }}161 >162 <div163 style={{164 fontFamily,165 fontWeight: 500,166 fontSize: size,167 lineHeight: 1,168 letterSpacing: `${TRACK}em`,169 paddingLeft: `${-TRACK}em`,170 whiteSpace: "nowrap",171 color,172 }}173 >174 {fill ? (175 <span176 style={{177 color: "transparent",178 backgroundImage: fill,179 WebkitBackgroundClip: "text",180 backgroundClip: "text",181 paddingRight: "0.08em",182 marginRight: "-0.08em",183 }}184 >185 {body}186 </span>187 ) : (188 body189 )}190 {tail ? <span style={{ color: stop }}>{tail}</span> : null}191 </div>192 </div>193 );194}195196/** The foreground at `scale`, around the frame's center; nothing extra at 1. */197function ScaleLayer({198 scale,199 children,200}: {201 scale: number;202 children: React.ReactNode;203}) {204 if (scale === 1) return children;205 return (206 <AbsoluteFill style={{ transform: `scale(${scale})` }}>207 {children}208 </AbsoluteFill>209 );210}211212export function StrobeWords({213 words = ["Plan.", "Write.", "Render.", "Ship."],214 rhythm,215 beat = 6,216 cuts = 13,217 logo,218 accent = "#3B5BFD",219 fontFamily = display,220 grain = true,221 scale = 1,222 delay = 0,223 theme = "dark",224 speed = 1,225}: StrobeWordsProps) {226 const t = Math.max(0, useCurrentFrame() - delay) * speed;227 const { width: W, height: H } = useVideoConfig();228 const u = H / 720;229 const list = words.length > 0 ? words : ["Ship."];230 const beats =231 rhythm && rhythm.length > 0232 ? rhythm233 : defaultRhythm(list.length, beat, cuts);234 const poster: Field = theme === "light" ? "paper" : "ink";235236 const offset = (((CYCLE.indexOf("accent") - (beats.length - 1)) % 3) + 3) % 3;237238 let index = beats.length;239 let at = 0;240 for (let i = 0; i < beats.length; i++) {241 if (t < at + beats[i]) {242 index = i;243 break;244 }245 at += beats[i];246 }247 const isPoster = index >= beats.length;248 const field: Field = isPoster ? poster : CYCLE[(index + offset) % 3];249 const text = isPoster250 ? list[list.length - 1]251 : list[252 (((index - beats.length + list.length - 1) % list.length) +253 list.length) %254 list.length255 ];256257 // Each strobe beat on the accent field is a radial-glow ground; the disc258 // sits in a slightly different place per beat so the cuts read as light.259 const k = isPoster ? 0 : index;260 const bx = 50 + ((k * 37) % 5) * 5 - 10;261 const glowField = [262 `radial-gradient(52% 64% at ${bx}% 104%, ${GLOW[0]} 0%, color-mix(in oklab, ${GLOW[1]} 85%, transparent) 30%, transparent 72%)`,263 `radial-gradient(90% 90% at ${100 - bx}% 0%, color-mix(in oklab, ${GLOW[3]} 80%, transparent) 0%, transparent 70%)`,264 `linear-gradient(180deg, ${GLOW[3]} 0%, ${GLOW[2]} 62%, #7e6fe0 100%)`,265 ].join(", ");266 const rise = interpolate(t - at, [0, 60], [0, 1], {267 extrapolateLeft: "clamp",268 extrapolateRight: "clamp",269 easing: Easing.bezier(0.22, 1, 0.36, 1),270 });271 // Poster: the glow's ring reads as a horizon arc low in frame, rising a272 // few percent over the hold, under the word rather than around it.273 const posterGlow = [274 `radial-gradient(78% 62% at 50% ${142 - 6 * rise}%, color-mix(in oklab, ${GLOW[3]} 90%, transparent) 60%, color-mix(in oklab, ${GLOW[0]} 80%, transparent) 63%, color-mix(in oklab, ${GLOW[1]} 40%, transparent) 67%, transparent 80%)`,275 `radial-gradient(90% 60% at 50% 120%, color-mix(in oklab, ${GLOW[2]} 45%, transparent) 0%, transparent 70%)`,276 GLOW[4],277 ].join(", ");278 const bg =279 field === "accent"280 ? glowField281 : field === "ink"282 ? isPoster283 ? posterGlow284 : INK285 : PAPER;286 const fg = field === "paper" ? PAPER_INK : "#F7F7F5";287 const stop = field === "accent" ? GLOW[0] : accent;288 const posterFill =289 isPoster && field === "paper"290 ? `linear-gradient(180deg, ${GLOW[2]} 10%, ${GLOW[3]} 92%)`291 : undefined;292293 const longest = list.reduce((m, w) => Math.max(m, widthEm(w)), 0.5);294 const strobeSize = Math.min(290 * u, (0.74 * W) / longest);295 const final = list[list.length - 1];296 const posterSize = Math.min(340 * u, (0.8 * W) / widthEm(final));297298 return (299 <AbsoluteFill style={{ background: bg, overflow: "hidden" }}>300 <ScaleLayer scale={scale}>301 <Word302 text={text}303 size={isPoster ? posterSize : strobeSize}304 color={fg}305 stop={stop}306 fill={posterFill}307 fontFamily={fontFamily}308 />309 {isPoster ? (310 <div311 style={{312 position: "absolute",313 left: 0,314 right: 0,315 bottom: 0.085 * H,316 display: "flex",317 justifyContent: "center",318 alignItems: "center",319 gap: 10 * u,320 color: fg,321 }}322 >323 {logo ?? <KuchiLogo fontSize={28 * u} color={fg} />}324 </div>325 ) : null}326 </ScaleLayer>327 {grain ? <Grain opacity={field === "paper" ? 0.04 : 0.05} /> : null}328 </AbsoluteFill>329 );330}









