---
title: "Dots engine"
description: "How the engine behind every loader turns a pattern into lit dots, from a JSON scene to a baked track, and the four ways it draws them."
url: "https://dotsengine.dev/docs/engine"
markdown: "https://dotsengine.dev/docs/engine.md"
updated: 2026-12-01
---

# Dots engine

How the engine behind every loader turns a pattern into lit dots, from a JSON scene to a baked track, and the four ways it draws them.

> The other pages of this site, each with its Markdown copy, are listed in [llms.txt](https://dotsengine.dev/llms.txt).

Every loader on this site runs on one engine: the `dot-matrix` item. It is a React component. Install it once. Then each loader is one `<DotMatrix>` with a few props.

```bash
npx shadcn@latest add https://dotsengine.dev/r/dot-matrix.json
```

```tsx
import { DotMatrix } from "@/components/ui/dot-matrix/dot-matrix";

export function Saving() {
  return <DotMatrix pattern="radar" lattice="circle" size={24} aria-label="Saving" />;
}
```

The item installs into one `dot-matrix/` folder in the `ui` folder that `components.json` names: `components/ui/` in Next.js, `src/components/ui/` in Vite and TanStack Start. It needs `@ui-sdk/core` and `@ui-sdk/react`, and the CLI installs them for you.

## What you choose

You decide what the dots draw, where they sit, how they look and move, and what state they show. Each choice has its own page.

| You choose         | Props                               | Read                               |
| ------------------ | ----------------------------------- | ---------------------------------- |
| What the dots draw | `pattern`                           | [Built-in patterns](https://dotsengine.dev/docs/patterns.md) |
| Where the dots sit | `lattice`, `look.dot`, `look.grid`  | [Layouts and dots](https://dotsengine.dev/docs/layouts.md)   |
| The color          | `color`, `look.colors`, `look.glow` | [Colors](https://dotsengine.dev/docs/colors.md)              |
| The movement       | `value`, `look.speed`, `look.morph` | [Motion](https://dotsengine.dev/docs/motion.md)              |
| The state          | `state`, `active`, `enter`          | [Loading states](https://dotsengine.dev/docs/states.md)      |

Every prop, with its type and default, is in the [DotMatrix API](https://dotsengine.dev/docs/api.md).

The same engine draws all of these. Only the props change:

```dot-matrix
[
  { "name": "orbit", "pattern": "orbit", "lattice": "circle" },
  { "name": "radar", "pattern": "radar", "lattice": "circle", "color": "chart-2" },
  { "name": "equalizer", "pattern": "equalizer", "lattice": "rounded", "color": "chart-5" },
  { "name": "check", "pattern": "check", "lattice": "circle", "color": "success" }
]
```

## From a pattern to dots

A pattern is plain JSON. We call it a scene. The engine turns a scene into dots in four steps:

1. **Compile.** Each node of the scene becomes a small function. It gives the light of one dot at one time.
2. **Bake.** The engine samples every dot 30 times a second, for one loop. It keeps the result as bytes, one byte for each dot in each frame. We call this a track.
3. **Draw.** A renderer reads the track and draws the frame for the current time. It never runs the scene again.
4. **Morph.** When the pattern, the lattice or the color changes, each dot moves from the old track to the new one. Nothing cross-fades.

A worker thread does the bake, so your page stays free. The loop starts when the bake is done. All loops follow the page clock, so two loaders with the same pattern move in step.

## Server rendering

The component file starts with `"use client"`, so it works in the Next.js App Router and in TanStack Start.

- **First frame on the server.** The server renders the first frame as plain dots. The loader shows before any script runs.
- **No layout shift.** The root box gets its width and height from `size` and the lattice. Nothing moves when the script takes over.
- **Same frame in both places.** Random parts of a pattern use a fixed hash. The server and the browser compute the same first frame, so hydration matches.
- **Hand over.** In the browser, the renderer mounts a layer over the first frame, then removes the server dots.

Pass only data from a server component: a pattern name, a scene, a lattice, colors. A `renderer` is a set of functions. Set it inside a client component.

## Four ways to draw

A renderer only reads tracks. So you can change the renderer and keep the same pattern.

| Renderer | Item | Use it for |
| --- | --- | --- |
| Canvas (default) | `dot-matrix` | Most loaders. One canvas each, drawn from shared sprites. |
| DOM | `dot-matrix-dom` | Small loaders that must move while the main thread is busy. The compositor runs their Web Animations. |
| SVG | `dot-matrix-svg` | One SVG per loader, with gradient halos and no filters. It installs `dot-matrix-dom` too. |
| WebGL | `dot-matrix-webgl` | Large fields and pages with many loaders. All of them share one WebGL2 context. |

```bash
npx shadcn@latest add https://dotsengine.dev/r/dot-matrix-webgl.json
```

```tsx
import { webglRenderer } from "@/components/ui/dot-matrix-webgl/dot-matrix-webgl";
import { DotMatrix } from "@/components/ui/dot-matrix/dot-matrix";

<DotMatrix pattern="plasma" size={240} renderer={webglRenderer} />;
```

The other renderers are `domRenderer` from `dot-matrix-dom/dot-matrix-dom`, `svgRenderer` from `dot-matrix-svg/dot-matrix-svg`, and `canvasRenderer` from `dot-matrix/dot-matrix-canvas`.

## Screen readers

The loader is an `<output>`. Its name says what the pattern means:

| Pattern                                       | Name                   |
| --------------------------------------------- | ---------------------- |
| A loop                                        | "Loading"              |
| `check`, or a scene with `outcome: "success"` | "Done"                 |
| `cross`, or a scene with `outcome: "failure"` | "Something went wrong" |

- Pass `aria-label` to say what loads, such as "Uploading photo".
- Pass `aria-hidden` when text next to it already says it.
- Pass `messages` to change the three names, for example in another language.
- When `pattern` changes to one with an outcome, a screen reader hears the outcome once.

The loop runs only while the loader is on screen and the tab is visible.
