Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [
{
"name": "@remotion/google-fonts",
"version": null
}
],
"dimensions": null,
"displayName": "Block City",
"initialProps": null,
"slug": "block-city",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/Sora\";\nimport React, { forwardRef, useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst { fontFamily: sora } = loadFont(\"normal\", {\n weights: [\"300\", \"400\"],\n subsets: [\"latin\"],\n});\n\ninterface BlockCityProps {\n /** Hero number, counted up on the accent block. */\n value?: number;\n prefix?: string;\n suffix?: string;\n /** Muted word after the number. */\n caption?: string;\n /** Optional dataset: one value per column, left to right (any scale). */\n data?: number[];\n accent?: string;\n /** Playback multiplier. */\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst RISE = Easing.bezier(0.3, 1.18, 0.5, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst COLS = 20;\nconst ROWS = 12;\nconst CELL = 52;\nconst FOOT = 37;\n\n// camera keyframes: [frame, pitch°, yaw°, camX, camY, dolly, lens] (lengths in u).\n// Fly low along the columns on a wide lens, then crane up and orbit to a long-lens\n// front view where the skyline reads as a bar chart.\nconst CAM: [number, number, number, number, number, number, number][] = [\n [0, 76, -90, -150, 20, 260, 760],\n [112, 70, -76, 200, 60, -140, 900],\n [140, 69, -72, 220, 50, -170, 940],\n [210, 52, -20, 20, -110, -300, 1300],\n];\n\nconst T_HERO = 112;\nconst T_LABEL = 178;\n\n// gradients.sh \"fluted\" palette: bg #050507, [#1d2a8f, #2f7bff, #ff7a3d, #ffe2c4].\n// It runs up the hero tower (deep blue at the street, warm at the roof) and tints the sky.\nconst FLUTED: RGB[] = [\n [29, 42, 143],\n [47, 123, 255],\n [255, 122, 61],\n [255, 226, 196],\n];\n\nconst PALETTES = {\n dark: {\n bg: [6, 6, 9],\n haze: [22, 23, 30],\n top: [92, 92, 98],\n side: [38, 38, 43],\n ground: \"#0E0E10\",\n line: \"rgba(255,255,255,0.05)\",\n fg: \"#F3F2EF\",\n muted: \"#8B8A90\",\n lead: \"rgba(255,255,255,0.35)\",\n sky: \"rgba(47,123,255,0.10)\",\n dusk: \"rgba(29,42,143,0.32)\",\n ring: \"rgba(6,6,9,0.9)\",\n spill: 0.2,\n grain: 0.06,\n },\n light: {\n bg: [245, 244, 240],\n haze: [240, 238, 233],\n top: [255, 255, 253],\n side: [228, 224, 216],\n ground: \"#EEECE6\",\n line: \"rgba(18,18,20,0.06)\",\n fg: \"#121214\",\n muted: \"#6E6C67\",\n lead: \"rgba(18,18,20,0.3)\",\n sky: \"rgba(255,255,255,0.9)\",\n dusk: \"rgba(255,226,196,0.55)\",\n ring: \"rgba(245,244,240,0.9)\",\n spill: 0.12,\n grain: 0.04,\n },\n} as const;\n\ntype Palette = (typeof PALETTES)[keyof typeof PALETTES];\ntype RGB = readonly number[];\n\nfunction hash(n: number) {\n const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;\n return x - Math.floor(x);\n}\n\nconst mix = (a: RGB, b: RGB, k: number): RGB => [\n a[0] + (b[0] - a[0]) * k,\n a[1] + (b[1] - a[1]) * k,\n a[2] + (b[2] - a[2]) * k,\n];\nconst shade = (c: RGB, k: number): RGB => [c[0] * k, c[1] * k, c[2] * k];\nconst css = (c: RGB) =>\n `rgb(${Math.round(c[0])},${Math.round(c[1])},${Math.round(c[2])})`;\n\n/** Deterministic dataset: a rising trend across columns, a ripple across rows. */\nfunction heightAt(c: number, r: number, data?: number[]) {\n const trend = data?.length\n ? (() => {\n const max = Math.max(...data);\n const v = data[Math.round((c / (COLS - 1)) * (data.length - 1))];\n return max > 0 ? v / max : 0;\n })()\n : 0.22 + 0.78 * (c / (COLS - 1)) ** 1.7;\n const ripple = 0.66 + 0.34 * Math.sin(r * 0.85 + c * 0.45);\n const noise = 0.85 + hash(c * 31 + r * 7) * 0.3;\n return 12 + 190 * trend * ripple * noise;\n}\n\nfunction camAt(t: number) {\n let i = 0;\n while (i < CAM.length - 2 && t > CAM[i + 1][0]) i++;\n const a = CAM[i];\n const b = CAM[i + 1];\n const k = interpolate(t, [a[0], b[0]], [0, 1], {\n ...CLAMP,\n easing: EASE_IO,\n });\n const v = a.map((x, j) => x + (b[j] - x) * k);\n return {\n pitch: v[1],\n yaw: v[2],\n camX: v[3],\n camY: v[4],\n dolly: v[5],\n lens: v[6],\n };\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{ position: \"absolute\", inset: 0, opacity }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\n numOctaves={2}\n seed={31}\n stitchTiles=\"stitch\"\n />\n <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\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\nconst face: React.CSSProperties = {\n position: \"absolute\",\n left: 0,\n top: 0,\n transformOrigin: \"0 0\",\n};\n\nfunction BlockCityBase({\n value = 340,\n prefix = \"+\",\n suffix = \"%\",\n caption = \"renders\",\n data,\n accent = \"#3B5BFD\",\n speed = 1,\n theme = \"dark\",\n}: BlockCityProps) {\n const t = useCurrentFrame() * speed;\n const { width, height } = useVideoConfig();\n const u = height / 720;\n const pal: Palette = PALETTES[theme];\n\n const cam = camAt(t);\n const persp = cam.lens * u;\n const rad = Math.PI / 180;\n const cp = Math.cos(cam.pitch * rad);\n const sp = Math.sin(cam.pitch * rad);\n const cyw = Math.cos(cam.yaw * rad);\n const syw = Math.sin(cam.yaw * rad);\n\n // the same transform chain as the CSS camera, for fog and the 2D label\n const project = (x: number, y: number, z: number) => {\n const px = x - cam.camX * u;\n const py = y - cam.camY * u;\n const rx = px * cyw - py * syw;\n const ry = px * syw + py * cyw;\n const y2 = ry * cp - z * sp;\n const z2 = ry * sp + z * cp + cam.dolly * u;\n const s = persp / (persp - z2);\n return { x: width / 2 + rx * s, y: height / 2 + y2 * s, z: z2 };\n };\n\n const heroC = COLS - 3;\n const heroR = ROWS - 3;\n const tallest = Math.max(\n ...Array.from({ length: COLS * ROWS }, (_, n) =>\n heightAt(n % COLS, Math.floor(n / COLS), data),\n ),\n );\n const heroH = tallest * 1.95 * u;\n\n // the rise wave travels from the near rows to the far rows with the camera\n const wave = interpolate(t, [0, 112], [5, COLS + 3], CLAMP);\n const heroP = interpolate(t, [T_HERO, T_HERO + 26], [0, 1], {\n ...CLAMP,\n easing: RISE,\n });\n const heroTint = interpolate(t, [T_HERO - 4, T_HERO + 12], [0, 1], CLAMP);\n\n const blocks: React.ReactNode[] = [];\n const s = FOOT * u;\n for (let r = 0; r < ROWS; r++) {\n for (let c = 0; c < COLS; c++) {\n const bx = (c - (COLS - 1) / 2) * CELL * u;\n const by = (r - (ROWS - 1) / 2) * CELL * u;\n const target = heightAt(c, r, data) * u;\n const lead = (wave - c + 2.6 - hash(c * 5 + r * 3) * 0.9) / 2.6;\n const rise = RISE(Math.max(0, Math.min(1, lead)));\n const isHero = c === heroC && r === heroR;\n let h = Math.max(2 * u, target * rise);\n if (isHero) h = h + (heroH - target) * heroP;\n\n // fog by distance past the point the camera looks at; cull what is behind the lens\n const pc = project(bx, by, h * 0.5);\n if (pc.z > persp * 0.86 || pc.y > height * 2) continue;\n const beyond = persp - pc.z - (persp - cam.dolly * u);\n const fog = interpolate(beyond, [-200 * u, 950 * u], [0, 0.88], CLAMP);\n // the hero tower throws warm light on its neighbours\n const near = (c - heroC) ** 2 + (r - heroR) ** 2;\n const spill = isHero ? 0 : heroTint * pal.spill * Math.exp(-near / 5);\n const baseTop: RGB = isHero\n ? mix(pal.top, FLUTED[3], heroTint)\n : mix(pal.top, FLUTED[2], spill);\n const baseSide: RGB = mix(pal.side, FLUTED[2], spill * 0.8);\n const bg = pal.haze;\n const top = css(mix(baseTop, bg, fog));\n const sideLit = mix(shade(baseSide, 1.08), bg, fog);\n const sideFront = mix(shade(baseSide, 0.9), bg, fog);\n const sideDark = mix(shade(baseSide, 0.72), bg, fog);\n // hero: the fluted gradient runs from the street (top of the face div) to the roof\n const heroFace = (k: number) => {\n const stops = FLUTED.map((c) =>\n css(mix(mix(shade(pal.side, k), shade(c, k), heroTint), bg, fog)),\n );\n return `linear-gradient(180deg, ${stops[0]} 0%, ${stops[1]} 38%, ${stops[2]} 78%, ${stops[3]} 100%)`;\n };\n const ao = (c3: RGB) =>\n `linear-gradient(180deg, ${css(mix(shade(c3, 0.72), bg, fog * 0.6))} 0%, ${css(c3)} ${Math.min(100, (40 * u * 100) / Math.max(h, 1))}%, ${css(c3)} 100%)`;\n\n blocks.push(\n <div\n key={`${c}-${r}`}\n style={{\n position: \"absolute\",\n left: 0,\n top: 0,\n transformStyle: \"preserve-3d\",\n transform: `translate3d(${bx}px, ${by}px, 0px)`,\n }}\n >\n {/* left (-x) */}\n <div\n style={{\n ...face,\n width: s,\n height: h,\n background: isHero ? heroFace(1.04) : ao(sideLit),\n transform: `translate3d(${-s / 2}px, ${-s / 2}px, 0px) rotateZ(90deg) rotateX(90deg)`,\n }}\n />\n {/* right (+x) */}\n <div\n style={{\n ...face,\n width: s,\n height: h,\n background: isHero ? heroFace(0.7) : ao(sideDark),\n transform: `translate3d(${s / 2}px, ${-s / 2}px, 0px) rotateZ(90deg) rotateX(90deg)`,\n }}\n />\n {/* front (+y) */}\n <div\n style={{\n ...face,\n width: s,\n height: h,\n background: isHero ? heroFace(0.88) : ao(sideFront),\n transform: `translate3d(${-s / 2}px, ${s / 2}px, 0px) rotateX(90deg)`,\n }}\n />\n {/* top */}\n <div\n style={{\n ...face,\n width: s,\n height: s,\n background: top,\n boxShadow: `inset 0 0 0 ${Math.max(0.6, 0.8 * u)}px ${css(mix(shade(baseTop, theme === \"dark\" ? 1.25 : 0.97), bg, fog))}`,\n transform: `translate3d(${-s / 2}px, ${-s / 2}px, ${h}px)`,\n }}\n />\n </div>,\n );\n }\n }\n\n const groundW = (COLS + 8) * CELL * u;\n const groundH = (ROWS + 8) * CELL * u;\n\n // hero label, placed in 2D from the projected roof of the hero block\n const heroX = (heroC - (COLS - 1) / 2) * CELL * u;\n const heroY = (heroR - (ROWS - 1) / 2) * CELL * u;\n const heroBase = heightAt(heroC, heroR, data) * u;\n const roof = project(heroX, heroY, heroBase + (heroH - heroBase) * heroP);\n const labelP = interpolate(t, [T_LABEL, T_LABEL + 22], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const count = interpolate(t, [T_LABEL, T_LABEL + 40], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const shown = Math.round(value * count);\n const leadLen = 40 * u;\n\n const fogTop = interpolate(cam.pitch, [54, 72], [0.18, 0.42]);\n\n return (\n <AbsoluteFill style={{ background: css(pal.bg), overflow: \"hidden\" }}>\n <AbsoluteFill\n style={{\n background: `radial-gradient(ellipse 80% 60% at 50% 18%, ${pal.sky}, transparent 70%), radial-gradient(ellipse 110% 46% at ${50 + Math.sin(t / 60) * 3}% 0%, ${pal.dusk}, transparent 72%)`,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n perspective: persp,\n perspectiveOrigin: \"50% 50%\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: width / 2,\n top: height / 2,\n width: 0,\n height: 0,\n transformStyle: \"preserve-3d\",\n transform: `translateZ(${cam.dolly * u}px) rotateX(${cam.pitch}deg) rotateZ(${cam.yaw}deg) translate3d(${-cam.camX * u}px, ${-cam.camY * u}px, 0px)`,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: -groundW / 2,\n top: -groundH / 2,\n width: groundW,\n height: groundH,\n background: `repeating-linear-gradient(90deg, ${pal.line} 0 ${Math.max(1, u)}px, transparent ${Math.max(1, u)}px ${CELL * u}px), repeating-linear-gradient(0deg, ${pal.line} 0 ${Math.max(1, u)}px, transparent ${Math.max(1, u)}px ${CELL * u}px), radial-gradient(closest-side, ${pal.ground}, ${css(pal.bg)})`,\n backgroundPosition: `${(CELL / 2 + 4) * u}px ${(CELL / 2 + 4) * u}px, ${(CELL / 2 + 4) * u}px ${(CELL / 2 + 4) * u}px, 0 0`,\n transform: \"translateZ(-1px)\",\n }}\n />\n {blocks}\n </div>\n </div>\n\n {/* atmospheric haze toward the horizon */}\n <AbsoluteFill\n style={{\n background: `linear-gradient(180deg, ${css(pal.bg)} 0%, rgba(${pal.haze.join(\",\")},${fogTop}) 24%, rgba(${pal.haze.join(\",\")},0) 50%)`,\n }}\n />\n\n {/* hero label: a roof marker, a short leader, the number to its left */}\n <div\n style={{\n position: \"absolute\",\n left: roof.x,\n top: roof.y,\n width: 0,\n height: 0,\n opacity: labelP,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: -3.5 * u,\n top: -3.5 * u,\n width: 7 * u,\n height: 7 * u,\n borderRadius: \"50%\",\n background: accent,\n boxShadow: `0 0 0 ${2 * u}px ${pal.ring}`,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n right: 10 * u,\n top: -0.5 * u,\n width: leadLen,\n height: Math.max(1, u),\n background: pal.lead,\n transformOrigin: \"100% 50%\",\n transform: `scaleX(${labelP})`,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n right: leadLen + 22 * u,\n top: -30 * u,\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"flex-end\",\n gap: 6 * u,\n whiteSpace: \"nowrap\",\n transform: `translateX(${(1 - labelP) * 14 * u}px)`,\n }}\n >\n <span\n style={{\n fontFamily: sora,\n fontWeight: 400,\n fontSize: 60 * u,\n letterSpacing: \"-0.045em\",\n lineHeight: 1,\n color: pal.fg,\n fontVariantNumeric: \"tabular-nums\",\n }}\n >\n {prefix}\n {shown}\n {suffix}\n </span>\n <span\n style={{\n fontFamily: sora,\n fontWeight: 300,\n fontSize: 18 * u,\n letterSpacing: \"0.01em\",\n color: pal.muted,\n }}\n >\n {caption}\n </span>\n </div>\n </div>\n\n <AbsoluteFill\n style={{\n background:\n theme === \"dark\"\n ? \"radial-gradient(ellipse 80% 80% at 50% 50%, transparent 60%, rgba(0,0,0,0.45) 100%)\"\n : \"radial-gradient(ellipse 85% 85% at 50% 50%, transparent 65%, rgba(110,100,85,0.1) 100%)\",\n }}\n />\n <Grain opacity={pal.grain} />\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n theme: {\n type: \"enum\",\n default: \"dark\",\n variants: {\n dark: {},\n light: {},\n },\n description: \"Theme\",\n },\n accent: {\n type: \"color\",\n default: \"#3B5BFD\",\n description: \"Accent\",\n },\n prefix: {\n type: \"text-content\",\n default: \"+\",\n description: \"Prefix\",\n },\n suffix: {\n type: \"text-content\",\n default: \"%\",\n description: \"Suffix\",\n },\n caption: {\n type: \"text-content\",\n default: \"renders\",\n description: \"Caption\",\n },\n value: {\n type: \"number\",\n default: 340,\n min: 0,\n max: 1020,\n step: 1,\n description: \"Value\",\n hiddenFromList: false,\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"theme\",\"accent\",\"prefix\",\"suffix\",\"caption\",\"value\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n prefix: \"+\",\n suffix: \"%\",\n caption: \"renders\",\n value: 340,\n speed: 1,\n};\n\ntype BlockCityElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof BlockCityBase>;\n\nconst BlockCityInner = forwardRef<\n HTMLDivElement,\n BlockCityElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<BlockCity>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <BlockCityBase\n {...(componentProps as unknown as ComponentProps<typeof BlockCityBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const BlockCity = Interactive.withSchema({\n Component: BlockCityInner,\n componentName: \"<BlockCity>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 218,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 218
}