Skip to content

Particles API

Particles

Extends Effect.

Factory Function

typescript
createParticles(config?: ParticlesConfig)

Methods

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


ParticlesConfig

typescript
interface ParticlesConfig {
    count?: number;
    color?: string;
    lineColor?: string;
    size?: [number, number];
    speed?: [number, number];
    connectionDistance?: number;
    lineWidth?: number;
    mouseMode?: ParticleMouseMode;
    mouseRadius?: number;
    mouseStrength?: number;
    particleForces?: boolean;
    glow?: boolean;
    background?: string | null;
    scale?: number;
}
PropertyTypeDefaultDescription
countnumber100Number of particles. Automatically halved on small screens.
colorstring'#6366f1'Particle fill color (hex string).
lineColorstring'#6366f1'Connection line color (hex string).
size[number, number][1, 3]Min/max particle radius in pixels.
speed[number, number][0.2, 0.8]Min/max particle drift speed.
connectionDistancenumber120Maximum distance for connection lines (before scale).
lineWidthnumber0.5Connection line width in pixels.
mouseModeParticleMouseMode'connect'Mouse interaction mode.
mouseRadiusnumber150Mouse influence radius in pixels (before scale).
mouseStrengthnumber0.03Mouse force strength (attract/repel modes).
particleForcesbooleanfalseEnable inter-particle repulsion.
glowbooleanfalseEnable particle glow effect via shadowBlur.
backgroundstring | nullnullBackground fill color. null for transparent.
scalenumber1Global scale factor.

ParticleMouseMode

typescript
type ParticleMouseMode = 'attract' | 'repel' | 'connect' | 'none';
ModeDescription
attractParticles within mouseRadius are pulled toward the cursor.
repelParticles within mouseRadius are pushed away from the cursor.
connectConnection lines are drawn between the cursor and nearby particles.
noneNo mouse interaction.

NetworkParticle

Internal representation of a particle.

typescript
type NetworkParticle = {
    x: number;        // X position in pixels
    y: number;        // Y position in pixels
    vx: number;       // Horizontal velocity
    vy: number;       // Vertical velocity
    radius: number;   // Particle radius
    baseSpeed: number; // Base drift speed
};

Performance

The simulation uses spatial grid partitioning to efficiently find nearby particles. Each frame, particles are bucketed into grid cells of size connectionDistance. Only neighboring cells are checked for connections, reducing the complexity from O(n^2) to approximately O(n*k), where k is the average number of neighbors per cell.

For best performance, keep count under 200 particles.