Led Ticker
KUCHI IS LIVE scrolls on a retro LED dot-matrix with a gradient on the last word.
Source
components/kuchi/led-ticker.tsx
1"use client";23import type React from "react";4import { useId, useMemo } from "react";5import {6 AbsoluteFill,7 Easing,8 interpolate,9 useCurrentFrame,10 useVideoConfig,11} from "remotion";1213export interface LedTickerProps {14 text?: string;15 highlightWord?: string;16 accent?: string;17 /** Frames the line takes to scroll in and settle. */18 scroll?: number;19 /** Radius of a lit dot, as a share of the grid pitch. */20 dotSize?: number;21 /** Color of the lit dots; overrides the theme ink. */22 ink?: string;23 /** Background fill; "transparent" drops it. */24 background?: string;25 /** Size of the dot matrix, around the frame's center. */26 scale?: number;27 /** Frames to hold the first frame before anything moves. */28 delay?: number;29 /** Film grain over the scene. */30 grain?: boolean;31 theme?: "dark" | "light";32 speed?: number;33}3435const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);36const SCROLL = Easing.bezier(0.2, 0.7, 0.25, 1);37const CLAMP = {38 extrapolateLeft: "clamp",39 extrapolateRight: "clamp",40} as const;4142const THEMES = {43 dark: {44 bg: "#0A0A0B",45 ink: "#F3F2EF",46 off: "#FFFFFF",47 offAlpha: 0.075,48 grain: 0.05,49 },50 light: {51 bg: "#F5F4F0",52 ink: "#141416",53 off: "#141416",54 offAlpha: 0.075,55 grain: 0.04,56 },57} as const;5859const GLYPHS: Record<string, string[]> = {60 A: [".###.", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],61 B: ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."],62 C: [".###.", "#...#", "#....", "#....", "#....", "#...#", ".###."],63 D: ["####.", "#...#", "#...#", "#...#", "#...#", "#...#", "####."],64 E: ["#####", "#....", "#....", "####.", "#....", "#....", "#####"],65 F: ["#####", "#....", "#....", "####.", "#....", "#....", "#...."],66 G: [".###.", "#...#", "#....", "#.###", "#...#", "#...#", ".####"],67 H: ["#...#", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],68 I: ["###", ".#.", ".#.", ".#.", ".#.", ".#.", "###"],69 J: ["..###", "...#.", "...#.", "...#.", "...#.", "#..#.", ".##.."],70 K: ["#...#", "#..#.", "#.#..", "##...", "#.#..", "#..#.", "#...#"],71 L: ["#....", "#....", "#....", "#....", "#....", "#....", "#####"],72 M: ["#...#", "##.##", "#.#.#", "#.#.#", "#...#", "#...#", "#...#"],73 N: ["#...#", "#...#", "##..#", "#.#.#", "#..##", "#...#", "#...#"],74 O: [".###.", "#...#", "#...#", "#...#", "#...#", "#...#", ".###."],75 P: ["####.", "#...#", "#...#", "####.", "#....", "#....", "#...."],76 Q: [".###.", "#...#", "#...#", "#...#", "#.#.#", "#..#.", ".##.#"],77 R: ["####.", "#...#", "#...#", "####.", "#.#..", "#..#.", "#...#"],78 S: [".####", "#....", "#....", ".###.", "....#", "....#", "####."],79 T: ["#####", "..#..", "..#..", "..#..", "..#..", "..#..", "..#.."],80 U: ["#...#", "#...#", "#...#", "#...#", "#...#", "#...#", ".###."],81 V: ["#...#", "#...#", "#...#", "#...#", "#...#", ".#.#.", "..#.."],82 W: ["#...#", "#...#", "#...#", "#.#.#", "#.#.#", "#.#.#", ".#.#."],83 X: ["#...#", "#...#", ".#.#.", "..#..", ".#.#.", "#...#", "#...#"],84 Y: ["#...#", "#...#", ".#.#.", "..#..", "..#..", "..#..", "..#.."],85 Z: ["#####", "....#", "...#.", "..#..", ".#...", "#....", "#####"],86 "0": [".###.", "#...#", "#..##", "#.#.#", "##..#", "#...#", ".###."],87 "1": ["..#..", ".##..", "..#..", "..#..", "..#..", "..#..", ".###."],88 "2": [".###.", "#...#", "....#", "...#.", "..#..", ".#...", "#####"],89 "3": ["#####", "...#.", "..#..", "...#.", "....#", "#...#", ".###."],90 "4": ["...#.", "..##.", ".#.#.", "#..#.", "#####", "...#.", "...#."],91 "5": ["#####", "#....", "####.", "....#", "....#", "#...#", ".###."],92 "6": ["..##.", ".#...", "#....", "####.", "#...#", "#...#", ".###."],93 "7": ["#####", "....#", "...#.", "..#..", ".#...", ".#...", ".#..."],94 "8": [".###.", "#...#", "#...#", ".###.", "#...#", "#...#", ".###."],95 "9": [".###.", "#...#", "#...#", ".####", "....#", "...#.", ".##.."],96 ".": [".", ".", ".", ".", ".", ".", "#"],97 ",": ["..", "..", "..", "..", "..", ".#", "#."],98 "!": ["#", "#", "#", "#", "#", ".", "#"],99 "?": [".###.", "#...#", "....#", "...#.", "..#..", ".....", "..#.."],100 "-": ["....", "....", "....", "####", "....", "....", "...."],101 ":": [".", ".", "#", ".", ".", "#", "."],102 "'": ["#", "#", ".", ".", ".", ".", "."],103 "&": [".##..", "#..#.", "#.#..", ".#...", "#.#.#", "#..#.", ".##.#"],104 "/": ["....#", "...#.", "...#.", "..#..", ".#...", ".#...", "#...."],105 "%": ["##..#", "##..#", "...#.", "..#..", ".#...", "#..##", "#..##"],106 "+": [".....", "..#..", "..#..", "#####", "..#..", "..#..", "....."],107 " ": ["...", "...", "...", "...", "...", "...", "..."],108};109110// The acme.dev "R" mark on the 7-row grid: top bar with no upper stem,111// the bowl, and the stem + leg below. Replaces the R when the text opens112// with the word "acme".113const MARK_R = [114 "#####.",115 ".....#",116 ".....#",117 ".####.",118 "#..#..",119 "#...#.",120 "#....#",121];122123// gradients.sh "halo" (peach → amber → rose → blue) across the hot word.124const HALO = ["#ffd2ad", "#ffb36b", "#e2457a", "#3d4dff"];125const HOT_STEPS = 9;126127function ramp(stops: string[], n: number) {128 return Array.from({ length: n }, (_, i) => {129 const k = (i / (n - 1)) * (stops.length - 1);130 const j = Math.min(stops.length - 2, Math.floor(k));131 const f = k - j;132 const a = Number.parseInt(stops[j].slice(1), 16);133 const b = Number.parseInt(stops[j + 1].slice(1), 16);134 const ch = (sh: number) =>135 Math.round(((a >> sh) & 255) * (1 - f) + ((b >> sh) & 255) * f)136 .toString(16)137 .padStart(2, "0");138 return `#${ch(16)}${ch(8)}${ch(0)}`;139 });140}141142const ROWS = 7;143const TRAIL = [1, 0.4, 0.16, 0.06];144const BUCKETS = 6;145146function hash(n: number) {147 const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;148 return x - Math.floor(x);149}150151interface Cell {152 c: number;153 r: number;154 hot: number;155}156157function layout(text: string, highlightWord?: string) {158 const chars = text.toUpperCase().split("");159 const target = highlightWord?.trim().toUpperCase();160 const brand = false;161 const cells: Cell[] = [];162 let col = 0;163 let wordStart = 0;164 let hotRange: [number, number] | null = null;165 let word = "";166 const closeWord = (end: number) => {167 if (!hotRange && target && word === target) hotRange = [wordStart, end];168 word = "";169 };170 chars.forEach((ch, i) => {171 const g = brand && i === 0 ? MARK_R : (GLYPHS[ch] ?? GLYPHS[" "]);172 if (ch === " ") {173 closeWord(col - 2);174 } else if (word === "") {175 wordStart = col;176 word = ch;177 } else {178 word += ch;179 }180 const gw = g[0].length;181 for (let r = 0; r < ROWS; r++) {182 for (let x = 0; x < gw; x++) {183 if (g[r][x] === "#") cells.push({ c: col + x, r, hot: 0 });184 }185 }186 col += gw + (i < chars.length - 1 ? 1 : 0);187 });188 closeWord(col - 1);189 const range = hotRange as [number, number] | null;190 if (range) {191 for (const cell of cells) {192 if (cell.c >= range[0] && cell.c <= range[1]) {193 cell.hot = cell.c - range[0] + 1;194 }195 }196 }197 return {198 cells,199 width: Math.max(1, col),200 hotWidth: range ? range[1] - range[0] + 1 : 0,201 };202}203204const ENTER = 2;205const SCROLL_DUR = 54;206const HOT_STEP = 0.8;207const HOT_DUR = 6;208209/** The foreground at `scale`, around the frame's center; nothing extra at 1. */210function ScaleLayer({211 scale,212 children,213}: {214 scale: number;215 children: React.ReactNode;216}) {217 if (scale === 1) return children;218 return (219 <AbsoluteFill style={{ transform: `scale(${scale})` }}>220 {children}221 </AbsoluteFill>222 );223}224225export function LedTicker({226 text = "acme is live",227 highlightWord = "live",228 accent = "#3B5BFD",229 scroll = SCROLL_DUR,230 dotSize = 0.45,231 ink: inkColor,232 background,233 scale = 1,234 delay = 0,235 grain = true,236 theme = "dark",237 speed = 1,238}: LedTickerProps) {239 const t = Math.max(0, useCurrentFrame() - delay) * speed;240 const { width: W, height: H } = useVideoConfig();241 const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");242 const pal = THEMES[theme];243 const fg = inkColor ?? pal.ink;244 const bg =245 background === "transparent" ? "transparent" : (background ?? pal.bg);246 const hotStart = ENTER + scroll + 14;247248 const {249 cells,250 width: textCols,251 hotWidth,252 } = useMemo(() => layout(text, highlightWord), [text, highlightWord]);253254 const pitch = Math.min((W * 0.86) / textCols, H / 13);255 const cols = Math.ceil(W / pitch) + 2;256 const rows = Math.ceil(H / pitch) + 2;257 const x0 = (W - cols * pitch) / 2;258 const y0 = (H - rows * pitch) / 2;259 const home = Math.round((cols - textCols) / 2);260 const band = Math.round((rows - ROWS) / 2);261 const rOff = pitch * 0.3;262 const rOn = pitch * dotSize;263264 const offsetAt = (f: number) => {265 const p = interpolate(f, [ENTER, ENTER + scroll], [0, 1], CLAMP);266 return home + Math.round((cols - home) * (1 - SCROLL(p)));267 };268269 const lit = new Map<number, { b: number; hot: number }>();270 TRAIL.forEach((w, k) => {271 const f = Math.floor(t) - k;272 if (f < ENTER - 1) return;273 const o = offsetAt(f);274 for (const cell of cells) {275 const c = o + cell.c;276 if (c < 0 || c >= cols) continue;277 const key = (band + cell.r) * cols + c;278 const prev = lit.get(key);279 if (!prev || prev.b < w) lit.set(key, { b: w, hot: cell.hot });280 }281 });282283 const cx = W / 2;284 const cy = H / 2;285 const ink: string[][] = Array.from({ length: BUCKETS }, () => []);286 const hot: string[][] = Array.from({ length: BUCKETS * HOT_STEPS }, () => []);287 const hotColors = ramp(288 [HALO[0], HALO[1], HALO[2], accent].slice(theme === "light" ? 1 : 0),289 HOT_STEPS,290 );291 for (const [key, v] of lit) {292 const r = Math.floor(key / cols);293 const c = key % cols;294 const x = x0 + (c + 0.5) * pitch;295 const y = y0 + (r + 0.5) * pitch;296 const nx = (x - cx) / (W * 0.6);297 const ny = (y - cy) / (H * 0.6);298 const falloff = 1 - Math.min(1, nx * nx + ny * ny) * 0.22;299 let b = v.b * falloff * (0.94 + hash(key * 0.37) * 0.06);300 let isHot = false;301 if (v.hot > 0 && v.b === 1) {302 const start = hotStart + (v.hot - 1) * HOT_STEP;303 const p = (t - start) / HOT_DUR;304 if (p > 0) {305 const dip = p < 0.45 ? 1 - p / 0.45 : Math.min(1, (p - 0.45) / 0.55);306 b *= 0.12 + 0.88 * EASE_IO(dip);307 isHot = p >= 0.45;308 }309 }310 const bucket = Math.min(BUCKETS - 1, Math.floor(b * BUCKETS));311 const rad = rOff + (rOn - rOff) * Math.min(1, b);312 const seg = `M${(x - rad).toFixed(2)} ${y.toFixed(2)}a${rad.toFixed(2)} ${rad.toFixed(2)} 0 1 0 ${(2 * rad).toFixed(2)} 0a${rad.toFixed(2)} ${rad.toFixed(2)} 0 1 0 ${(-2 * rad).toFixed(2)} 0`;313 if (isHot) {314 const k = hotWidth > 1 ? (v.hot - 1) / (hotWidth - 1) : 0;315 const step = Math.round(k * (HOT_STEPS - 1));316 hot[bucket * HOT_STEPS + step].push(seg);317 } else {318 ink[bucket].push(seg);319 }320 }321322 const total = hotStart + hotWidth * HOT_STEP + HOT_DUR + 40;323 const cam = interpolate(t, [0, total], [1.035, 1], {324 ...CLAMP,325 easing: EASE_IO,326 });327 const bucketOpacity = (i: number) => (i + 1) / BUCKETS;328329 return (330 <AbsoluteFill style={{ background: bg, overflow: "hidden" }}>331 <ScaleLayer scale={scale}>332 <AbsoluteFill333 style={{ transform: `scale(${cam})`, transformOrigin: "50% 50%" }}334 >335 <svg336 width={W}337 height={H}338 viewBox={`0 0 ${W} ${H}`}339 style={{ position: "absolute", inset: 0 }}340 aria-hidden341 >342 <defs>343 <pattern344 id={`${uid}-dot`}345 patternUnits="userSpaceOnUse"346 x={x0}347 y={y0}348 width={pitch}349 height={pitch}350 >351 <circle352 cx={pitch / 2}353 cy={pitch / 2}354 r={rOff}355 fill={pal.off}356 fillOpacity={pal.offAlpha}357 />358 </pattern>359 <radialGradient id={`${uid}-fall`} cx="50%" cy="50%" r="62%">360 <stop offset="0%" stopColor="#fff" stopOpacity={1} />361 <stop offset="55%" stopColor="#fff" stopOpacity={0.62} />362 <stop offset="100%" stopColor="#fff" stopOpacity={0.18} />363 </radialGradient>364 <mask id={`${uid}-mask`}>365 <rect width={W} height={H} fill={`url(#${uid}-fall)`} />366 </mask>367 </defs>368 <rect369 width={W}370 height={H}371 fill={`url(#${uid}-dot)`}372 mask={`url(#${uid}-mask)`}373 />374 {ink.map((segs, i) =>375 segs.length ? (376 <path377 key={`i${i}`}378 d={segs.join("")}379 fill={fg}380 opacity={bucketOpacity(i)}381 />382 ) : null,383 )}384 {hot.map((segs, i) =>385 segs.length ? (386 <path387 key={`h${i}`}388 d={segs.join("")}389 fill={hotColors[i % HOT_STEPS]}390 opacity={bucketOpacity(Math.floor(i / HOT_STEPS))}391 />392 ) : null,393 )}394 </svg>395 </AbsoluteFill>396 </ScaleLayer>397 {grain ? (398 <svg399 width="100%"400 height="100%"401 style={{402 position: "absolute",403 inset: 0,404 opacity: pal.grain,405 pointerEvents: "none",406 }}407 aria-hidden408 >409 <filter id={`${uid}-grain`}>410 <feTurbulence411 type="fractalNoise"412 baseFrequency="0.9"413 numOctaves={2}414 seed={5}415 stitchTiles="stitch"416 />417 <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" />418 </filter>419 <rect width="100%" height="100%" filter={`url(#${uid}-grain)`} />420 </svg>421 ) : null}422 </AbsoluteFill>423 );424}









