Fluid
Stir colored dye through a real-time fluid simulation with the pointer, or let it drift on its own.
Overview
Fluid runs a stable-fluids simulation on the GPU. Each frame it adds splats of dye and force where the pointer moved, keeps small eddies alive with vorticity, solves for pressure so the flow stays incompressible, and carries both the velocity and the dye along the flow. The result reacts to every pointer movement and settles back to calm when left alone.
Use it for an expressive hero, an empty state, or a playful moment where interaction is the point. Its cost is higher than a static gradient, so measure on representative devices and lower simResolution, dyeResolution, or pressureIterations if frames drop.
Installation
Usage
import { Fluid } from "honestui/shaders"
<div className="relative h-96 overflow-hidden rounded-xl bg-neutral-950">
<Fluid className="absolute inset-0" colors={["#4f8bff", "#ff5fb4"]} />
<div className="relative">{/* content */}</div>
</div>By default the simulation listens to pointer movement over its own container. When content is layered above the simulation, set listenOnWindow so pointer movement over that content still stirs the fluid beneath it. Only movement within the container's bounds splats. Leave colors empty for a slowly turning rainbow, and set transparent to draw dye over whatever is behind the canvas.
Accessibility
Fluid is decorative and hidden from assistive technology. Nothing it shows should carry meaning, and content placed over it needs its own background or enough contrast against every color the dye can reach.
The simulation pauses while it is offscreen or the tab is hidden. When the user prefers reduced motion, or paused is set, it renders a still image and ignores the pointer. Without WebGL2 or float render targets it shows a static gradient in the first two colors.