Skip to content

Donuts API

Donuts

Extends Effect.

Factory Function

typescript
createDonuts(config?: DonutsConfig)

Methods

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


DonutsConfig

typescript
interface DonutsConfig {
    background?: string;
    collisionPadding?: number;
    colors?: string[];
    count?: number;
    gradient?: boolean;
    mouseAvoidance?: boolean;
    mouseAvoidanceRadius?: number;
    mouseAvoidanceStrength?: number;
    radiusRange?: [number, number];
    repulsionStrength?: number;
    rotationSpeedRange?: [number, number];
    scale?: number;
    speedRange?: [number, number];
    thickness?: number;
}
PropertyTypeDefaultDescription
backgroundstring'#a51955'Canvas background fill color.
collisionPaddingnumber20Minimum spacing between donut edges in pixels.
colorsstring[]['#bd1961', '#da287c']Fill colors for the donuts. Each donut picks a random color.
countnumber12Number of donuts on screen.
gradientbooleanfalseWhen enabled, donuts are filled with a radial gradient.
mouseAvoidancebooleanfalseWhen enabled, donuts move away from the mouse cursor.
mouseAvoidanceRadiusnumber150Distance in pixels within which donuts are repelled from the cursor (before scale).
mouseAvoidanceStrengthnumber0.03How strongly donuts are repelled from the cursor. Higher = stronger avoidance.
radiusRange[number, number][60, 90]Outer radius range [min, max] in pixels (before scale).
repulsionStrengthnumber0.02How strongly donuts repel each other. Higher = snappier avoidance.
rotationSpeedRange[number, number][0.0005, 0.002]Rotation speed range [min, max] in radians per frame.
scalenumber1Scales donut radius, speed, and collision padding proportionally.
speedRange[number, number][0.15, 0.6]Movement speed range [min, max] in pixels per frame (before scale).
thicknessnumber0.39Ring thickness as a fraction of the outer radius (0–1).