Boids
Craig Reynolds’ flocking — separation, alignment, cohesion — on a spatial hash. The flock scatters from your pointer (blushing as it flees) or follows it like a shadow.
canvassimulationpointerclick5 files · 472 locdeps: clsx, tailwind-merge
Installation
With the shadcn CLI, pointing at this platform’s registry:
npx shadcn@latest add https://opusui.131199999.xyz/r/boids.jsonOr offline, straight from your opus55 checkout (copies every file it needs):
node ../tailwind_component/opus55/scripts/add.mjs boidsUsage
import { Boids } from "@/components/opus/backgrounds/boids";
<Boids count={160} className="absolute inset-0" />API
| Prop | Type | Default | Description |
|---|---|---|---|
| color / alarm | string | — | Calm and fleeing colours. |
| count | number | 160 | Number of boids (max 400). |
| speed / size | number | 110 / 6 | Cruise speed (px/s) and body size (px). |
| mode | "flee" | "follow" | "flee" | Pointer behaviour. |
| interactive | boolean | true | React to the pointer (tracked on window). |
| className | string | — | Wrapper classes — `absolute inset-0` to fill a relative parent. |
| children | ReactNode | — | Optional content rendered above the canvas. |
Notes
- Canvas 2D with a device-pixel-ratio aware backing store (capped at 2×).
- The animation loop stops off-screen and in hidden tabs; resize re-seeds the scene.
prefers-reduced-motion: reducedraws a single static frame.