Skip to content

Snow API

SnowSimulation

Extends LimitedFrameRateCanvas.

Constructor

typescript
new SnowSimulation(canvas: HTMLCanvasElement, config?: SnowSimulationConfig)

Methods

start(): void

Starts the snowfall animation.

stop(): void

Stops the snowfall animation.

destroy(): void

Stops the animation and removes all event listeners.


SnowSimulationConfig

typescript
interface SnowSimulationConfig {
    fillStyle?: string;
    particles?: number;
    scale?: number;
    size?: number;
    speed?: number;
    canvasOptions?: CanvasRenderingContext2DSettings;
}
PropertyTypeDefaultDescription
fillStylestring'rgb(255 255 255 / .75)'CSS color string for the snowflake fill.
particlesnumber200Number of snowflakes. Automatically halved on small screens.
scalenumber1Scales all snowflake sizes proportionally.
sizenumber6Maximum snowflake radius in pixels (before scale).
speednumber2Fall speed multiplier.
canvasOptionsCanvasRenderingContext2DSettings{colorSpace: 'display-p3'}Options passed to canvas.getContext('2d').

Snowflake

Internal representation of a snowflake particle.

typescript
interface Snowflake {
    x: number;       // Normalized X position (0-1)
    y: number;       // Normalized Y position (0-1)
    density: number;  // Controls the wave/swing pattern
    radius: number;   // Visual radius in pixels
}