Installation
npx kinetic-ui-cli@latest add boids-canvasUsage
import { BoidsCanvas } from "@/components/creative/boids-canvas";
export default function Page() {
return (
<div className="w-full h-screen relative">
<BoidsCanvas count={200} color="#3b82f6" />
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
<h1 className="text-white text-6xl font-bold">Hero Text</h1>
</div>
</div>
);
}
How it works
This component does not use WebGL or Three.js. Instead, it relies on an incredibly optimized 2D Canvas requestAnimationFrame loop.
The behavior of the "boids" (bird-oid objects) is governed by three simple mathematical rules coined by Craig Reynolds in 1986:
- Separation: Steer to avoid crowding local flockmates.
- Alignment: Steer towards the average heading of local flockmates.
- Cohesion: Steer to move towards the average position (center of mass) of local flockmates.
Additionally, a fourth rule is injected into the velocity vector when the user's cursor comes within a certain radius, forcing the boids to rapidly scatter away from the mouse.
Usage Guide
1. Import the Component
Import the component into your React or Next.js page:
import { BoidsCanvas } from "@/components/creative/boids-canvas";
2. Implementation Example
Render the component and customize its behavior by passing props:
import { BoidsCanvas } from "@/components/creative/boids-canvas";
export default function Example() {
return (
<div className="w-full flex items-center justify-center p-8">
<BoidsCanvas
count{10}
color="example"
/>
</div>
);
}