Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "rotary-dial",
"title": "Rotary Dial",
"description": "A knurled dial turns to 10 while its arc heats up and 10x render speed counts up.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/rotary-dial/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/SpaceGrotesk\";\nimport type React from \"react\";\nimport {\n AbsoluteFill,\n Easing,\n interpolate,\n spring,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n weights: [\"300\", \"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface RotaryDialProps {\n from?: number;\n to?: number;\n unit?: string;\n label?: string;\n accent?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n speed?: number;\n}\n\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst BEATS = {\n label: 6,\n value: 12,\n grab: 18,\n turn: 24,\n land: 72,\n} as const;\n\nconst HEAVY = { mass: 1, damping: 26, stiffness: 120 };\nconst CHIP = { mass: 0.5, damping: 12, stiffness: 200 };\n\nconst THEMES = {\n dark: {\n fg: \"#F3F2EF\",\n muted: \"rgba(243,242,239,0.56)\",\n lit: \"#9DC2FF\",\n tick: \"rgba(255,255,255,0.2)\",\n scrim: \"4,6,12\",\n scrimFrom: 0.86,\n scrimTo: 0.4,\n collar: \"#0E0F13\",\n collarLip: \"rgba(255,255,255,0.09)\",\n knurl: [\"#17181C\", \"#34353B\"],\n metal: { mid: \"#3E3F45\", lo: \"#27282C\", hi: \"#7C7D85\", hi2: \"#5A5B62\" },\n chamfer: [\"rgba(255,255,255,0.4)\", \"rgba(0,0,0,0.6)\"],\n shadow: \"0,0,0\",\n shadowA: 0.8,\n },\n light: {\n fg: \"#141413\",\n muted: \"rgba(20,20,19,0.52)\",\n lit: \"\",\n tick: \"rgba(30,26,20,0.2)\",\n scrim: \"244,243,239\",\n scrimFrom: 0.88,\n scrimTo: 0.36,\n collar: \"#DEDBD3\",\n collarLip: \"rgba(255,255,255,0.95)\",\n knurl: [\"#8F8E92\", \"#C9C8CC\"],\n metal: { mid: \"#C4C4C8\", lo: \"#A5A5AA\", hi: \"#F4F4F6\", hi2: \"#DCDCE0\" },\n chamfer: [\"rgba(255,255,255,0.95)\", \"rgba(40,36,30,0.35)\"],\n shadow: \"48,40,28\",\n shadowA: 0.36,\n },\n} as const;\n\nfunction hexToRgb(hex: string) {\n const h = hex.replace(\"#\", \"\");\n const n = Number.parseInt(\n h.length === 3\n ? h\n .split(\"\")\n .map((c) => c + c)\n .join(\"\")\n : h,\n 16,\n );\n return `${(n >> 16) & 255},${(n >> 8) & 255},${n & 255}`;\n}\n\nfunction niceStep(range: number) {\n const raw = range / 9;\n const pow = 10 ** Math.floor(Math.log10(raw));\n const n = raw / pow;\n const k = n <= 1 ? 1 : n <= 2 ? 2 : n <= 2.5 ? 2.5 : n <= 5 ? 5 : 10;\n return k * pow;\n}\n\nfunction formatLabel(v: number) {\n return Number.isInteger(v) ? String(v) : v.toFixed(1);\n}\n\nfunction Odometer({\n value,\n decimals,\n size,\n}: {\n value: number;\n decimals: number;\n size: number;\n}) {\n const m = 10 ** decimals;\n const scaled = value * m;\n const k = Math.floor(scaled + 1e-6);\n const frac = Math.max(0, scaled - k);\n const r = interpolate(frac, [0.45, 1], [0, 1], { ...CLAMP, easing: MOVE });\n const fmt = (n: number) => {\n const s = String(Math.abs(n)).padStart(decimals + 1, \"0\");\n return decimals ? `${s.slice(0, -decimals)}.${s.slice(-decimals)}` : s;\n };\n const a = fmt(k);\n const b = fmt(k + 1);\n const len = Math.max(a.length, b.length);\n const pa = a.padStart(len, \" \");\n const pb = b.padStart(len, \" \");\n const colW = 0.62 * size;\n const cols: React.ReactNode[] = [];\n for (let i = 0; i < len; i++) {\n const ca = pa[i];\n const cb = pb[i];\n const isDot = ca === \".\" || cb === \".\";\n const w = isDot\n ? 0.28 * size\n : ca === \" \"\n ? colW * r\n : cb === \" \"\n ? colW * (1 - r)\n : colW;\n const rolling = ca !== cb;\n const blur = Math.sin(r * Math.PI) * size * 0.03;\n cols.push(\n <span\n key={i}\n style={{\n position: \"relative\",\n display: \"inline-block\",\n width: w,\n height: size,\n textAlign: \"center\",\n }}\n >\n {rolling ? (\n <>\n <span\n style={{\n position: \"absolute\",\n left: -0.2 * size,\n right: -0.2 * size,\n top: 0,\n transform: `translateY(${-r * size * 0.42}px)`,\n opacity: (1 - r) ** 2,\n filter: blur > 0.2 ? `blur(${blur}px)` : undefined,\n }}\n >\n {ca}\n </span>\n <span\n style={{\n position: \"absolute\",\n left: -0.2 * size,\n right: -0.2 * size,\n top: 0,\n transform: `translateY(${(1 - r) * size * 0.42}px)`,\n opacity: r ** 1.5,\n filter: blur > 0.2 ? `blur(${blur}px)` : undefined,\n }}\n >\n {cb}\n </span>\n </>\n ) : (\n <span\n style={{\n position: \"absolute\",\n left: -0.2 * size,\n right: -0.2 * size,\n top: 0,\n }}\n >\n {ca}\n </span>\n )}\n </span>,\n );\n }\n return <>{cols}</>;\n}\n\nexport function RotaryDial({\n from = 1,\n to = 10,\n unit = \"×\",\n label = \"Render speed\",\n accent = \"#3B5BFD\",\n theme = \"dark\",\n ground,\n groundParams,\n speed = 1,\n}: RotaryDialProps) {\n const t = useCurrentFrame() * speed;\n const { width: VW, height: VH, fps } = useVideoConfig();\n const tall = VH > VW;\n const u = tall ? VW / 760 : Math.min(VW / 1280, VH / 720);\n const p = THEMES[theme];\n const dark = theme === \"dark\";\n const acc = hexToRgb(accent);\n const lit = p.lit || accent;\n const resolvedGround: GshPresetId | undefined =\n ground ?? (groundParams ? undefined : dark ? \"earthshine\" : \"paper-crease\");\n\n const range = to - from;\n const span = Math.abs(range) || 1;\n const step = niceStep(span);\n const decimals = span < 5 ? 1 : 0;\n const lo = Math.min(from, to);\n const hi = Math.max(from, to);\n\n const A0 = -135;\n const A1 = 135;\n const prog = (f: number) => {\n const move = interpolate(f, [BEATS.turn, BEATS.land], [0, 1.025], {\n ...CLAMP,\n easing: MOVE,\n });\n const detent = spring({ frame: f - BEATS.land, fps, config: CHIP });\n return move - 0.025 * Math.min(1, detent);\n };\n const k = prog(t);\n const kc = Math.min(1, k);\n const angle = A0 + (A1 - A0) * k;\n const angVel = Math.abs(prog(t + 0.5) - prog(t - 0.5)) * (A1 - A0);\n const value = Math.min(hi, Math.max(lo, from + range * kc));\n const rest = Math.min(1, angVel / 8);\n\n const grab = interpolate(\n t,\n [BEATS.grab, BEATS.turn, BEATS.land - 6, BEATS.land],\n [0, 1, 1, 0],\n { ...CLAMP, easing: MOVE },\n );\n const click = spring({ frame: t - BEATS.land, fps, config: CHIP });\n const clickPunch = Math.sin(Math.min(1, click) * Math.PI) * 0.025;\n const knobScale = 1 - grab * 0.03 + clickPunch;\n\n const R = (tall ? 190 : 140) * u;\n const rCollar = R + 12 * u;\n const rFace = R - 17 * u;\n const rTick = R + 32 * u;\n const rLabel = R + 66 * u;\n const box = (rLabel + 30 * u) * 2;\n\n const ticks: React.ReactNode[] = [];\n const labels: React.ReactNode[] = [];\n const minorPer = 5;\n const count = Math.round(span / step) * minorPer;\n for (let i = 0; i <= count; i++) {\n const frac = i / count;\n const a = A0 + (A1 - A0) * frac;\n const major = i % minorPer === 0;\n const behind = Math.min(angle, A1) - a;\n const on = interpolate(behind, [-1.2, 0.6], [0, 1], CLAMP);\n const flash = on * rest * Math.exp(-Math.max(0, behind) / 22);\n const len = (major ? 20 : 11) * u * (1 + flash * 0.3);\n const wid = (major ? 3 : 2) * u;\n ticks.push(\n <div\n key={i}\n style={{\n position: \"absolute\",\n left: box / 2 - wid / 2,\n top: box / 2 - rTick - len,\n width: wid,\n height: len,\n borderRadius: wid,\n transformOrigin: `50% ${rTick + len}px`,\n transform: `rotate(${a}deg)`,\n background: on > 0.01 ? lit : p.tick,\n opacity: on > 0.01 ? 0.5 + 0.5 * on : 1,\n }}\n />,\n );\n if (i === 0 || i === count) {\n const v = from + (range * i) / count;\n const rad = (a * Math.PI) / 180;\n const x = box / 2 + Math.sin(rad) * rLabel;\n const y = box / 2 - Math.cos(rad) * rLabel;\n labels.push(\n <div\n key={`l${i}`}\n style={{\n position: \"absolute\",\n left: x - 40 * u,\n top: y - 12 * u + 14 * u,\n width: 80 * u,\n height: 24 * u,\n lineHeight: `${24 * u}px`,\n textAlign: \"center\",\n fontFamily: sans,\n fontWeight: 400,\n fontSize: 18 * u,\n fontVariantNumeric: \"tabular-nums\",\n color: on > 0.5 ? p.fg : p.muted,\n }}\n >\n {formatLabel(v)}\n {unit}\n </div>,\n );\n }\n }\n\n const m = p.metal;\n const circle = (r: number): React.CSSProperties => ({\n position: \"absolute\",\n left: box / 2 - r,\n top: box / 2 - r,\n width: r * 2,\n height: r * 2,\n borderRadius: \"50%\",\n });\n const ridge = 3;\n\n const cam = spring({\n frame: t,\n fps,\n config: HEAVY,\n durationInFrames: 54,\n });\n const push = interpolate(t, [BEATS.land, BEATS.land + 60], [0, 1], {\n ...CLAMP,\n easing: MOVE,\n });\n const camK = interpolate(cam, [0, 1], [1.08, 1]) + push * 0.02;\n const light = interpolate(t, [BEATS.turn, BEATS.land + 6], [0, 1], {\n ...CLAMP,\n easing: ENTER,\n });\n const scrim = interpolate(light, [0, 1], [p.scrimFrom, p.scrimTo]);\n const bloom = interpolate(\n t,\n [BEATS.land, BEATS.land + 4, BEATS.land + 40],\n [0, 1, 0.55],\n {\n ...CLAMP,\n easing: ENTER,\n },\n );\n\n const word = (start: number) =>\n interpolate(t, [start, start + 14], [0, 1], { ...CLAMP, easing: ENTER });\n const ink = (v: number): React.CSSProperties => ({\n opacity: v,\n transform: `translateY(${(1 - v) * 0.22}em)`,\n filter: v < 1 ? `blur(${(1 - v) * 6 * u}px)` : undefined,\n });\n const wLabel = word(BEATS.label);\n const wValue = word(BEATS.value);\n const numSize = (tall ? 168 : 150) * u;\n\n const dial = (\n <div\n style={{\n position: \"relative\",\n width: box,\n height: box,\n flexShrink: 0,\n }}\n >\n {ticks}\n {labels}\n <div\n style={{\n ...circle(rCollar),\n background: p.collar,\n boxShadow: [\n `inset 0 ${3 * u}px ${6 * u}px rgba(${p.shadow},${p.shadowA})`,\n `inset 0 ${-1.2 * u}px 0 ${p.collarLip}`,\n `0 0 ${70 * u}px ${-6 * u}px rgba(${acc},${0.5 * bloom})`,\n ].join(\", \"),\n }}\n />\n <div\n style={{\n ...circle(rCollar),\n transform: `scale(${knobScale})`,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: rCollar - R,\n top: rCollar - R,\n width: R * 2,\n height: R * 2,\n borderRadius: \"50%\",\n boxShadow: [\n `0 ${(16 - grab * 6) * u}px ${(30 - grab * 8) * u}px rgba(${p.shadow},${p.shadowA * 0.7})`,\n `0 ${3 * u}px ${6 * u}px rgba(${p.shadow},${p.shadowA * 0.6})`,\n ].join(\", \"),\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: `repeating-conic-gradient(from ${angle}deg, ${p.knurl[0]} 0deg ${ridge / 2}deg, ${p.knurl[1]} ${ridge / 2}deg ${ridge}deg)`,\n filter: rest > 0.05 ? `blur(${rest * 1.6 * u}px)` : undefined,\n opacity: 1 - rest * 0.35,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background:\n \"linear-gradient(180deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0.04) 40%, rgba(0,0,0,0.35) 78%, rgba(0,0,0,0.55) 100%)\",\n }}\n />\n </div>\n <div\n style={{\n position: \"absolute\",\n left: rCollar - rFace - 3 * u,\n top: rCollar - rFace - 3 * u,\n width: (rFace + 3 * u) * 2,\n height: (rFace + 3 * u) * 2,\n borderRadius: \"50%\",\n background: `linear-gradient(180deg, ${p.chamfer[0]}, ${p.chamfer[1]})`,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n left: rCollar - rFace,\n top: rCollar - rFace,\n width: rFace * 2,\n height: rFace * 2,\n borderRadius: \"50%\",\n background: [\n `repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,0.035) 0 ${0.8 * u}px, rgba(0,0,0,0.04) ${0.8 * u}px ${1.7 * u}px)`,\n \"radial-gradient(circle at 50% 42%, rgba(255,255,255,0.06), transparent 60%)\",\n `conic-gradient(from 0deg, ${m.mid} 0deg, ${m.lo} 62deg, ${m.mid} 108deg, ${m.hi2} 150deg, ${m.mid} 192deg, ${m.lo} 244deg, ${m.mid} 290deg, ${m.hi} 328deg, ${m.mid} 360deg)`,\n ].join(\", \"),\n boxShadow: `inset 0 ${1.5 * u}px ${2 * u}px rgba(0,0,0,0.35)`,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n left: rCollar - rFace,\n top: rCollar - rFace,\n width: rFace * 2,\n height: rFace * 2,\n transform: `rotate(${angle}deg)`,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: rFace - 3.5 * u,\n top: 12 * u,\n width: 7 * u,\n height: 40 * u,\n borderRadius: 4 * u,\n background: lit,\n boxShadow: `inset 0 ${1.5 * u}px ${2 * u}px rgba(0,0,0,0.35), 0 0 ${10 * u * bloom}px rgba(${acc},${0.6 * bloom})`,\n }}\n />\n </div>\n </div>\n </div>\n );\n\n const readout = (\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: tall ? \"center\" : \"flex-start\",\n gap: 4 * u,\n minWidth: tall ? undefined : 300 * u,\n }}\n >\n <div\n style={{\n ...ink(wLabel),\n fontFamily: sans,\n fontWeight: 400,\n fontSize: (tall ? 34 : 28) * u,\n letterSpacing: \"-0.01em\",\n color: p.muted,\n paddingLeft: tall ? 0 : 6 * u,\n }}\n >\n {label}\n </div>\n <div\n style={{\n ...ink(wValue),\n display: \"flex\",\n alignItems: \"baseline\",\n fontFamily: sans,\n fontWeight: 300,\n fontSize: numSize,\n lineHeight: `${numSize}px`,\n letterSpacing: \"-0.04em\",\n fontVariantNumeric: \"tabular-nums\",\n color: p.fg,\n whiteSpace: \"nowrap\",\n }}\n >\n <Odometer value={value} decimals={decimals} size={numSize} />\n <span\n style={{\n color: lit,\n fontSize: numSize * 0.6,\n lineHeight: `${numSize}px`,\n marginLeft: 0.06 * numSize,\n }}\n >\n {unit}\n </span>\n </div>\n </div>\n );\n\n return (\n <AbsoluteFill\n style={{ overflow: \"hidden\", background: dark ? \"#03050b\" : \"#eeece8\" }}\n >\n <GshGround\n preset={resolvedGround}\n params={groundParams}\n timeOffset={dark ? 3 : 6}\n timeScale={0.5}\n />\n <AbsoluteFill\n style={{\n background: `radial-gradient(70% 60% at 50% 45%, rgba(${p.scrim},${scrim}) 0%, rgba(${p.scrim},${Math.min(1, scrim + 0.12)}) 100%)`,\n }}\n />\n <AbsoluteFill\n style={{\n alignItems: \"center\",\n justifyContent: \"center\",\n transform: `scale(${camK})`,\n }}\n >\n <div\n style={{\n display: \"flex\",\n flexDirection: tall ? \"column\" : \"row\",\n alignItems: \"center\",\n gap: (tall ? 40 : 40) * u,\n transform: tall ? `translateY(${-150 * u}px)` : undefined,\n }}\n >\n {dial}\n {readout}\n </div>\n </AbsoluteFill>\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/rotary-dial.tsx"
}
],
"type": "registry:component"
}