{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ascii-donut",
  "title": "ASCII Donut",
  "description": "The spinning torus — 3D points z-buffered per character cell, shaded by luminance ramp.",
  "dependencies": [],
  "registryDependencies": [
    "@atroui/utils",
    "@atroui/ascii-rig"
  ],
  "files": [
    {
      "path": "registry/default/ui/ascii-donut.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport {\n  ASCII_RAMPS,\n  readAsciiColor,\n  resolveAsciiRamp,\n  setupAsciiCanvas,\n  useAsciiTick,\n} from \"@/lib/ascii-rig\"\n\nexport type AsciiDonutProps = {\n  /** Columns (character cells). Rows derive from the 1:2 cell ratio. */\n  cols?: number\n  /** Spin multiplier. 0 still renders one lit frame. */\n  speed?: number\n  /** Luminance ramp, dim → bright. A literal string or a rig ramp name. */\n  chars?: string\n  /** Accessible description of the decorative scene. */\n  label?: string\n  className?: string\n}\n\nconst DEFAULT_RAMP = ASCII_RAMPS.classic\n\nfunction clampInt(v: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, Math.round(v)))\n}\n\n/**\n * ASCII Donut — the a1k0n torus: points plotted on a rotating torus,\n * depth-buffered per cell, shaded by surface-normal · light through a\n * luminance ramp (.,-~:;=!*#$@). Pure canvas, monospace cells, DPR-sharp.\n */\nexport function AsciiDonut({\n  cols: colsProp = 64,\n  speed = 1,\n  chars,\n  label = \"Rotating ASCII torus\",\n  className,\n}: AsciiDonutProps) {\n  const cols = clampInt(colsProp, 24, 110)\n  const rows = Math.round(cols * 0.32)\n  const hostRef = React.useRef<HTMLDivElement>(null)\n  const canvasRef = React.useRef<HTMLCanvasElement>(null)\n\n  const draw = React.useCallback(\n    (t: number) => {\n      const canvas = canvasRef.current\n      if (!canvas) return\n      const setup = setupAsciiCanvas(canvas, cols, rows, 10)\n      if (!setup) return\n      const { ctx } = setup\n      const ramp = resolveAsciiRamp(chars ?? DEFAULT_RAMP)\n      ctx.fillStyle = readAsciiColor(hostRef.current)\n      ctx.clearRect(0, 0, setup.w, setup.h)\n\n      const cells = cols * rows\n      const zbuffer = new Float32Array(cells)\n      const lum = new Int8Array(cells)\n      lum.fill(-1)\n\n      // Base tilt so even the static reduced-motion frame reads as a donut.\n      const A = 0.6 + speed * t * 0.8\n      const B = 0.25 + speed * t * 0.4\n      const cosA = Math.cos(A)\n      const sinA = Math.sin(A)\n      const cosB = Math.cos(B)\n      const sinB = Math.sin(B)\n\n      const K1x = (cols * 5 * 3) / 8 // screen_width*K2*3 / (8*(R1+R2)), K2=5\n      const K1y = rows * 0.62\n\n      for (let theta = 0; theta < 6.283; theta += 0.07) {\n        const costheta = Math.cos(theta)\n        const sintheta = Math.sin(theta)\n        for (let phi = 0; phi < 6.283; phi += 0.02) {\n          const cosphi = Math.cos(phi)\n          const sinphi = Math.sin(phi)\n          const circlex = 2 + costheta // R2 + R1*cosθ, R1=R2/2\n          const circley = 0.5 * sintheta\n\n          const x =\n            circlex * (cosB * cosphi + sinA * sinB * sinphi) -\n            circley * cosA * sinB\n          const y =\n            circlex * (sinB * cosphi - sinA * cosB * sinphi) +\n            circley * cosA * cosB\n          const z = 5 + cosA * circlex * sinphi + circley * sinA\n          const ooz = 1 / z\n          const xp = Math.round(cols / 2 + K1x * ooz * x)\n          const yp = Math.round(rows / 2 - K1y * ooz * y)\n          if (xp < 0 || xp >= cols || yp < 0 || yp >= rows) continue\n\n          const L =\n            cosphi * costheta * sinB -\n            cosA * costheta * sinphi -\n            sinA * sintheta +\n            cosB * (cosA * sintheta - costheta * sinA * sinphi)\n          if (L <= 0) continue\n\n          const idx = yp * cols + xp\n          const zb = zbuffer[idx] ?? -Infinity\n          if (ooz > zb) {\n            zbuffer[idx] = ooz\n            lum[idx] = Math.min(11, Math.floor(L * 8))\n          }\n        }\n      }\n\n      for (let r = 0; r < rows; r++) {\n        let line = \"\"\n        for (let c = 0; c < cols; c++) {\n          const n = lum[r * cols + c] ?? -1\n          line += n < 0 ? \" \" : (ramp[Math.min(n, ramp.length - 1)] ?? \" \")\n        }\n        ctx.fillText(line, 0, r * setup.cellH)\n      }\n    },\n    [cols, rows, speed, chars]\n  )\n\n  useAsciiTick(hostRef, draw, { fps: 16 })\n\n  return (\n    <div\n      ref={hostRef}\n      role=\"img\"\n      aria-label={label}\n      className={cn(\"flex justify-center overflow-hidden\", className)}\n    >\n      <canvas ref={canvasRef} className=\"max-w-full\" aria-hidden=\"true\" />\n    </div>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/ui/ascii-donut.tsx"
    }
  ],
  "type": "registry:ui"
}