Skip to content

Fluid API

Fluid

Extends Effect.

Factory Function

typescript
createFluid(config?: FluidConfig)

Methods

See Effect for the full method reference: mount(), start(), pause(), resume(), configure(), withFade(), and destroy().

The fluid effect responds to mouse movement: moving the mouse over the canvas stirs the velocity field and injects colored dye.


FluidConfig

typescript
interface FluidConfig {
    speed?: number;
    resolution?: number;
    colors?: string[];
    viscosity?: number;
    diffusion?: number;
    mouseForce?: number;
    scale?: number;
}
PropertyTypeDefaultDescription
speednumber1Animation speed multiplier.
resolutionnumber128Grid resolution for the fluid simulation (higher = smoother but slower).
colorsstring[]['#ff3366', '#33ccff', '#66ff33', '#ff9933', '#cc33ff']Dye colors injected into the simulation.
viscositynumber0.5Velocity damping — higher values make the fluid thicker.
diffusionnumber0.5Dye spreading rate — higher values make colors spread faster.
mouseForcenumber1Strength of the mouse stir force.
scalenumber1Global scale factor.

FluidCell

Internal representation of a single grid cell in the simulation.

typescript
type FluidCell = {
    vx: number;
    vy: number;
    dyeR: number;
    dyeG: number;
    dyeB: number;
};