Fluid Dynamics
Interactive, generative canvas gradients that react to your cursor position in real-time.
Installation
npx kinetic-ui-cli@latest add fluid-canvasUsage
import { FluidCanvas } from "@/components/creative/fluid-canvas";
export default function Page() {
return (
<div className="w-full h-screen relative">
<FluidCanvas colors={["#4f46e5", "#ec4899", "#06b6d4"]} />
{/* Your content here */}
<div className="absolute inset-0 z-10 flex items-center justify-center">
<h1 className="text-white text-5xl mix-blend-overlay">Hello World</h1>
</div>
</div>
);
}
How it works
Instead of loading massive WebGL fluid simulation libraries, this component generates a convincing "liquid" aesthetic using high-performance 2D Canvas tricks.
- Overlapping Orbs: It renders massive radial gradients (orbs) that slowly orbit around the center of the screen using
Math.sin()andMath.cos()tied to a continuousrequestAnimationFrametimer. - Global Composite Operation: By setting the canvas
globalCompositeOperationto"screen", the overlapping colors blend together like light, creating bright, vibrant intersections. - Mouse Attraction: We calculate the distance vector between the user's cursor and the center of the orbs. If the cursor is close, we inject a slight "pull" force, dragging the gradient centers toward the mouse.
- CSS Blur: The
<canvas>DOM element itself is heavily blurred (blur-[60px]) and scaled up (scale-110) using Tailwind CSS. This instantly smooths out the hard edges of the gradients, creating the thick, liquid aesthetic.
Usage Guide
1. Import the Component
Import the component into your React or Next.js page:
import { FluidCanvas } from "@/components/creative/fluid-canvas";
2. Implementation Example
Render the component and customize its behavior by passing props:
import { FluidCanvas } from "@/components/creative/fluid-canvas";
export default function Example() {
return (
<div className="w-full flex items-center justify-center p-8">
<FluidCanvas
colors="example"
speed{10}
/>
</div>
);
}