Skip to content

Glitter API

Glitter

Extends Effect.

Factory Function

typescript
createGlitter(config?: GlitterConfig)

Methods

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


GlitterConfig

typescript
interface GlitterConfig {
    count?: number;
    colors?: string[];
    size?: number;
    speed?: number;
    groundLevel?: number;
    maxSettled?: number;
    scale?: number;
}
PropertyTypeDefaultDescription
countnumber80Number of falling glitter pieces. Automatically halved on small screens.
colorsstring[]['#ffd700', '#c0c0c0', '#ff69b4', '#00bfff', '#ff4500', '#7fff00', '#9370db']Hex color strings for the glitter pieces.
sizenumber4Base glitter piece size in pixels (before scale).
speednumber1Fall speed multiplier.
groundLevelnumber0.85Normalized Y position (0-1) where glitter settles.
maxSettlednumber200Maximum number of settled pieces on the ground. Oldest pieces are removed when exceeded.
scalenumber1Scales all piece sizes proportionally.

FallingGlitter

Internal representation of a falling glitter piece.

typescript
type FallingGlitter = {
    x: number;           // Normalized X position (0-1)
    y: number;           // Normalized Y position (0-1)
    vy: number;          // Vertical velocity
    size: number;        // Piece size in pixels
    rotation: number;    // Current rotation angle
    rotationSpeed: number; // Rotation speed per frame
    flipAngle: number;   // 3D flip angle for depth simulation
    flipSpeed: number;   // Flip rotation speed
    sparkle: number;     // Current sparkle intensity (0-1)
    colorIndex: number;  // Index into the colors array
    settled: boolean;    // Whether the piece has settled
};

SettledGlitter

Internal representation of a settled glitter piece on the ground.

typescript
type SettledGlitter = {
    x: number;           // Normalized X position (0-1)
    y: number;           // Normalized Y position (0-1)
    size: number;        // Piece size in pixels
    rotation: number;    // Fixed rotation angle
    sparklePhase: number; // Phase offset for sparkle animation
    sparkleSpeed: number; // Speed of sparkle pulsing
    colorIndex: number;  // Index into the colors array
};