Backgrounds

Dither

A live field crushed to one bit through an ordered threshold matrix. The only background here that looks better the cheaper it gets, and the only one that runs the same on a decade-old laptop as on a workstation.

Install

bun add ogl

Then copy 2 files into your project:

  • components/registry/dither/dither.tsx
  • hooks/use-animation-loop.ts

Props

PropTypeDefaultDescription
pattern"bayer2" | "bayer4" | "bayer8" | "halftone" | "noise""bayer8"Which threshold matrix decides each cell. Bayer is the ordered one — a fixed lattice, so the texture is stable and never crawls between frames. Halftone rotates the grid forty-five degrees and clusters instead of scattering, which is what a printing press does. Noise drops the lattice entirely and pays for it with a pattern that shimmers the moment anything moves.
levelsnumber2Tones per channel after quantisation. Two is the honest one-bit case. Above four this stops being dithering and starts being a slightly cheap gradient — worth dragging once to see exactly where the effect stops earning its name.
pixelSizenumber3Size of one dither cell, held in CSS pixels rather than device pixels. Held in device pixels the grid would halve on a retina screen and the effect would vanish on exactly the displays people judge it on.
field"plasma" | "ridges" | "tunnel" | "drift""plasma"What is being quantised underneath. The dither is indifferent to it — that is the point of a threshold matrix — but the four differ sharply in how much smooth gradient they hand it, and a pattern only shows its character on a gradient.
fieldSpeednumber0.3Rate the field evolves. At zero it parks, which is the clearest way to see the threshold matrix itself rather than the image passing through it.
fieldScalenumber2.4Size of the field's features relative to the container. Small enough and the whole panel is one tone with nothing for the dither to resolve; large enough and every cell disagrees with its neighbour and the pattern turns to static.
frameHoldnumber0How many frames the field is held before it advances. Zero runs at display rate; three gives the deliberate stutter of a machine that could not keep up. The frame is still drawn either way and the held time is spent in one go when the hold expires — so this is a look, not a saving, and not a speed control in disguise.
contrastnumber1Contrast applied around mid-grey before quantisation. This is the real control over how much of the field survives: at two levels there is exactly one threshold, so pushing contrast up does not brighten the image, it decides where the edge between black and white falls.
inkColorstring (hex)"#e8e4d8"The colour a lit cell takes. Warm off-white rather than pure white on purpose — a true #ffffff against near-black is the one pairing that makes the grid buzz.
paperColorstring (hex)"#0b0b0d"The colour an unlit cell takes.

What It Demonstrates

Loop
An animation that repeats, a set number of times or infinitely.
Stepped animation
An animation that is divided into discrete steps, like a countdown timer.
Idle animation
Subtle motion that plays while an element is just sitting there, waiting to be interacted with.
Compositing
Letting the GPU move or fade an element on its own layer without redoing layout or paint.
Hardware acceleration
Animating transform and opacity lets the GPU keep motion smooth.

Related Components

Appears In