# Flip dot display

An electromechanical flip dot sign for status words, streamed tokens and level columns. Discs turn on their axle, only where the picture changes, with a ragged mechanical ripple.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Flip dot display. An agent's run board on a 56 by 7 flip dot sign. Each step flips in disc by disc with a ragged mechanical ripple; long steps scroll through and hold at both ends. Preview: https://chatcn.dev/preview/flip-dot-display-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/flip-dot-display
```

## Usage

```tsx
import { FlipDotDisplay } from "@/components/ui/chatcn/pro/flip-dot-display"

<FlipDotDisplay text={run.status} cols={56} onFlip={(count) => clicks.play(count)} />
```

Give a fixed `cols` to a value that changes, so the board keeps its width. Text is set in the kit's 5 by 7 dot font, uppercased, with one blank column between characters; narrow glyphs and spaces take their own width so words read evenly, and digits stay tabular. A change sends only the discs that differ, each after its own delay of 0 to 220 ms, so the board settles in a ragged ripple. `sweep="column"` turns that into a wave from the start edge.

When `text` grows by appending, as a streamed reply does, only the new characters' discs turn. Once it no longer fits, the board starts a fresh line at the word being written, so the end is always in view and the sign re-sets once per line instead of once per token. Streamed discs start within 90 ms of each other, so a line stays readable while tokens keep coming. Text that is replaced with something too wide scrolls through one column every 80 ms, holds at the end, and returns to the start; `overflow="clip"` cuts it instead.

Pass `columns`, one value from 0 to 1 per column, for bars from the bottom, or a getter for a live level that runs at the frame rate without re-rendering. Pass `frame`, a row major `Uint8Array` of 0 and 1, to draw anything else.

## Examples

### Streaming, level columns, sweep, scroll, pitch and reduced motion

Example: Flip dot display states. A streamed reply, level columns from a simulated voice, the column sweep, scroll, two pitches and reduced motion. Preview: https://chatcn.dev/preview/flip-dot-display-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `text` | `string` | Uppercased, in the 5 by 7 dot font |
| `frame` | `Uint8Array` | Rows of 0 and 1, row major. Wins over `text` |
| `columns` | `number[] | () => Float32Array` | Bars from the bottom, `round(value * rows)` discs each. Wins over both |
| `rows` | `number` | Default 7 |
| `cols` | `number` | Default: fits the text, at least 28 |
| `pitch` | `number` | Disc pitch in CSS px. Default 10. Shrinks to fit a narrow container, in whole device px |
| `overflow` | `"scroll" | "clip"` | For text wider than the board. Default `scroll` |
| `sweep` | `"random" | "column"` | Ragged start, or a wave from the start edge |
| `onFlip` | `(count: number) => void` | Once per frame change, with the number of discs that turned. The board makes no sound |
| `label` | `string` | Accessible name. Defaults to the text |
| `face` | `string` | Light face color. Default the lighter of the text and page tokens |
| `reducedMotion` | `boolean` | Force it on or off. Defaults to the user's setting |
| `paused`, `defaultPaused`, `onPausedChange` | `boolean` | Controlled or uncontrolled pause of the scroll and of a level getter |
| `pauseControl` | `boolean` | Show the pause button while something loops. Default true |

## Keyboard

| Key | Action |
| --- | --- |
| `Tab`, `Enter` | Focus and toggle the pause button, when it shows |

## Accessibility

- The board is one `role="img"` named by its text, updated at most once a second, so a stream is not read token by token. Pass `label` for columns and frames.
- The canvas is `aria-hidden`. The board always reads left to right, like a real sign, also inside right to left pages.
- Under `forced-colors: active` the discs hide and the text shows plain inside an outline that keeps the board's place.
- The light face and the board come from the text and page tokens, so the sign holds its contrast in every theme.

## Motion

- A disc turns about its diagonal axle: it narrows to its edge, shows the other face and eases onto its stop. 90 ms of swing, then 60 ms of settle, with nothing passing the stop. Each face darkens as it turns away from the light at the upper left.
- Discs snap to whole device pixels. The three resting looks are drawn once; each frame repaints only the discs that are turning, so a board of thousands of discs costs nothing at rest.
- Scroll steps and level columns turn in 75 ms with nearly no stagger, so moving text stays legible.
- The loop runs at 60 fps only while discs turn. Through a scroll's hold it sleeps until the next step, and it stops offscreen, in hidden tabs and when paused.
- Under reduced motion discs change face at once, with no turn and no stagger, and wide text rests at its start.

Source: https://chatcn.dev/docs/components/flip-dot-display