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
lab/flow-fieldInstallation
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-fieldOr by URL: https://asafefe.dev/r/lab-flow-field.json
Brings along
- utils
- @soultel/lab-canvas
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| background | string | "var(--background)" | Solid color trails fade into. Match what is behind it. |
| color | string | "var(--foreground)" | Trail color. |
| accentColor | string | "var(--primary)" | Color for the accent share of particles. |
| accentRatio | number | 0.18 | Share of accent particles, 0 to 1. |
| fade | number | 0.06 | Trail fade per frame. Lower means longer trails. |
| speed | number | 1.2 | Step length per frame in px. |
| maxParticles | number | 1100 | Upper bound on particles. |
| interactive / reseedOnClick | boolean | true | Pointer swirl and click to reseed. |
