{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cell-divide",
  "title": "Cell Divide",
  "description": "A grid of dots doubles by cell division up to a count of 64.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/cell-divide/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Sora\";\nimport { type CSSProperties, type ReactNode, useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sora } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\n\n// gradients.sh \"beam\" palette\nconst BEAM = {\n  bg: \"#02030a\",\n  c: [\"#f4f7ff\", \"#8fb4ff\", \"#3d5bff\", \"#1a1660\"],\n} as const;\n\nexport interface CellDivideProps {\n  generations?: number;\n  label?: string;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\nconst RAYS = 96;\nconst R_RATIO = 0.4;\nconst SQ2 = Math.SQRT2;\nconst START = 14;\nconst MOTION = [17, 15, 14, 13, 12, 12, 12];\nconst PAUSE = 4;\nconst SWITCH_AT = 0.74;\nconst ROLL = 9;\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_DIV = Easing.bezier(0.42, 0, 0.45, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    bg: BEAM.bg,\n    fg: \"#F3F2EF\",\n    muted: \"#8E90A0\",\n    stops: [BEAM.c[0], BEAM.c[1], BEAM.c[2], \"#2a35a8\"],\n    glow: 0.2,\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    muted: \"#6E6C67\",\n    stops: [BEAM.c[1], \"#6f8dff\", BEAM.c[2], BEAM.c[3]],\n    glow: 0,\n    grain: 0.045,\n  },\n} as const;\n\nfunction gridOf(g: number) {\n  return { cols: 2 ** Math.ceil(g / 2), rows: 2 ** Math.floor(g / 2) };\n}\n\nfunction schedule(G: number) {\n  let t = START;\n  const divs: { start: number; dur: number }[] = [];\n  for (let g = 0; g < G; g++) {\n    const dur = MOTION[Math.min(g, MOTION.length - 1)];\n    divs.push({ start: t, dur });\n    t += dur + PAUSE;\n  }\n  return { divs, end: t - PAUSE };\n}\n\nfunction smin(a: number, b: number, k: number) {\n  if (k <= 1e-6) return Math.min(a, b);\n  const h = Math.max(k - Math.abs(a - b), 0) / k;\n  return Math.min(a, b) - (h * h * k) / 4;\n}\n\nfunction lobe(\n  mx: number,\n  my: number,\n  ex: number,\n  ey: number,\n  sep: number,\n  rho: number,\n  k: number,\n) {\n  const half = sep / 2;\n  const fx = -ey;\n  const fy = ex;\n  const sdf = (u: number, v: number) =>\n    smin(Math.hypot(u - half, v) - rho, Math.hypot(u + half, v) - rho, k);\n  const reach = rho + k / 4;\n  const pinched = half >= reach;\n  const neckH = pinched ? 0 : Math.sqrt(reach * reach - half * half);\n  const angles: { a: number; neck: number }[] = [];\n  for (let i = 0; i < RAYS; i++)\n    angles.push({ a: (i / RAYS) * Math.PI * 2, neck: 0 });\n  if (!pinched) {\n    const n1 = Math.atan2(neckH, -half);\n    const n2 = Math.atan2(-neckH, -half) + Math.PI * 2;\n    angles.push({ a: n1, neck: 1 }, { a: n2, neck: -1 });\n    angles.sort((p, q) => p.a - q.a);\n  }\n  const rMax = 2 * rho + k + sep;\n  const step = Math.max(rho / 14, 0.4);\n  const pts: string[] = [];\n  for (const { a, neck } of angles) {\n    let u: number;\n    let v: number;\n    if (neck !== 0) {\n      u = 0;\n      v = neck * neckH;\n    } else {\n      const c = Math.cos(a);\n      const s = Math.sin(a);\n      const rEnd = c < -1e-9 ? Math.min(rMax, half / -c) : rMax;\n      let lo = 0;\n      let hi = -1;\n      for (let r = step; r < rEnd; r += step) {\n        if (sdf(half + r * c, r * s) > 0) {\n          hi = r;\n          break;\n        }\n        lo = r;\n      }\n      if (hi < 0 && sdf(half + rEnd * c, rEnd * s) > 0) hi = rEnd;\n      let r = rEnd;\n      if (hi >= 0) {\n        for (let it = 0; it < 12; it++) {\n          const mid = (lo + hi) / 2;\n          if (sdf(half + mid * c, mid * s) > 0) hi = mid;\n          else lo = mid;\n        }\n        r = (lo + hi) / 2;\n      }\n      u = half + r * c;\n      v = r * s;\n    }\n    const x = mx + ex * u + fx * v;\n    const y = my + ey * u + fy * v;\n    pts.push(`${x.toFixed(2)} ${y.toFixed(2)}`);\n  }\n  return `M${pts.join(\"L\")}Z`;\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={41}\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\nexport function CellDivide({\n  generations = 6,\n  label = \"×2 every week\",\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: CellDivideProps) {\n  const t = useCurrentFrame() * speed;\n  const { width, height } = useVideoConfig();\n  const u = Math.min(width / 1280, height / 720);\n  const p = THEMES[theme];\n  const G = Math.max(2, Math.min(7, Math.round(generations)));\n  const { divs, end } = schedule(G);\n\n  const heroSize = 176 * u;\n  const labelSize = 24 * u;\n  const finalCount = 2 ** G;\n  const heroW = String(finalCount).length * 0.6 * heroSize;\n  const labelW = label.length * 0.56 * labelSize + 24 * u;\n  const textW = Math.max(heroW, labelW);\n  const gap = 72 * u;\n  const f = G % 2 === 0 ? 1 : SQ2;\n  const E = Math.min(\n    height * 0.6,\n    (0.44 * width - (gap + textW) / 2) / (SQ2 - f / 2),\n    (0.88 * width - gap - textW) / f,\n  );\n  const slotRight = width / 2 - (f * E + gap + textW) / 2 + f * E;\n  const cy = height / 2;\n\n  const pitchOf = (g: number) => E / 2 ** (g / 2);\n  const posOf = (g: number, c: number, r: number) => {\n    const { cols, rows } = gridOf(g);\n    const pitch = pitchOf(g);\n    const cx = slotRight - (cols * pitch) / 2;\n    return {\n      x: cx + (c - (cols - 1) / 2) * pitch,\n      y: cy + (r - (rows - 1) / 2) * pitch,\n    };\n  };\n\n  let gen = 0;\n  let active = -1;\n  let s = 0;\n  for (let g = 0; g < divs.length; g++) {\n    const d = divs[g];\n    if (t >= d.start + d.dur) gen = g + 1;\n    else if (t >= d.start) {\n      active = g;\n      s = (t - d.start) / d.dur;\n      break;\n    }\n  }\n\n  const intro = interpolate(t, [0, 16], [0, 1], { ...CLAMP, easing: EASE_OUT });\n  const push = interpolate(t, [0, end + 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const camScale = 0.985 + 0.03 * push;\n\n  const gradId = `cd${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  const colW = f * E;\n  const colCx = slotRight - colW / 2;\n  const gradCx = colCx - colW * (0.34 - 0.1 * push);\n  const gradCy = cy - E * (0.42 - 0.06 * push);\n  const gradR = Math.hypot(colW, E) * 0.98;\n  const cellFill = `url(#${gradId})`;\n\n  const shapes: ReactNode[] = [];\n  if (active >= 0) {\n    const g = active;\n    const { cols, rows } = gridOf(g);\n    const horiz = g % 2 === 0;\n    const pitchP = pitchOf(g);\n    const pitchC = pitchOf(g + 1);\n    const e = interpolate(EASE_DIV(s), [0, 0.3, 0.78, 1], [0, 0.44, 0.86, 1]);\n    const k0 = 0.55 * R_RATIO * pitchP;\n    const k = k0 * (1 - e);\n    const rho0 = R_RATIO * pitchP - k0 / 4;\n    const rho1 = R_RATIO * pitchC;\n    const rho = rho0 + (rho1 - rho0) * Math.min(1, e / 0.7);\n    const sep = pitchC * e;\n    for (let r = 0; r < rows; r++) {\n      for (let c = 0; c < cols; c++) {\n        const P = posOf(g, c, r);\n        const d1 = horiz ? posOf(g + 1, 2 * c, r) : posOf(g + 1, c, 2 * r);\n        const d2 = horiz\n          ? posOf(g + 1, 2 * c + 1, r)\n          : posOf(g + 1, c, 2 * r + 1);\n        const mx = P.x + ((d1.x + d2.x) / 2 - P.x) * e;\n        const my = P.y + ((d1.y + d2.y) / 2 - P.y) * e;\n        const ex = horiz ? 1 : 0;\n        const ey = horiz ? 0 : 1;\n        const d =\n          lobe(mx, my, ex, ey, sep, rho, k) +\n          lobe(mx, my, -ex, -ey, sep, rho, k);\n        shapes.push(<path key={`${c}-${r}`} d={d} fill={cellFill} />);\n      }\n    }\n  } else {\n    const { cols, rows } = gridOf(gen);\n    const rad = R_RATIO * pitchOf(gen);\n    for (let r = 0; r < rows; r++) {\n      for (let c = 0; c < cols; c++) {\n        const P = posOf(gen, c, r);\n        const wave =\n          gen === G\n            ? Math.sin(\n                Math.PI *\n                  interpolate(\n                    t,\n                    [end + 2 + (c + r) * 0.6, end + 11 + (c + r) * 0.6],\n                    [0, 1],\n                    CLAMP,\n                  ),\n              )\n            : 0;\n        const introScale = gen === 0 ? 0.86 + 0.14 * intro : 1;\n        shapes.push(\n          <circle\n            key={`${c}-${r}`}\n            cx={P.x}\n            cy={P.y}\n            r={rad * introScale * (1 + 0.07 * wave)}\n            fill={cellFill}\n          />,\n        );\n      }\n    }\n  }\n\n  const switches = divs.map((d) => d.start + d.dur * SWITCH_AT);\n  let shown = 0;\n  for (let i = 0; i < switches.length; i++) if (t >= switches[i]) shown = i + 1;\n  const rollK =\n    shown > 0\n      ? interpolate(\n          t,\n          [switches[shown - 1], switches[shown - 1] + ROLL],\n          [0, 1],\n          {\n            ...CLAMP,\n            easing: EASE_OUT,\n          },\n        )\n      : 1;\n  const cur = 2 ** shown;\n  const prev = shown > 0 ? 2 ** (shown - 1) : cur;\n  const rolling = rollK < 1;\n\n  const textIn = interpolate(t, [6, 24], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const labelIn = interpolate(t, [12, 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const lineH = heroSize * 0.98;\n  const numStyle: CSSProperties = {\n    fontFamily: sora,\n    fontWeight: 300,\n    fontSize: heroSize,\n    lineHeight: `${lineH}px`,\n    height: lineH,\n    letterSpacing: \"-0.05em\",\n    color: p.fg,\n    fontVariantNumeric: \"tabular-nums\",\n    whiteSpace: \"nowrap\",\n  };\n\n  return (\n    <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(${colW * 0.95}px ${E * 0.95}px at ${colCx}px ${cy}px, color-mix(in oklab, ${BEAM.c[2]} ${p.glow * 100}%, transparent) 0%, transparent 100%)`,\n          opacity: intro,\n        }}\n      />\n      <AbsoluteFill\n        style={{\n          transform: `scale(${camScale})`,\n          transformOrigin: \"50% 50%\",\n        }}\n      >\n        <svg\n          width={width}\n          height={height}\n          style={{ position: \"absolute\", inset: 0, opacity: intro }}\n          aria-hidden\n        >\n          <defs>\n            <radialGradient\n              id={gradId}\n              gradientUnits=\"userSpaceOnUse\"\n              cx={gradCx}\n              cy={gradCy}\n              r={gradR}\n            >\n              <stop offset=\"0\" stopColor={p.stops[0]} />\n              <stop offset=\"0.3\" stopColor={p.stops[1]} />\n              <stop offset=\"0.66\" stopColor={p.stops[2]} />\n              <stop offset=\"1\" stopColor={p.stops[3]} />\n            </radialGradient>\n          </defs>\n          {shapes}\n        </svg>\n\n        <div\n          style={{\n            position: \"absolute\",\n            left: slotRight + gap,\n            top: cy,\n            transform: \"translateY(-50%)\",\n            display: \"flex\",\n            flexDirection: \"column\",\n            alignItems: \"flex-start\",\n            gap: 16 * u,\n          }}\n        >\n          <div\n            style={{\n              position: \"relative\",\n              height: lineH,\n              overflow: \"hidden\",\n              opacity: textIn,\n              transform: `translateY(${(1 - textIn) * 14 * u}px)`,\n            }}\n          >\n            <div\n              style={{\n                ...numStyle,\n                transform: `translateY(${rolling ? (1 - rollK) * lineH : 0}px)`,\n              }}\n            >\n              {cur}\n            </div>\n            {rolling ? (\n              <div\n                style={{\n                  ...numStyle,\n                  position: \"absolute\",\n                  left: 0,\n                  top: 0,\n                  transform: `translateY(${-rollK * lineH}px)`,\n                }}\n              >\n                {prev}\n              </div>\n            ) : null}\n          </div>\n          <div\n            style={{\n              display: \"flex\",\n              alignItems: \"center\",\n              gap: 12 * u,\n              marginLeft: 6 * u,\n              opacity: labelIn,\n              transform: `translateY(${(1 - labelIn) * 8 * u}px)`,\n            }}\n          >\n            <span\n              style={{\n                width: 10 * u,\n                height: 10 * u,\n                borderRadius: \"50%\",\n                background: accent,\n                flexShrink: 0,\n              }}\n            />\n            <span\n              style={{\n                fontFamily: sora,\n                fontWeight: 400,\n                fontSize: labelSize,\n                letterSpacing: \"-0.015em\",\n                color: p.muted,\n                whiteSpace: \"nowrap\",\n              }}\n            >\n              {label}\n            </span>\n          </div>\n        </div>\n      </AbsoluteFill>\n\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse 85% 85% at 50% 50%, transparent 64%, ${p.bg} 100%)`,\n          opacity: 0.5,\n        }}\n      />\n      <Grain opacity={p.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/cell-divide.tsx"
    }
  ],
  "type": "registry:component"
}
