Skip to content

Lightning API

Lightning

Extends Effect.

Factory Function

typescript
createLightning(config?: LightningConfig)

Methods

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


LightningConfig

typescript
interface LightningConfig {
    frequency?: number;
    color?: string;
    branches?: boolean;
    flash?: boolean;
    scale?: number;
}
PropertyTypeDefaultDescription
frequencynumber1Bolt spawn rate multiplier. 1 means roughly one bolt every 3 seconds.
colorstring'#b4c8ff'Hex color string for the bolt glow. The inner line is always white.
branchesbooleantrueEnable smaller branch bolts forking off the main bolt.
flashbooleantrueEnable a brief white screen flash when a bolt strikes.
scalenumber1Global scale factor for line widths.

LightningBolt

Internal representation of a lightning bolt.

typescript
type LightningBolt = {
    segments: { x: number; y: number }[];  // Normalized positions (0-1)
    branches: LightningBranch[];         // Forked sub-bolts
    alpha: number;                       // Current opacity (1 to 0)
    lifetime: number;                    // Total lifetime in ticks
    ticksAlive: number;                  // Ticks since spawn
};

LightningBranch

Internal representation of a branch forking off a main bolt.

typescript
type LightningBranch = {
    segments: { x: number; y: number }[];  // Normalized positions (0-1)
    alpha: number;                       // Branch opacity relative to parent
};