Skip to documentation content

Reaction Diffusion

Organic patterns that grow and settle from a live reaction-diffusion simulation.

reaction-diffusion-demo

Overview

Reaction Diffusion runs a Gray-Scott simulation on the GPU. Two chemicals spread across a grid at different rates, one feeding on the other, and stable shapes emerge on their own: branching coral, separate spots that split, a winding maze, or a drifting pattern that never settles.

The pattern is drawn in one color with soft, antialiased edges on a transparent background, so it works on light and dark pages. With the default currentColor it follows the text color and theme. Use it behind a section heading, on an empty state, or as a quiet texture on a 404 page.

The simulation starts from scattered drops and grows for a moment before the first frame. Moving the pointer across it seeds new growth along the pointer's path.

Installation

npm install honestui

Usage

import { ReactionDiffusion } from "honestui/shaders"

<div className="relative h-96 text-foreground">
  <ReactionDiffusion className="absolute inset-0" pattern="coral" opacity={0.35} fade="radial" />
  <h2 className="relative">Grown, not drawn.</h2>
</div>

Each pattern grows from fresh drops, so changing pattern starts the simulation again. A new seed gives a different starting layout of the same pattern.

Patterns

PatternWhat grows
coralBranching lines that fill the area and then hold still
spotsRound spots that split and spread until they are evenly spaced
mazeNarrow winding channels, like a fingerprint
driftArcs and blobs that keep moving and never settle

Accessibility

Reaction Diffusion is decorative and its canvas is hidden from assistive technology. Put text and actions in normal HTML. Keep opacity low behind text, or use fade so the pattern stays away from it, and check contrast where the pattern is densest.

When the user prefers reduced motion, or paused is set, the simulation runs ahead to a settled pattern and shows it as a still frame. It also stops while it is offscreen or the tab is hidden. The simulation needs WebGL2 with floating-point render targets; without them, the container shows only its background.

Performance

The simulation runs on a grid coarser than the screen: one cell is scale CSS pixels. A larger scale gives larger shapes and costs less. Changing scale or seed restarts the simulation.

API Reference

PropTypeDefaultDescription
patterncoral|spots|maze|drift"coral"The pattern the simulation grows.
colorstring"currentColor"Pattern color. Any CSS color.
backgroundstring"transparent"Color between the shapes.
opacitynumber0.35Opacity of the pattern, from 0 to 1.
fadenone|radial|edges|top|bottom"none"Fades the pattern out toward the edges.
scalenumber2Size of one simulation cell in CSS pixels.
speednumber1How fast the pattern grows, up to 4. 0 holds it still.
interactivebooleantrueSeeds new growth along the pointer's path.
seednumber1Starting layout. A new value restarts the simulation.
pausedbooleanfalseShows a settled pattern as a still frame.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content drawn above the pattern.