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": [],
"dimensions": null,
"displayName": "Pendulum Wave",
"initialProps": null,
"slug": "pendulum-wave",
"sourceCode": "import { AbsoluteFill, Interactive, Sequence, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ntype PendulumWaveProps = {\n /** Number of pendulums. */\n count?: number;\n /** Swings the slowest pendulum makes per loop; pendulum i makes cycles + i. */\n cycles?: number;\n /** Frames until every pendulum realigns. */\n loopFrames?: number;\n speed?: number;\n background?: string;\n /** Bobs and guides. */\n color?: string;\n /** The wave line threaded through the bobs. */\n accent?: string;\n /** Draw the faint per-pendulum tracks and centre line. */\n showGuides?: boolean;\n};\n\nconst pendulumWaveDefaults: Required<PendulumWaveProps> = {\n count: 15,\n cycles: 10,\n loopFrames: 450,\n speed: 1,\n background: \"#111111\",\n color: \"#FFFFFF\",\n accent: \"#E5322D\",\n showGuides: true,\n};\n\nconst TAU = Math.PI * 2;\nconst SMEAR_FRAMES = 4;\nconst SMEAR_SAMPLES = 6;\n\ntype Point = { x: number; y: number };\n\nconst fmt = (n: number) => Math.round(n * 10) / 10;\n\n// Catmull-Rom through the bobs so the wave reads as one continuous curve.\nfunction smoothPath(points: Point[]) {\n if (points.length < 2) return \"\";\n let d = `M ${fmt(points[0].x)} ${fmt(points[0].y)}`;\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1] ?? points[i];\n const p1 = points[i];\n const p2 = points[i + 1];\n const p3 = points[i + 2] ?? p2;\n const c1x = p1.x + (p2.x - p0.x) / 6;\n const c1y = p1.y + (p2.y - p0.y) / 6;\n const c2x = p2.x - (p3.x - p1.x) / 6;\n const c2y = p2.y - (p3.y - p1.y) / 6;\n d += ` C ${fmt(c1x)} ${fmt(c1y)} ${fmt(c2x)} ${fmt(c2y)} ${fmt(p2.x)} ${fmt(p2.y)}`;\n }\n return d;\n}\n\nconst circle = (x: number, y: number, r: number) =>\n `M ${fmt(x - r)} ${fmt(y)} a ${fmt(r)} ${fmt(r)} 0 1 0 ${fmt(r * 2)} 0 a ${fmt(r)} ${fmt(r)} 0 1 0 ${fmt(-r * 2)} 0`;\n\nfunction PendulumWaveBase({\n count = pendulumWaveDefaults.count,\n cycles = pendulumWaveDefaults.cycles,\n loopFrames = pendulumWaveDefaults.loopFrames,\n speed = pendulumWaveDefaults.speed,\n background = pendulumWaveDefaults.background,\n color = pendulumWaveDefaults.color,\n accent = pendulumWaveDefaults.accent,\n showGuides = pendulumWaveDefaults.showGuides,\n}: PendulumWaveProps) {\n const frame = useCurrentFrame();\n const { width, height } = useVideoConfig();\n const n = Math.max(2, Math.round(count));\n const loop = Math.max(1, loopFrames);\n const time = frame * speed;\n\n const marginX = width * 0.1;\n const gap = (width - marginX * 2) / (n - 1);\n const amp = height * 0.3;\n const cy = height / 2;\n const r0 = Math.min(gap * 0.3, height * 0.022);\n const unit = Math.min(width, height) / 720;\n\n // Phase of pendulum i: 2π · t · (cycles + i) / T. At t = 0 and t = T all\n // pendulums sit at the top extreme, so the loop closes on a straight line.\n const phaseAt = (i: number, t: number) => (TAU * t * (cycles + i)) / loop;\n\n const bobs = Array.from({ length: n }, (_, i) => {\n const c = Math.cos(phaseAt(i, time));\n // Fake depth: bobs swinging toward the viewer (lower) read slightly bigger.\n return { x: marginX + i * gap, y: cy - amp * c, r: r0 * (1 - 0.22 * c) };\n });\n\n let smear = \"\";\n for (let i = 0; i < n; i++) {\n const x = fmt(bobs[i].x);\n for (let s = 0; s <= SMEAR_SAMPLES; s++) {\n const t = time - (SMEAR_FRAMES * speed * s) / SMEAR_SAMPLES;\n const y = fmt(cy - amp * Math.cos(phaseAt(i, t)));\n smear += `${s === 0 ? \"M\" : \"L\"} ${x} ${y} `;\n }\n }\n\n const tracks = bobs\n .map((b) => `M ${fmt(b.x)} ${fmt(cy - amp)} V ${fmt(cy + amp)}`)\n .join(\" \");\n const ticks = bobs\n .map(\n (b) =>\n circle(b.x, cy - amp, 2.2 * unit) + circle(b.x, cy + amp, 2.2 * unit),\n )\n .join(\" \");\n\n return (\n <AbsoluteFill style={{ backgroundColor: background }}>\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n aria-label=\"Pendulum wave\"\n style={{ display: \"block\" }}\n >\n {showGuides ? (\n <g stroke={color} fill=\"none\">\n <path\n d={`M ${fmt(marginX - gap)} ${cy} H ${fmt(width - marginX + gap)}`}\n strokeOpacity={0.14}\n strokeWidth={unit}\n />\n <path\n d={tracks}\n strokeOpacity={0.08}\n strokeWidth={unit}\n strokeDasharray={`${2 * unit} ${6 * unit}`}\n />\n <path d={ticks} fill={color} fillOpacity={0.25} stroke=\"none\" />\n </g>\n ) : null}\n <path\n d={smoothPath(bobs)}\n fill=\"none\"\n stroke={accent}\n strokeWidth={2.5 * unit}\n strokeLinecap=\"round\"\n strokeOpacity={0.85}\n />\n <path\n d={smear}\n fill=\"none\"\n stroke={color}\n strokeOpacity={0.13}\n strokeWidth={r0 * 0.9}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n <path\n d={bobs.map((b) => circle(b.x, b.y, b.r)).join(\" \")}\n fill={color}\n />\n </svg>\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n count: {\n type: \"number\",\n default: 15,\n min: 2,\n max: 40,\n step: 1,\n description: \"Pendulums\",\n hiddenFromList: false,\n },\n cycles: {\n type: \"number\",\n default: 10,\n min: 1,\n max: 30,\n step: 1,\n description: \"Swings of the slowest\",\n hiddenFromList: false,\n },\n loopFrames: {\n type: \"number\",\n default: 450,\n min: 90,\n max: 900,\n step: 30,\n description: \"Loop frames\",\n hiddenFromList: false,\n },\n showGuides: {\n type: \"boolean\",\n default: true,\n description: \"Guides\",\n },\n background: {\n type: \"color\",\n default: \"#111111\",\n description: \"Background\",\n },\n color: {\n type: \"color\",\n default: \"#FFFFFF\",\n description: \"Bobs\",\n },\n accent: {\n type: \"color\",\n default: \"#E5322D\",\n description: \"Wave line\",\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([\"count\",\"cycles\",\"loopFrames\",\"showGuides\",\"background\",\"color\",\"accent\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n count: 15,\n cycles: 10,\n loopFrames: 450,\n showGuides: true,\n background: \"#111111\",\n color: \"#FFFFFF\",\n accent: \"#E5322D\",\n speed: 1,\n};\n\ntype PendulumWaveElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof PendulumWaveBase>;\n\nconst PendulumWaveInner = forwardRef<\n HTMLDivElement,\n PendulumWaveElementProps & { 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 ?? \"<PendulumWave>\"}\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 <PendulumWaveBase\n {...(componentProps as unknown as ComponentProps<typeof PendulumWaveBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const PendulumWave = Interactive.withSchema({\n Component: PendulumWaveInner,\n componentName: \"<PendulumWave>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 450,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 450
}