# ASCII Donut

> The classic donut.c torus, lit and z-buffered.

Category: Backgrounds. Docs: https://asciicn.sumak.dev/docs/ascii-donut

## Installation

```bash
npx shadcn@latest add @asciicn/ascii-donut
```

Needs the `@asciicn` registry in components.json: `"registries": { "@asciicn": "https://asciicn.sumak.dev/r/{name}.json" }`.

## Usage

```tsx
import { AsciiDonut } from "@/components/ascii/ascii-donut"

<AsciiDonut className="h-80 text-primary" />
```

## Examples

### Thermal palette

`color` takes gradient stops from faint to full ink, so the lit side glows hot.

```tsx
import { palettes } from "@/lib/ascii"

<AsciiDonut color={palettes.thermal} className="h-64" />
```

### Braille

Braille packs 2×4 dots into every cell, which gives four times the resolution at the same font size.

```tsx
<AsciiDonut charset="braille" fontSize={10} className="h-64 text-primary" />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `speed` | `number` | `1` | Rotation speed multiplier. |
| `thickness` | `number` | `0.5` | Tube radius relative to the ring. |
| `charset` | `string` | `"donut"` | The original .,-~:;=!*#$@ ramp. |

Also accepts every `AsciiCanvas` prop:

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `charset` | `CharsetName | string` | `"standard"` | Named ramp or your own string, empty to dense. "braille" packs 2×4 dots per cell, "quadrants" 2×2 blocks. |
| `fontSize` | `number` | `12` | Cell size in CSS pixels. Smaller means more detail. |
| `dither` | `"none" | "bayer" | "floyd"` | `"none"` | Quantisation. Floyd–Steinberg for photos, Bayer for a retro look. |
| `color` | `"ink" | "source" | string[]` | `"ink"` | Ink uses the CSS colour (theme with text-*). Source keeps pixel colours. An array maps tone onto gradient stops, e.g. palettes.thermal. |
| `edges` | `number` | `0` | Outline contours with | / - \ where the tone gradient beats this strength. Try 0.3. Ramps only. |
| `opacity` | `boolean` | `false` | Fade each glyph by its tone. |
| `brightness` | `number` | `0` | Added after contrast, -1 to 1. |
| `contrast` | `number` | `1` | Multiplier around mid grey. |
| `gamma` | `number` | `1` | Tone curve exponent. |
| `invert` | `boolean` | `false` | Swap ink and blank. |
| `animate` | `boolean` | `auto` | On for fields, frames and video. Off under reduced motion, except video. |
| `fps` | `number` | `30` | Frame cap. |
| `ref` | `Ref<AsciiHandle>` |  | Exposes text(), svg(), png() and the canvas. |

## Notes

- **Accessibility.** Labelled "Spinning ASCII donut". Pass `aria-label` to describe it in your own words, or `aria-hidden` when it is decoration.
- **Motion.** Animation pauses offscreen and in hidden tabs. Under `prefers-reduced-motion` it freezes on the current frame.
- **Theming.** Glyphs take the CSS `color`, so `text-primary` or `text-foreground/40` themes them. Theme changes repaint at once.
- **Performance.** Glyphs are stamped from a pre-rendered atlas onto one canvas, capped at 30 fps. Export with `ref.current.text()`, `svg()` or `png()`.
