asafefe.dev
Lab

Lab/10

Flow Field

Each particle reads an angle from a shifting sine field and steps along it. The canvas fades a little each frame, so paths turn into trails.

  • Canvas
  • Generative
Move to stir, click to reseed

Installation

Add Flow Field to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-flow-field

Or by URL: https://asafefe.dev/r/lab-flow-field.json

Brings along

  • utils
  • @soultel/lab-canvas

Usage

example.tsx10 lines
import { FlowField } from "@/components/lab/flow-field"

export function Hero() {
  return (
    <section className="relative h-[420px] bg-background">
      <FlowField className="absolute inset-0" />
      <h1 className="relative">Hello</h1>
    </section>
  )
}

Props

PropTypeDefaultDescription
backgroundstring"var(--background)"Solid color trails fade into. Match what is behind it.
colorstring"var(--foreground)"Trail color.
accentColorstring"var(--primary)"Color for the accent share of particles.
accentRationumber0.18Share of accent particles, 0 to 1.
fadenumber0.06Trail fade per frame. Lower means longer trails.
speednumber1.2Step length per frame in px.
maxParticlesnumber1100Upper bound on particles.
interactive / reseedOnClickbooleantruePointer swirl and click to reseed.