Skip to content
WANCRAFT

E.48Backgrounds & Effects

Flow Field

Particles drifting along an evolving simplex-noise vector field, leaving soft fading trails.

NewReactCanvasTailwindadvanced

Overview

Flow Field steers hundreds of particles through a slowly evolving 3D simplex-noise vector field and draws each one as a fading polyline trail on a single canvas. Trails are rebuilt from a per-particle history every frame, so the canvas stays transparent on any background with no smearing or ghost pixels. A mouse pointer stirs the field into a gentle vortex or pushes particles away. Adaptive mode scales the particle count with the container area and sheds particles when frames drop; the loop pauses offscreen and in hidden tabs, and reduced motion renders a still frame of streamlines.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/flow-field.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/flow-field.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/flow-field.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { FlowField } from "@/components/ui/flow-field";

export function FlowFieldExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <FlowField />
    </div>
  );
}

03Props

PropTypeDefaultDescription
particleCountnumber1200Particles before adaptive reduction.
speednumber1Drift speed multiplier; 0 freezes the particles.
noiseScalenumber3Field frequency (per 1000px). Higher values give tighter swirls.
trailnumber20Trail length in recorded positions per particle (min 2).
lineWidthnumber1Trail stroke width in px.
colorstring"#FF7448"Main particle colour (any CSS colour).
secondaryColorstring"#B6F3D1"Colour used by every third particle (any CSS colour).
pointer"vortex" | "repel" | "none""vortex"How particles react to a mouse or pen pointer.
adaptivebooleantrueScale the count with container area (30–100% of a 1280×720 reference) and shed 25% when below ~40fps.
childrenReactNode—Optional content layered above the field.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Inline seeded 3D simplex noise — no dependencies
  • 02History-based trails: transparent canvas, no ghosting, instant theme changes
  • 03Alpha-bucketed batched strokes: a handful of draw calls per frame
  • 04Pointer vortex or repel with a smooth falloff
  • 05Adaptive particle count by area and frame rate
  • 06DPR-aware canvas (capped at 2), ResizeObserver, pauses offscreen and in hidden tabs
motion · continuousinput · pointerinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; layered content stays fully interactive.
  • prefers-reduced-motion renders a single still frame of streamlines and disables pointer effects.
  • Only mouse and pen pointers stir the field, so touch scrolling never triggers motion.
  • Very light palette colours are deepened automatically on light themes so trails keep their contrast.

06Limitations

  • Canvas 2D is CPU-bound: beyond ~4,000 particles with long trails consider WebGL.