Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

10.5 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [
      {
        "name": "@remotion/paths",
        "version": null
      }
    ],
    "dimensions": null,
    "displayName": "Neon Sign",
    "initialProps": null,
    "slug": "neon-sign",
    "sourceCode": "import { getBoundingBox, getSubpaths } from \"@remotion/paths\";\nimport { forwardRef, useId, useImperativeHandle, useMemo, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ntype NeonSignProps = {\n  /** SVG path data for the tube. Each subpath (M command) flickers on its own. */\n  path?: string;\n  /** viewBox for the path. Defaults to the path's bounding box. */\n  viewBox?: string;\n  /** Tube color when lit. */\n  color?: string;\n  /** Color of the halo and the glow on the wall. */\n  glowColor?: string;\n  /** Unlit glass tube. */\n  tubeColor?: string;\n  /** Color of the hot core inside the tube. */\n  coreColor?: string;\n  backgroundColor?: string;\n  /** Tube thickness in path units. */\n  strokeWidth?: number;\n  /** Share of the frame width the sign spans. */\n  fit?: number;\n  seed?: number;\n  speed?: number;\n};\n\n// Handwritten \"hello\" with an underline swash, one subpath per tube.\nconst HELLO = [\n  \"M 30 132 C 52 112 74 70 70 46 C 67 28 50 30 47 52 C 44 76 42 112 40 140 C 46 116 58 100 72 100 C 86 100 84 122 86 134 C 88 144 100 144 110 132\",\n  \"M 110 132 C 124 124 142 110 136 98 C 130 88 112 96 112 116 C 112 138 134 146 156 130\",\n  \"M 156 130 C 176 110 196 66 190 46 C 186 32 170 36 168 60 C 166 90 168 126 172 136 C 176 146 188 142 196 132\",\n  \"M 196 132 C 216 110 232 66 226 46 C 222 32 206 36 204 60 C 202 90 204 126 208 136 C 212 146 224 142 232 132\",\n  \"M 232 132 C 238 116 248 100 262 100 C 278 100 280 124 268 136 C 256 146 242 136 248 118 C 252 106 268 104 290 104\",\n  \"M 52 170 C 120 160 210 162 296 152\",\n].join(\" \");\n\nconst neonSignDefaults = {\n  path: HELLO,\n  color: \"#E5322D\",\n  glowColor: \"#E5322D\",\n  tubeColor: \"#2A2A2A\",\n  coreColor: \"#FFFFFF\",\n  backgroundColor: \"#111111\",\n  strokeWidth: 6,\n  fit: 0.62,\n  seed: 7,\n  speed: 1,\n};\n\nconst FIRST = 3;\nconst STEP = 3.4;\nconst STUTTER = 7;\n// Whole sign drops out once after everything is lit, then holds.\nconst BUZZ: [number, number][] = [\n  [29, 0.1],\n  [30, 0],\n  [31, 0.55],\n  [32, 0.2],\n];\nconst clamp = {\n  extrapolateLeft: \"clamp\" as const,\n  extrapolateRight: \"clamp\" as const,\n};\n\nfunction segmentLevel(t: number, i: number, seed: number) {\n  const onset = FIRST + i * STEP + random(`neon-sign-${seed}-${i}`) * 2;\n  if (t < onset) return 0;\n  if (t < onset + STUTTER) {\n    const tick = Math.floor(t);\n    const v = random(`neon-sign-${seed}-${i}-${tick}`);\n    const ramp = (t - onset) / STUTTER;\n    return v < 0.5 - ramp * 0.3 ? 0.04 : 0.55 + 0.45 * v;\n  }\n  return 1;\n}\n\nfunction NeonSignBase(props: NeonSignProps) {\n  const {\n    path,\n    viewBox,\n    color,\n    glowColor,\n    tubeColor,\n    coreColor,\n    backgroundColor,\n    strokeWidth,\n    fit,\n    seed,\n    speed,\n  } = { ...neonSignDefaults, ...props };\n  const uid = `neon-sign-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  const frame = useCurrentFrame();\n  const { width, height } = useVideoConfig();\n  const t = frame * Math.max(0, speed);\n\n  const segments = useMemo(() => getSubpaths(path), [path]);\n  const box = useMemo(() => {\n    if (viewBox) {\n      const [x, y, w, h] = viewBox.split(/[\\s,]+/).map(Number);\n      return { x, y, w, h };\n    }\n    const b = getBoundingBox(path);\n    const pad = strokeWidth * 6;\n    return {\n      x: b.x1 - pad,\n      y: b.y1 - pad,\n      w: b.width + pad * 2,\n      h: b.height + pad * 2,\n    };\n  }, [path, viewBox, strokeWidth]);\n\n  const tick = Math.floor(t);\n  const buzz = BUZZ.find(([f]) => f === tick)?.[1] ?? 1;\n  const levels = segments.map((_, i) => segmentLevel(t, i, seed) * buzz);\n  const average =\n    levels.reduce((a, b) => a + b, 0) / Math.max(1, levels.length);\n\n  const scale = Math.min((width * fit) / box.w, (height * 0.7) / box.h);\n  const drawW = box.w * scale;\n  const drawH = box.h * scale;\n  const settle = interpolate(t, [32, 40], [0.85, 1], clamp);\n\n  return (\n    <AbsoluteFill style={{ backgroundColor }}>\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse ${drawW * 0.75}px ${drawH * 0.85}px at 50% 50%, ${glowColor} 0%, transparent 100%)`,\n          opacity: 0.28 * average * settle,\n        }}\n      />\n      <AbsoluteFill style={{ alignItems: \"center\", justifyContent: \"center\" }}>\n        <svg\n          width={drawW}\n          height={drawH}\n          viewBox={`${box.x} ${box.y} ${box.w} ${box.h}`}\n          style={{ overflow: \"visible\" }}\n        >\n          <defs>\n            <filter\n              id={`${uid}-wide`}\n              filterUnits=\"userSpaceOnUse\"\n              x={box.x - box.w}\n              y={box.y - box.h}\n              width={box.w * 3}\n              height={box.h * 3}\n            >\n              <feGaussianBlur stdDeviation={strokeWidth * 2.2} />\n            </filter>\n            <filter\n              id={`${uid}-near`}\n              filterUnits=\"userSpaceOnUse\"\n              x={box.x - box.w}\n              y={box.y - box.h}\n              width={box.w * 3}\n              height={box.h * 3}\n            >\n              <feGaussianBlur stdDeviation={strokeWidth * 0.6} />\n            </filter>\n          </defs>\n          <g fill=\"none\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n            {segments.map((d, i) => (\n              <path\n                key={`tube-${i}`}\n                d={d}\n                stroke={tubeColor}\n                strokeWidth={strokeWidth}\n              />\n            ))}\n            {segments.map((d, i) => {\n              const level = levels[i];\n              if (level <= 0) return null;\n              return (\n                <g key={`lit-${i}`}>\n                  <path\n                    d={d}\n                    stroke={glowColor}\n                    strokeWidth={strokeWidth * 3}\n                    opacity={0.7 * level}\n                    filter={`url(#${uid}-wide)`}\n                  />\n                  <path\n                    d={d}\n                    stroke={color}\n                    strokeWidth={strokeWidth * 1.6}\n                    opacity={0.9 * level}\n                    filter={`url(#${uid}-near)`}\n                  />\n                  <path\n                    d={d}\n                    stroke={color}\n                    strokeWidth={strokeWidth}\n                    opacity={level}\n                  />\n                  <path\n                    d={d}\n                    stroke={coreColor}\n                    strokeWidth={strokeWidth * 0.36}\n                    opacity={0.9 * level}\n                  />\n                </g>\n              );\n            })}\n          </g>\n        </svg>\n      </AbsoluteFill>\n    </AbsoluteFill>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  strokeWidth: {\n    type: \"number\",\n    default: 6,\n    min: 2,\n    max: 14,\n    step: 1,\n    description: \"Tube width\",\n    hiddenFromList: false,\n  },\n  fit: {\n    type: \"number\",\n    default: 0.62,\n    min: 0.3,\n    max: 0.9,\n    step: 0.01,\n    description: \"Fit\",\n    hiddenFromList: false,\n  },\n  seed: {\n    type: \"number\",\n    default: 7,\n    min: 1,\n    max: 99,\n    step: 1,\n    description: \"Seed\",\n    hiddenFromList: false,\n  },\n  color: {\n    type: \"color\",\n    default: \"#E5322D\",\n    description: \"Tube\",\n  },\n  glowColor: {\n    type: \"color\",\n    default: \"#E5322D\",\n    description: \"Glow\",\n  },\n  tubeColor: {\n    type: \"color\",\n    default: \"#2A2A2A\",\n    description: \"Unlit tube\",\n  },\n  coreColor: {\n    type: \"color\",\n    default: \"#FFFFFF\",\n    description: \"Core\",\n  },\n  backgroundColor: {\n    type: \"color\",\n    default: \"#111111\",\n    description: \"Background\",\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([\"strokeWidth\",\"fit\",\"seed\",\"color\",\"glowColor\",\"tubeColor\",\"coreColor\",\"backgroundColor\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  strokeWidth: 6,\n  fit: 0.62,\n  seed: 7,\n  color: \"#E5322D\",\n  glowColor: \"#E5322D\",\n  tubeColor: \"#2A2A2A\",\n  coreColor: \"#FFFFFF\",\n  backgroundColor: \"#111111\",\n  speed: 1,\n};\n\ntype NeonSignElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof NeonSignBase>;\n\nconst NeonSignInner = forwardRef<\n  HTMLDivElement,\n  NeonSignElementProps & { 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 ?? \"<NeonSign>\"}\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        <NeonSignBase\n          {...(componentProps as unknown as ComponentProps<typeof NeonSignBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const NeonSign = Interactive.withSchema({\n  Component: NeonSignInner,\n  componentName: \"<NeonSign>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 40,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 40
}