# ASCII Matrix

> Digital rain with flickering katakana and fading trails.

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

## Installation

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

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

## Usage

```tsx
import { AsciiMatrix } from "@/components/ascii/ascii-matrix"

<div className="h-96">
  <AsciiMatrix className="text-primary" />
</div>
```

## Examples

### Binary rain

Any string works as `glyphs`. Pair it with a palette for a green phosphor look that ignores the theme colour.

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

<AsciiMatrix glyphs="01" color={palettes.matrix} density={0.5} />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glyphs` | `string` | `katakana + digits` | Characters the rain is made of. |
| `speed` | `number` | `14` | Rows per second for an average drop. |
| `density` | `number` | `0.7` | 0 to 1. Lower leaves longer gaps. |

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.** Decorative, so it renders `aria-hidden`. Put real content on top of it.
- **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()`.
