Skip to content

Fireworks API

FireworkSimulation

Extends LimitedFrameRateCanvas.

Constructor

typescript
new FireworkSimulation(canvas: HTMLCanvasElement, config?: FireworkSimulationConfig)

Methods

start(): void

Starts the simulation loop.

stop(): void

Stops the simulation loop.

destroy(): void

Stops the simulation and removes all event listeners.

fireExplosion(variant, position?): void

Fires a single explosion of the given variant.

typescript
sim.fireExplosion(variant: FireworkVariant, position?: Point): void
ParameterTypeRequiredDescription
variantFireworkVariantYesThe explosion type to fire.
positionPointNoScreen position in pixels. Defaults to center at 40% height.

FireworkSimulationConfig

typescript
interface FireworkSimulationConfig {
    scale?: number;
    autoSpawn?: boolean;
    canvasOptions?: CanvasRenderingContext2DSettings;
}
PropertyTypeDefaultDescription
scalenumber1Scales all particle sizes, trail widths, and glow proportionally.
autoSpawnbooleantrueWhen false, no fireworks are launched automatically. Use fireExplosion() for manual control.
canvasOptionsCanvasRenderingContext2DSettings{colorSpace: 'display-p3'}Options passed to canvas.getContext('2d').

FireworkVariant

Union type of all available explosion variants.

typescript
type FireworkVariant =
    | 'peony' | 'chrysanthemum' | 'willow' | 'ring'
    | 'palm' | 'crackle' | 'crossette' | 'dahlia'
    | 'brocade' | 'horsetail' | 'strobe' | 'heart'
    | 'spiral' | 'flower' | 'saturn' | 'concentric';

Variant Details

Classic

VariantParticlesShape3DGravityNotes
peony50-70CircleYes0.8Standard spherical burst.
chrysanthemum80-120LineYes0.5Dense, long trails, sparkle.
willow50-70LineNo1.5Long drooping trails.
palm20-30LineNo1.2Narrow upward cone.
brocade60-80LineNo1.3Golden shimmer, sparkle. Forced hue 35-50.
horsetail30-40LineNo2.0Extreme gravity fountain cascade.

Geometric

VariantParticlesShapeNotes
ring40-60DiamondEvenly distributed angles forming a circle.
concentric60-85DiamondComposite: outer ring (speed 7-10) + inner ring (speed 3-5), hue +120.
saturn90-150MixedComposite: outer shell + filled sphere + rotated elliptical ring (hue +60) with z-depth.

Shapes

VariantParticlesShapeGravityNotes
heart60-80Circle0.3Parametric heart curve with slight random tilt.
flower70-90Circle0.3Rose curve r = |cos(nθ)| with 2-4 petals.
spiral45-60Circle0.43-5 arms with increasing angle/speed offset.
dahlia48-108Circle0.76-9 petal groups with alternating hue (±25).

Effects

VariantParticlesShapeNotes
crackle40-55Star8 sparks emitted when each particle dies.
crossette16-20CircleSplits into 4 peony sub-bursts at alpha 0.5.
strobe40-55CircleBlinks on/off (3 frames each) at ~10Hz.

ExplosionType

A subset of FireworkVariant — all variants except composites.

typescript
type ExplosionType =
    | 'peony' | 'chrysanthemum' | 'willow' | 'ring'
    | 'palm' | 'crackle' | 'crossette' | 'dahlia'
    | 'brocade' | 'horsetail' | 'strobe' | 'heart'
    | 'spiral' | 'flower';

ParticleShape

The visual shape drawn at the head of a particle.

typescript
type ParticleShape = 'line' | 'circle' | 'star' | 'diamond';

FIREWORK_VARIANTS

typescript
const FIREWORK_VARIANTS: FireworkVariant[]

Array containing all 16 variant names. Useful for building UIs.


Point

typescript
type Point = {
    x: number;
    y: number;
};