Growth Line
An exponential growth curve draws through milestones to a 100k endpoint.
Source
components/kuchi/growth-line.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/SchibstedGrotesk";4import type React from "react";5import { useId } from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 spring,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";1415const { fontFamily: sans } = loadFont("normal", {16 weights: ["400", "500"],17 subsets: ["latin"],18});1920export interface GrowthMilestone {21 /**22 * Position along the curve, 0..1. Omit it when the label is a number ("10k"):23 * the dot then sits where the curve actually crosses that value.24 */25 at?: number;26 label: string;27}2829export interface GrowthLineProps {30 /** The number that lands at the tip. */31 value?: string;32 /** Muted line under the value. */33 label?: string;34 milestones?: GrowthMilestone[];35 /** How hard the curve bends upward: 2 = gentle, 6 = hockey stick. */36 steepness?: number;37 accent?: string;38 /** Color of the value and milestone labels; overrides the theme ink. */39 ink?: string;40 /** Background fill; "transparent" drops it. */41 background?: string;42 /** Typeface for the copy. Load it yourself; Schibsted Grotesk by default. */43 fontFamily?: string;44 /** Weight of the value. */45 fontWeight?: number;46 /** Width of the curve, in pixels at 720p. */47 strokeWidth?: number;48 /** Size of the foreground, around the frame's center. */49 scale?: number;50 /** Frames to hold the first frame before anything moves. */51 delay?: number;52 grain?: boolean;53 /** Playback multiplier. */54 speed?: number;55 theme?: "dark" | "light";56}5758const DEFAULT_MILESTONES: GrowthMilestone[] = [59 { at: 0.03, label: "Launch" },60 { label: "1k" },61 { label: "10k" },62];6364const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);65const EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);66const CLAMP = {67 extrapolateLeft: "clamp",68 extrapolateRight: "clamp",69} as const;7071const THEMES = {72 dark: {73 bg: "#0A0A0B",74 fg: "#F3F2EF",75 muted: "#8B8A90",76 axis: "rgba(255,255,255,0.16)",77 dot: "rgba(255,255,255,0.07)",78 wash: "rgba(255,122,61,0.07)",79 tail: 0.35,80 fill: 0.26,81 grain: 0.06,82 /** gradients.sh "fluted" (#1d2a8f #2f7bff #ff7a3d #ffe2c4): cool start, hot tip */83 line: ["#3346C8", "#2F7BFF", "#FF7A3D", "#FFE2C4"],84 tip: "#FFB27F",85 },86 light: {87 bg: "#F5F4F0",88 fg: "#121214",89 muted: "#6E6C67",90 axis: "rgba(18,18,20,0.16)",91 dot: "rgba(18,18,20,0.08)",92 wash: "rgba(255,255,255,0.7)",93 tail: 0.4,94 fill: 0.22,95 grain: 0.045,96 line: ["#1D2A8F", "#2F7BFF", "#FF7A3D", "#E2551C"],97 tip: "#FF7A3D",98 },99} as const;100101/** Beats, in frames at speed 1. */102const DRAW = [-4, 118] as const;103const PULL = [84, 128] as const;104const HIT = 120;105const DRAW_EASE = Easing.bezier(0.3, 0.05, 0.55, 1);106107const drawProgress = (t: number) =>108 interpolate(t, DRAW, [0, 1], { ...CLAMP, easing: DRAW_EASE });109110/** The frame at which the tip reaches `at` (inverts the draw easing). */111function reachFrame(at: number) {112 for (let fr = DRAW[0]; fr <= DRAW[1]; fr += 0.5) {113 if (drawProgress(fr) >= at) return fr;114 }115 return DRAW[1];116}117118function Grain({ opacity }: { opacity: number }) {119 const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;120 return (121 <svg122 width="100%"123 height="100%"124 style={{ position: "absolute", inset: 0, opacity }}125 aria-hidden126 >127 <filter id={id}>128 <feTurbulence129 type="fractalNoise"130 baseFrequency="0.9"131 numOctaves={2}132 seed={11}133 stitchTiles="stitch"134 />135 <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" />136 </filter>137 <rect width="100%" height="100%" filter={`url(#${id})`} />138 </svg>139 );140}141142/** "100k" -> 100000, "1.2M" -> 1200000, "10,000" -> 10000. */143function parseValue(v: string) {144 const m = v.replace(/,/g, "").match(/([\d.]+)\s*([kKmMbB]?)/);145 if (!m) return null;146 const n = Number.parseFloat(m[1]);147 if (!Number.isFinite(n)) return null;148 const mult = { k: 1e3, m: 1e6, b: 1e9 }[m[2].toLowerCase()] ?? 1;149 return n * mult;150}151152const lerp = (a: number, b: number, k: number) => a + (b - a) * k;153154/** The foreground at `scale`, around the frame's center; nothing extra at 1. */155function ScaleLayer({156 scale,157 children,158}: {159 scale: number;160 children: React.ReactNode;161}) {162 if (scale === 1) return children;163 return (164 <AbsoluteFill style={{ transform: `scale(${scale})` }}>165 {children}166 </AbsoluteFill>167 );168}169170export function GrowthLine({171 value = "100k",172 label = "creators in the first year",173 milestones = DEFAULT_MILESTONES,174 steepness = 4.6,175 accent = "#3B5BFD",176 ink,177 background,178 fontFamily = sans,179 fontWeight = 400,180 strokeWidth = 3,181 scale = 1,182 delay = 0,183 grain = true,184 speed = 1,185 theme = "dark",186}: GrowthLineProps) {187 const t = Math.max(0, useCurrentFrame() - delay) * speed;188 const { width, height, fps } = useVideoConfig();189 const u = height / 720;190 const p = THEMES[theme];191 const fg = ink ?? p.fg;192 const id = useId().replace(/[^a-zA-Z0-9_-]/g, "");193194 // World: the full curve as it sits in the final, pulled-back frame.195 const L = width * 0.1;196 const Rr = width * 0.84;197 const B = height * 0.84;198 const T = height * 0.2;199 const k = steepness;200 const base = (x: number) => (Math.exp(k * x) - 1) / (Math.exp(k) - 1);201 const f = (x: number) => {202 // a little organic texture that calms down as the curve takes off203 const wob =204 0.008 * Math.sin(x * 31 + 1.3) * Math.sin(x * 7.3 + 0.4) * (1 - x) +205 0.004 * Math.sin(x * 67 + 2.1) * (1 - x);206 return Math.max(0, base(x) + wob * Math.min(1, x * 6));207 };208 const world = (x: number): [number, number] => [209 lerp(L, Rr, x),210 lerp(B, T, f(x)),211 ];212213 // Tip progress214 const prog = drawProgress(t);215 const [tipWx, tipWy] = world(prog);216217 // Camera: tracks the tip close-up, then pulls back to the whole curve.218 const pull = interpolate(t, PULL, [0, 1], { ...CLAMP, easing: EASE_IO });219 const zTrack = interpolate(t, [0, PULL[0]], [2.9, 2.2], {220 ...CLAMP,221 easing: EASE_IO,222 });223 const kick =224 1 +225 0.014 *226 interpolate(t, [HIT, HIT + 4, HIT + 22], [0, 1, 0], {227 ...CLAMP,228 easing: EASE_OUT,229 });230 const z = lerp(zTrack, 1, pull) * kick;231 // the tip rides low-left of centre early on, drifting up as the curve steepens232 const anchorX = width * lerp(0.56, 0.6, prog);233 const anchorY = height * lerp(0.6, 0.66, prog);234 const cx = lerp(tipWx, width / 2, pull);235 const cy = lerp(tipWy, height / 2, pull);236 const ax = lerp(anchorX, width / 2, pull);237 const ay = lerp(anchorY, height / 2, pull);238 const proj = (wx: number, wy: number): [number, number] => [239 (wx - cx) * z + ax,240 (wy - cy) * z + ay,241 ];242243 // Curve path, screen space244 const N = 220;245 const pts: Array<[number, number]> = [];246 const steps = Math.max(2, Math.ceil(N * prog));247 for (let i = 0; i <= steps; i++) {248 const [wx, wy] = world((prog * i) / steps);249 pts.push(proj(wx, wy));250 }251 const d = pts252 .map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(2)} ${y.toFixed(2)}`)253 .join(" ");254 const [sx0, sy0] = proj(L, B);255 const [sxr] = proj(Rr, B);256 const [tipX, tipY] = proj(tipWx, tipWy);257 const fillD = `${d} L${tipX.toFixed(2)} ${sy0.toFixed(2)} L${pts[0][0].toFixed(2)} ${sy0.toFixed(2)} Z`;258 const [, syTop] = proj(L, T);259260 // Parallax dot grid behind the line (moves at a fraction of the camera)261 const zp = 1 + (z - 1) * 0.45;262 const gap = 44 * u * zp;263 const gx = (((ax - cx * zp) % gap) + gap) % gap;264 const gy = (((ay - cy * zp) % gap) + gap) % gap;265266 const enter = interpolate(t, [0, 10], [0.55, 1], CLAMP);267268 // A running count rides just ahead of the tip and hands off to the value.269 const target = parseValue(value);270 const marks = milestones.flatMap((m) => {271 if (m.at !== undefined) return [{ at: m.at, label: m.label }];272 const v = parseValue(m.label);273 if (v === null || target === null || v <= 0 || v >= target) return [];274 // invert the base curve: x where f(x) = v / target275 const at = Math.log(1 + (v / target) * (Math.exp(k) - 1)) / k;276 return [{ at, label: m.label }];277 });278 const count = target === null ? null : Math.round(target * base(prog));279 const countO =280 interpolate(t, [0, 6], [0.4, 1], CLAMP) *281 interpolate(t, [HIT - 4, HIT + 2], [1, 0], CLAMP);282283 // Final hit284 const hit = spring({285 frame: t - HIT,286 fps,287 config: { damping: 15, stiffness: 170, mass: 0.7 },288 });289 const hitO = interpolate(t, [HIT, HIT + 6], [0, 1], CLAMP);290 const ring = interpolate(t, [HIT, HIT + 26], [0, 1], {291 ...CLAMP,292 easing: EASE_OUT,293 });294 const lab = interpolate(t, [HIT + 8, HIT + 28], [0, 1], {295 ...CLAMP,296 easing: EASE_OUT,297 });298 const valueSize = 128 * u;299300 return (301 <AbsoluteFill302 style={{303 background:304 background === "transparent" ? undefined : (background ?? p.bg),305 overflow: "hidden",306 }}307 >308 {/* depth: a sparse dot plane that drifts slower than the line */}309 <AbsoluteFill310 style={{311 backgroundImage: `radial-gradient(circle at center, ${p.dot} ${1.1 * u}px, transparent ${1.7 * u}px)`,312 backgroundSize: `${gap}px ${gap}px`,313 backgroundPosition: `${gx - gap / 2}px ${gy - gap / 2}px`,314 WebkitMaskImage:315 "radial-gradient(ellipse 70% 70% at 50% 50%, #000 20%, transparent 100%)",316 maskImage:317 "radial-gradient(ellipse 70% 70% at 50% 50%, #000 20%, transparent 100%)",318 opacity: enter,319 }}320 />321 {/* soft light that follows the tip */}322 <AbsoluteFill323 style={{324 background: `radial-gradient(circle ${height * 0.5}px at ${tipX}px ${tipY}px, ${p.wash}, transparent 100%)`,325 }}326 />327328 <ScaleLayer scale={scale}>329 <svg330 width={width}331 height={height}332 style={{ position: "absolute", inset: 0, opacity: enter }}333 aria-hidden334 >335 <defs>336 <linearGradient337 id={`${id}s`}338 gradientUnits="userSpaceOnUse"339 x1={pts[0][0]}340 y1={pts[0][1]}341 x2={tipX}342 y2={tipY}343 >344 <stop offset="0" stopColor={p.line[0]} stopOpacity={p.tail} />345 <stop offset="0.42" stopColor={p.line[1]} stopOpacity={0.9} />346 <stop offset="0.86" stopColor={p.line[2]} stopOpacity={1} />347 <stop offset="1" stopColor={p.line[3]} stopOpacity={1} />348 </linearGradient>349 {/* area: the same palette left to right, faded out toward the axis */}350 <linearGradient351 id={`${id}f`}352 gradientUnits="userSpaceOnUse"353 x1={pts[0][0]}354 y1={0}355 x2={tipX}356 y2={0}357 >358 <stop offset="0" stopColor={p.line[0]} />359 <stop offset="0.5" stopColor={p.line[1]} />360 <stop offset="1" stopColor={p.line[2]} />361 </linearGradient>362 <linearGradient363 id={`${id}v`}364 gradientUnits="userSpaceOnUse"365 x1={0}366 y1={Math.min(tipY, syTop)}367 x2={0}368 y2={sy0}369 >370 <stop offset="0" stopColor="#fff" stopOpacity={p.fill} />371 <stop offset="1" stopColor="#fff" stopOpacity={0} />372 </linearGradient>373 <mask id={`${id}m`} maskUnits="userSpaceOnUse">374 <rect375 x={0}376 y={Math.min(tipY, syTop) - 10}377 width={width}378 height={height * 4}379 fill={`url(#${id}v)`}380 />381 </mask>382 <radialGradient id={`${id}h`}>383 <stop offset="0" stopColor={p.line[2]} stopOpacity={0.3} />384 <stop offset="1" stopColor={p.line[2]} stopOpacity={0} />385 </radialGradient>386 </defs>387388 {/* hairline axes */}389 <line390 x1={sx0}391 y1={sy0}392 x2={sxr}393 y2={sy0}394 stroke={p.axis}395 strokeWidth={Math.max(1, u)}396 />397 <line398 x1={sx0}399 y1={sy0}400 x2={sx0}401 y2={syTop}402 stroke={p.axis}403 strokeWidth={Math.max(1, u)}404 />405406 <path d={fillD} fill={`url(#${id}f)`} mask={`url(#${id}m)`} />407 <path408 d={d}409 fill="none"410 stroke={`url(#${id}s)`}411 strokeWidth={strokeWidth * u}412 strokeLinecap="round"413 strokeLinejoin="round"414 />415416 {/* milestones */}417 {marks.map((m) => {418 const [mx, my] = proj(...world(m.at));419 const reach = reachFrame(m.at);420 const pop = spring({421 frame: t - reach,422 fps,423 config: { damping: 13, stiffness: 190, mass: 0.6 },424 });425 if (t < reach) return null;426 return (427 <g key={m.label}>428 <circle429 cx={mx}430 cy={my}431 r={5.5 * u * (0.6 + 0.4 * pop)}432 fill={p.bg}433 stroke={accent}434 strokeWidth={2.2 * u}435 opacity={Math.min(1, pop * 1.5)}436 />437 </g>438 );439 })}440441 {/* tip */}442 <circle cx={tipX} cy={tipY} r={18 * u} fill={`url(#${id}h)`} />443 <circle444 cx={tipX}445 cy={tipY}446 r={lerp(6, 40, ring) * u}447 fill="none"448 stroke={p.line[2]}449 strokeWidth={1.5 * u}450 opacity={t >= HIT ? (1 - ring) * 0.7 : 0}451 />452 <circle cx={tipX} cy={tipY} r={5 * u} fill={p.tip} />453 <circle cx={tipX} cy={tipY} r={1.8 * u} fill={p.bg} opacity={0.9} />454 </svg>455456 {/* milestone labels: screen-space type, upper-left of the dot */}457 {marks.map((m) => {458 const [mx, my] = proj(...world(m.at));459 const reach = reachFrame(m.at);460 const a = interpolate(t, [reach + 1, reach + 14], [0, 1], {461 ...CLAMP,462 easing: EASE_OUT,463 });464 // labels quiet down once the camera pulls back so the value owns the frame465 const quiet = interpolate(t, [HIT - 6, HIT + 14], [1, 0.55], CLAMP);466 return (467 <div468 key={m.label}469 style={{470 position: "absolute",471 left: mx - 200 * u,472 top: my - 46 * u,473 width: 200 * u + 6 * u,474 textAlign: "right",475 fontFamily,476 fontWeight: 500,477 fontSize: 17 * u,478 letterSpacing: "-0.01em",479 color: fg,480 opacity: a * quiet,481 transform: `translateY(${(1 - a) * 10 * u}px)`,482 fontVariantNumeric: "tabular-nums",483 whiteSpace: "nowrap",484 }}485 >486 {m.label}487 </div>488 );489 })}490491 {count !== null && (492 <div493 style={{494 position: "absolute",495 left: tipX + 14 * u,496 top: tipY - 34 * u,497 fontFamily,498 fontWeight: 400,499 fontSize: 16 * u,500 letterSpacing: "-0.01em",501 color: p.muted,502 fontVariantNumeric: "tabular-nums",503 opacity: countO,504 whiteSpace: "nowrap",505 }}506 >507 {count.toLocaleString("en-US")}508 </div>509 )}510511 {/* the value lands at the tip */}512 <div513 style={{514 position: "absolute",515 right: width - tipX + 78 * u,516 top: tipY - 16 * u,517 textAlign: "right",518 opacity: hitO,519 transform: `translateY(${(1 - hit) * 26 * u}px) scale(${1.06 - 0.06 * hit})`,520 transformOrigin: "100% 0%",521 }}522 >523 <div524 style={{525 fontFamily,526 fontWeight,527 fontSize: valueSize,528 lineHeight: 0.9,529 letterSpacing: "-0.05em",530 color: fg,531 fontVariantNumeric: "tabular-nums",532 whiteSpace: "nowrap",533 }}534 >535 {value}536 </div>537 <div538 style={{539 marginTop: 14 * u,540 fontFamily,541 fontWeight: 400,542 fontSize: 20 * u,543 letterSpacing: "-0.01em",544 color: p.muted,545 opacity: lab,546 transform: `translateY(${(1 - lab) * 10 * u}px)`,547 whiteSpace: "nowrap",548 }}549 >550 {label}551 </div>552 </div>553 </ScaleLayer>554555 <AbsoluteFill556 style={{557 background: `radial-gradient(ellipse 80% 80% at 50% 50%, transparent 60%, ${p.bg} 100%)`,558 opacity: 0.7,559 }}560 />561 {grain ? <Grain opacity={p.grain} /> : null}562 </AbsoluteFill>563 );564}









