Countdown
A monumental countdown numeral inside a ring resolves into a Live lockup.
Source
components/kuchi/countdown.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/BricolageGrotesque";4import { loadFont as loadManrope } from "@remotion/google-fonts/Manrope";5import type React from "react";6import { useId } from "react";7import {8 AbsoluteFill,9 Easing,10 interpolate,11 spring,12 useCurrentFrame,13 useVideoConfig,14} from "remotion";1516const { fontFamily: sans } = loadFont("normal", {17 weights: ["400", "500"],18 subsets: ["latin"],19});20const manrope = loadManrope("normal", {21 weights: ["600"],22 subsets: ["latin"],23});242526/** Full logo as on acme.dev: R mark (0.76em tall, baseline-aligned) + "Acme" in Manrope 600. */27function KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {28 return (29 <div30 style={{31 display: "flex",32 alignItems: "baseline",33 color,34 fontFamily: manrope.fontFamily,35 fontWeight: 600,36 fontSize,37 letterSpacing: "-0.025em",38 lineHeight: 1,39 }}40 >41 <span>Acme</span>42 </div>43 );44}4546export interface CountdownProps {47 /** First number of the countdown. */48 from?: number;49 /** What the countdown lands on: "Live", a product name, a date. */50 finalLabel?: string;51 /** Show the small accent dot before the final label. */52 indicator?: boolean;53 /** Small lockup under the final label. Pass "" to hide it. */54 caption?: string;55 /** Replaces the default acme mark in the lockup. */56 logo?: React.ReactNode;57 /** Frames per number. */58 beat?: number;59 accent?: string;60 /** Text color of the numerals, final label and mark; overrides the theme ink. */61 ink?: string;62 /** Background fill; "transparent" drops it. */63 background?: string;64 /** Typeface for the numerals and labels. Load it yourself; Bricolage Grotesque by default. */65 fontFamily?: string;66 /** Weight of the countdown numerals. */67 fontWeight?: number;68 /** Glowing ring behind the numerals that opens around the final label. */69 halo?: boolean;70 /** Size of the countdown, around the frame's center. */71 scale?: number;72 /** Frames to hold the first frame before anything moves. */73 delay?: number;74 /** Film grain over the scene. */75 grain?: boolean;76 /** Playback multiplier. */77 speed?: number;78 theme?: "dark" | "light";79}8081const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);82const EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);83const CLAMP = {84 extrapolateLeft: "clamp",85 extrapolateRight: "clamp",86} as const;8788const THEMES = {89 dark: {90 bg: "#0A0A0B",91 fg: "#F3F2EF",92 muted: "#8B8A90",93 track: "rgba(255,255,255,0.10)",94 stage: "rgba(255,255,255,0.06)",95 push: "rgba(255,255,255,0.09)",96 grain: 0.06,97 /** gradients.sh "radial-glow" (#f3f1ff #9db4ff #5a46cb #1d1240) as a thick halo */98 halo: [99 "rgba(29,18,64,0)",100 "rgba(29,18,64,0.55)",101 "rgba(90,70,203,0.55)",102 "rgba(157,180,255,0.5)",103 "rgba(214,218,255,0.32)",104 "rgba(90,70,203,0.36)",105 "rgba(29,18,64,0.4)",106 ],107 },108 light: {109 bg: "#F5F4F0",110 fg: "#121214",111 muted: "#6E6C67",112 track: "rgba(18,18,20,0.10)",113 stage: "rgba(255,255,255,0.85)",114 push: "rgba(255,255,255,0.75)",115 grain: 0.045,116 halo: [117 "rgba(157,180,255,0)",118 "rgba(157,180,255,0.16)",119 "rgba(90,70,203,0.22)",120 "rgba(157,180,255,0.55)",121 "rgba(243,241,255,0.9)",122 "rgba(157,180,255,0.3)",123 "rgba(90,70,203,0.08)",124 ],125 },126} as const;127128type Palette = (typeof THEMES)[keyof typeof THEMES];129type Exit = "ring" | "slice" | "through";130131function Grain({ opacity }: { opacity: number }) {132 const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;133 return (134 <svg135 width="100%"136 height="100%"137 style={{ position: "absolute", inset: 0, opacity }}138 aria-hidden139 >140 <filter id={id}>141 <feTurbulence142 type="fractalNoise"143 baseFrequency="0.9"144 numOctaves={2}145 seed={13}146 stitchTiles="stitch"147 />148 <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" />149 </filter>150 <rect width="100%" height="100%" filter={`url(#${id})`} />151 </svg>152 );153}154155/** A centred monumental numeral; everything else is styling passed in. */156function Numeral({157 n,158 size,159 color,160 fontFamily,161 fontWeight,162 style,163}: {164 n: number;165 size: number;166 color: string;167 fontFamily: string;168 fontWeight: number;169 style?: React.CSSProperties;170}) {171 return (172 <AbsoluteFill173 style={{174 display: "flex",175 alignItems: "center",176 justifyContent: "center",177 ...style,178 }}179 >180 <div181 style={{182 fontFamily,183 fontWeight,184 fontSize: size,185 lineHeight: 1,186 letterSpacing: "-0.04em",187 color,188 fontVariantNumeric: "tabular-nums",189 // optical centring: Inter Tight figures sit high in the em box190 transform: `translateY(${size * 0.035}px)`,191 }}192 >193 {n}194 </div>195 </AbsoluteFill>196 );197}198199/** The foreground at `scale`, around the frame's center; nothing extra at 1. */200function ScaleLayer({201 scale,202 children,203}: {204 scale: number;205 children: React.ReactNode;206}) {207 if (scale === 1) return children;208 return (209 <AbsoluteFill style={{ transform: `scale(${scale})` }}>210 {children}211 </AbsoluteFill>212 );213}214215export function Countdown({216 from = 3,217 finalLabel = "Live",218 indicator = true,219 caption = "acme 2.0",220 logo,221 beat = 20,222 accent = "#3B5BFD",223 ink,224 background,225 fontFamily = sans,226 fontWeight = 400,227 halo: showHalo = true,228 scale: zoom = 1,229 delay = 0,230 grain = true,231 speed = 1,232 theme = "dark",233}: CountdownProps) {234 const t = Math.max(0, useCurrentFrame() - delay) * speed;235 const { width, height, fps } = useVideoConfig();236 const u = height / 720;237 const p: Palette = THEMES[theme];238 const fg = ink ?? p.fg;239 const bg = background ?? p.bg;240 const count = Math.max(1, Math.round(from));241 const size = height * 0.66;242 const ringR = height * 0.36;243 const cxp = width / 2;244 const cyp = height / 2;245 const final = count * beat;246247 const exitOf = (k: number): Exit =>248 k === count - 1 ? "through" : k % 2 === 0 ? "ring" : "slice";249250 const layers: React.ReactNode[] = [];251 const overlays: React.ReactNode[] = [];252253 for (let k = 0; k < count; k++) {254 const n = count - k;255 const start = k * beat;256 const end = start + beat;257 if (t < start - beat || t > end + beat) continue;258259 // ---- entrance (driven by the previous numeral's exit) ----260 const prevExit: Exit | null = k === 0 ? null : exitOf(k - 1);261 let style: React.CSSProperties = {};262 let opacity = 1;263 let scale = 1;264 let blur = 0;265 let mask: string | undefined;266267 if (prevExit === null) {268 const a = interpolate(t, [0, 9], [0, 1], { ...CLAMP, easing: EASE_OUT });269 opacity = 0.3 + 0.7 * a;270 scale = 1.05 - 0.05 * a;271 blur = (1 - a) * 8 * u;272 } else if (prevExit === "ring") {273 const a = interpolate(t, [start - 12, start], [0, 360], {274 ...CLAMP,275 easing: EASE_IO,276 });277 if (t < start - 12) opacity = 0;278 else if (t < start)279 mask = `conic-gradient(from 0deg at 50% 50%, #000 0deg, #000 ${a}deg, transparent ${a + 0.8}deg)`;280 const s = interpolate(t, [start - 12, start + 6], [1.04, 1], {281 ...CLAMP,282 easing: EASE_OUT,283 });284 scale = s;285 } else if (prevExit === "slice") {286 const a = interpolate(t, [start, start + 9], [0, 1], {287 ...CLAMP,288 easing: EASE_OUT,289 });290 opacity = t < start ? 0 : a;291 scale = 1.14 - 0.14 * a;292 blur = (1 - a) * 10 * u;293 }294295 // a slow breath while the numeral holds296 scale *= interpolate(t, [start, end], [1, 0.985], CLAMP);297298 // ---- exit ----299 const exit = exitOf(k);300 if (exit === "ring") {301 const a = interpolate(t, [end - 12, end], [0, 360], {302 ...CLAMP,303 easing: EASE_IO,304 });305 if (t >= end) opacity = 0;306 else if (t > end - 12)307 mask = `conic-gradient(from 0deg at 50% 50%, transparent 0deg, transparent ${a}deg, #000 ${a + 0.8}deg)`;308309 // the ring itself: a hairline track and an accent sweep that leads the wipe310 const ringIn = interpolate(t, [end - 16, end - 10], [0, 1], CLAMP);311 const ringOut = interpolate(t, [end, end + 8], [1, 0], {312 ...CLAMP,313 easing: EASE_OUT,314 });315 const ringScale = interpolate(t, [end, end + 8], [1, 1.06], {316 ...CLAMP,317 easing: EASE_OUT,318 });319 const ro = ringIn * ringOut;320 if (ro > 0) {321 const circ = 2 * Math.PI * ringR;322 const hand = ((a - 90) * Math.PI) / 180;323 overlays.push(324 <svg325 key={`ring${k}`}326 width={width}327 height={height}328 style={{329 position: "absolute",330 inset: 0,331 opacity: ro,332 transform: `scale(${ringScale})`,333 }}334 aria-hidden335 >336 <circle337 cx={cxp}338 cy={cyp}339 r={ringR}340 fill="none"341 stroke={p.track}342 strokeWidth={Math.max(1, 1.2 * u)}343 />344 <circle345 cx={cxp}346 cy={cyp}347 r={ringR}348 fill="none"349 stroke={accent}350 strokeWidth={3 * u}351 strokeLinecap="round"352 strokeDasharray={`${(circ * a) / 360} ${circ}`}353 transform={`rotate(-90 ${cxp} ${cyp})`}354 />355 {a > 0 && a < 360 && (356 <line357 x1={cxp}358 y1={cyp}359 x2={cxp + Math.cos(hand) * ringR}360 y2={cyp + Math.sin(hand) * ringR}361 stroke={p.fg}362 strokeOpacity={0.35}363 strokeWidth={Math.max(1, u)}364 />365 )}366 </svg>,367 );368 }369 } else if (exit === "slice") {370 const cut = interpolate(t, [end - 9, end - 3], [0, 1], {371 ...CLAMP,372 easing: EASE_IO,373 });374 const part = interpolate(t, [end - 3, end + 5], [0, 1], {375 ...CLAMP,376 easing: Easing.bezier(0.5, 0, 0.2, 1),377 });378 if (t >= end - 3) {379 // replace the whole numeral with two halves that shear apart380 const cutY = cyp + size * 0.02;381 const shift = part * width * 0.42;382 const gapY = part * size * 0.03;383 const halves: Array<[string, number]> = [384 [`inset(0 0 ${height - cutY}px 0)`, -1],385 [`inset(${cutY}px 0 0 0)`, 1],386 ];387 for (const [clip, dir] of halves) {388 // trailing ghosts: a fake motion blur along the shear389 for (let g = 2; g >= 0; g--) {390 const lag = g * 0.09;391 const sh = Math.max(0, part - lag) / Math.max(0.001, 1 - lag);392 layers.push(393 <Numeral394 key={`h${k}${dir}${g}`}395 n={n}396 size={size}397 color={fg}398 fontFamily={fontFamily}399 fontWeight={fontWeight}400 style={{401 clipPath: clip,402 transform: `translate(${dir * sh * shift}px, ${dir * gapY}px) scale(${scale})`,403 opacity:404 interpolate(part, [0.25, 1], [1, 0], CLAMP) *405 (g === 0406 ? 1407 : 0.2 * interpolate(part, [0.1, 0.35], [0, 1], CLAMP)),408 filter: g === 0 ? undefined : `blur(${3 * u}px)`,409 }}410 />,411 );412 }413 }414 opacity = 0;415 }416 const lineO =417 interpolate(t, [end - 9, end - 7], [0, 1], CLAMP) *418 interpolate(t, [end - 1, end + 6], [1, 0], CLAMP);419 if (lineO > 0) {420 const span = width * 0.62;421 overlays.push(422 <div423 key={`cut${k}`}424 style={{425 position: "absolute",426 left: cxp - span / 2,427 top: cyp + size * 0.02 - u,428 width: span,429 height: Math.max(1.5, 2 * u),430 background: accent,431 transformOrigin: "0% 50%",432 transform: `scaleX(${cut})`,433 opacity: lineO,434 }}435 />,436 );437 }438 } else {439 // scale-through: the last numeral rushes past the camera440 const r = interpolate(t, [end - 8, end + 2], [0, 1], CLAMP);441 const grow = (x: number) => 1 + 9 * x * x * x;442 if (r > 0) {443 for (let g = 3; g >= 1; g--) {444 const gr = Math.max(0, r - g * 0.06);445 layers.push(446 <Numeral447 key={`g${k}${g}`}448 n={n}449 size={size}450 color={fg}451 fontFamily={fontFamily}452 fontWeight={fontWeight}453 style={{454 transform: `scale(${scale * grow(gr)})`,455 opacity:456 0.14 * interpolate(gr, [0, 0.2, 0.8], [0, 1, 0], CLAMP),457 filter: `blur(${(3 + gr * gr * 18) * u}px)`,458 }}459 />,460 );461 }462 }463 scale *= grow(r);464 opacity *= interpolate(r, [0.45, 0.95], [1, 0], CLAMP);465 blur += r * r * 16 * u;466 }467468 if (opacity > 0.001) {469 style = {470 opacity,471 transform: `scale(${scale})`,472 filter: blur > 0.2 ? `blur(${blur}px)` : undefined,473 WebkitMaskImage: mask,474 maskImage: mask,475 };476 layers.push(477 <Numeral478 key={`n${k}`}479 n={n}480 size={size}481 color={fg}482 fontFamily={fontFamily}483 fontWeight={fontWeight}484 style={style}485 />,486 );487 }488 }489490 // ---- final hit ----491 const f = spring({492 frame: t - final,493 fps,494 config: { damping: 16, stiffness: 160, mass: 0.8 },495 });496 const fO = interpolate(t, [final, final + 6], [0, 1], CLAMP);497 const fBlur = interpolate(t, [final, final + 8], [10 * u, 0], {498 ...CLAMP,499 easing: EASE_OUT,500 });501 const dot = spring({502 frame: t - final - 4,503 fps,504 config: { damping: 12, stiffness: 200, mass: 0.5 },505 });506 const push = interpolate(t, [final - 2, final + 2, final + 26], [0, 1, 0], {507 ...CLAMP,508 easing: EASE_OUT,509 });510 const cap = interpolate(t, [final + 12, final + 32], [0, 1], {511 ...CLAMP,512 easing: EASE_OUT,513 });514 const finalIsLogo = finalLabel.trim().toLowerCase() === "acme";515 const finalSize = Math.min(516 height * 0.3,517 (width * 0.7) / Math.max(3, Array.from(finalLabel).length * 0.56),518 );519 // rough rendered width of the final line, so the halo can open around it520 const finalW = Math.max(521 2 * ringR,522 finalSize *523 (finalIsLogo524 ? 3.9525 : Array.from(finalLabel).length * 0.55 + (indicator ? 0.4 : 0)),526 );527 // "acme 2.0" -> the real logo followed by "2.0"528 const capMatch = /^acme\b\s*(.*)$/i.exec(caption);529 const capText = capMatch ? capMatch[1] : caption;530 const capLogo =531 logo ??532 (finalIsLogo && !capMatch ? null : (533 <KuchiLogo fontSize={27 * u} color={fg} />534 ));535 // the whole stage leans in a touch at the cut, then settles536 const stageKick =537 1 + 0.02 * interpolate(t, [final, final + 3, final + 24], [0, 1, 0], CLAMP);538539 // the halo sits on the countdown ring's radius, breathes in as the count540 // runs, and opens up at the hit to frame the final label541 const haloOpen = interpolate(t, [final - 4, final + 30], [0, 1], {542 ...CLAMP,543 easing: EASE_OUT,544 });545 const haloScale =546 interpolate(t, [0, final], [0.94, 1], CLAMP) *547 (1 + (finalW / (2 * ringR * 0.9) - 1) * haloOpen);548 const haloIn = interpolate(t, [0, 14], [0, 1], {549 ...CLAMP,550 easing: EASE_OUT,551 });552 const hs = (k: number) => `${(ringR * k).toFixed(1)}px`;553 const h = p.halo;554 const halo = `radial-gradient(circle at 50% 50%, ${h[0]} ${hs(0.78)}, ${h[1]} ${hs(0.88)}, ${h[2]} ${hs(0.96)}, ${h[3]} ${hs(0.995)}, ${h[4]} ${hs(1.01)}, ${h[5]} ${hs(1.07)}, ${h[6]} ${hs(1.2)}, transparent ${hs(1.55)})`;555 // a slow light that travels around the halo556 const sweep = 200 + t * 1.1;557558 return (559 <AbsoluteFill style={{ background: bg, overflow: "hidden" }}>560 <AbsoluteFill561 style={{562 background: `radial-gradient(ellipse 60% 65% at 50% 38%, ${p.stage}, transparent 75%)`,563 }}564 />565 <ScaleLayer scale={zoom}>566 {showHalo ? (567 <AbsoluteFill568 style={{569 background: halo,570 opacity: haloIn,571 transform: `scale(${haloScale})`,572 WebkitMaskImage: `conic-gradient(from ${sweep}deg at 50% 50%, rgba(0,0,0,0.55), #000 40%, rgba(0,0,0,0.55) 70%, rgba(0,0,0,0.55))`,573 maskImage: `conic-gradient(from ${sweep}deg at 50% 50%, rgba(0,0,0,0.55), #000 40%, rgba(0,0,0,0.55) 70%, rgba(0,0,0,0.55))`,574 }}575 />576 ) : null}577 <AbsoluteFill style={{ transform: `scale(${stageKick})` }}>578 {layers}579 {overlays}580581 {t >= final - 1 && (582 <AbsoluteFill583 style={{584 display: "flex",585 flexDirection: "column",586 alignItems: "center",587 justifyContent: "center",588 gap: 30 * u,589 }}590 >591 <div592 style={{593 display: "flex",594 alignItems: "center",595 gap: finalSize * 0.16,596 opacity: fO,597 filter: fBlur > 0.2 ? `blur(${fBlur}px)` : undefined,598 transform: `scale(${0.9 + 0.1 * f})`,599 }}600 >601 {indicator && (602 <div603 style={{604 width: finalSize * 0.2,605 height: finalSize * 0.2,606 borderRadius: "50%",607 background: accent,608 transform: `scale(${0.5 + 0.5 * dot})`,609 marginTop: finalSize * 0.06,610 }}611 />612 )}613 {finalIsLogo ? (614 <KuchiLogo fontSize={finalSize} color={fg} />615 ) : (616 <div617 style={{618 fontFamily,619 fontWeight: 500,620 fontSize: finalSize,621 lineHeight: 1,622 letterSpacing: "-0.04em",623 color: fg,624 whiteSpace: "nowrap",625 }}626 >627 {finalLabel}628 </div>629 )}630 </div>631 {caption !== "" && (632 <div633 style={{634 display: "flex",635 alignItems: "center",636 gap: 10 * u,637 opacity: cap,638 transform: `translateY(${(1 - cap) * 12 * u}px)`,639 fontFamily,640 fontWeight: 400,641 fontSize: 24 * u,642 letterSpacing: "-0.01em",643 color: p.muted,644 }}645 >646 {capLogo}647 {capText}648 </div>649 )}650 </AbsoluteFill>651 )}652 </AbsoluteFill>653 </ScaleLayer>654655 {/* exposure push at the hit: light lifts, no white flash */}656 <AbsoluteFill657 style={{658 background: `radial-gradient(ellipse 70% 70% at 50% 50%, ${p.push}, transparent 80%)`,659 opacity: push,660 }}661 />662 <AbsoluteFill663 style={{664 background: `radial-gradient(ellipse 80% 80% at 50% 50%, transparent 60%, ${bg} 100%)`,665 opacity: 0.6,666 }}667 />668 {grain ? <Grain opacity={p.grain} /> : null}669 </AbsoluteFill>670 );671}









