start()
start(run?: RunOptions): this
Starts the fireworks show. Fires an opening salvo, begins the render loop, and fades in the backdrop.
Returns: this.
fireworks.start({ duration: 10000 });
Configure the show before it starts. Control it after initialisation.
Defaults are preset. Change values inline, hover or focus a help button for a brief explanation, or click it for full details. Styles and presets may change resolved defaults.
Use these public members on your initialised fireworks instance.
After const fireworks = new GrandFireworks(config), these methods control the instance. A return type of this means the same instance, so calls can be chained. Await Promise-returning methods to wait for completion. Examples below are code samples; they do not launch effects on this page.
await fireworks.stop();
// Stops new launches, finishes active fireworks,
// plays the finale when configured, fades out, then resolves.
fireworks.stop({ immediate: true }); // Emergency stop
fireworks.stop({ finale: false }); // Skip one configured finale
fireworks.finalize(); // Graceful stop with finalestart()start(run?: RunOptions): this
Starts the fireworks show. Fires an opening salvo, begins the render loop, and fades in the backdrop.
Returns: this.
fireworks.start({ duration: 10000 });stop()stop(options?: StopOptions): Promise<this>
Gracefully stops the show. Enters the "finishing" state — lets in-flight rockets complete, optionally triggers the finale, then fades out.
Returns: Promise<this>.
await fireworks.stop({ finale: true });pause()pause(internal?: boolean | string): this
Pauses the show. Pass internal=true (or a string reason) for automatic pauses such as hidden tabs or offscreen visibility.
Returns: this.
fireworks.pause();resume()resume(internal?: boolean | string): this
Resumes a previously paused show.
Returns: this.
fireworks.resume();clear()clear(): this
Clears all in-flight rockets, particles, flashes, and text effects.
Returns: this.
fireworks.clear();destroy()destroy(): void
Destroys the instance, releasing listeners, animation state, audio, and renderer resources.
Returns: void.
fireworks.destroy();finalize()finalize(): Promise<this>
Triggers stop() with the finale forced on.
Returns: Promise<this>.
await fireworks.finalize();launch()launch(options?: LaunchOptions): this
Manually fires a single rocket with optional overrides.
Returns: this.
fireworks.launch({ type: 'grand_peony', x: 0.5, burstHeight: 0.3 });placeburst()placeburst(options?: BurstOptions): this
Detonates a shell immediately at a point, fitted to the requested on-screen radius. No rocket and no flight time.
Returns: this.
fireworks.placeburst({ element: '#celebrate', radius: 120 });launchTo()launchTo(options: LaunchToOptions): this
Flies a rocket from one point to another and bursts on arrival, using the same origin and travel time the host is simulating.
Returns: this.
fireworks.launchTo({ x: 40, y: 300, targetX: 200, targetY: 80, duration: 600, radius: 100 });launchText()launchText(text: string, overrides?: Partial<TextFireworkOptions>): Promise<string[]>
Rasterizes text to a hidden canvas and fires rockets that assemble into the text shape mid-air. Resolves with the rendered lines.
Returns: Promise<string[]>.
const lines = await fireworks.launchText('HELLO', { tilt: [-15, 15] });launchTextSequence()launchTextSequence(messages: string | TextSequenceItem[] | TextSequenceItem, options?: TextSequenceOptions,): Promise<TextSequenceResult>
Plays a sequence of text fireworks. Resolves when the sequence completes or is cancelled.
Returns: Promise<TextSequenceResult>.
const result = await fireworks.launchTextSequence(['READY', 'GO'], { interval: 3000 });cancelTextSequence()cancelTextSequence(options?: { clear?: boolean }): boolean
Cancels the current text sequence. Returns true if a sequence was cancelled.
Returns: boolean.
const cancelled = fireworks.cancelTextSequence({ clear: true });launchFinale()launchFinale(options?: FinaleLaunchOptions): this
Launches the Super Grand Finale, or the World Ender when finale.type is 'world-ender'.
Returns: this.
fireworks.launchFinale({ stopAfter: false });launchWorldEnder()launchWorldEnder(overrides?: Partial<WorldEnderOptions>): this
Launches a staged, branching World Ender effect.
Returns: this.
fireworks.launchWorldEnder({ firstSplitCount: 6, stopAfter: false });setOptions()setOptions(partial: GrandFireworksOptions): this
Merges partial options into the current configuration and re-resolves.
Returns: this.
fireworks.setOptions({ show: { intensity: 1.2 } });setOpacity()setOpacity(level: number): this
Sets the overall opacity of the fireworks layer (0 to 1).
Returns: this.
fireworks.setOpacity(0.7);setZoom()setZoom(level: number): this
Sets the viewport zoom level, scaling from the screen center (0.1 to 4).
Returns: this.
fireworks.setZoom(0.5);setStyle()setStyle(name: StyleName): this
Switches to a named visual style preset.
Returns: this.
fireworks.setStyle('cinematic');setColorTheme()setColorTheme(name: ColorThemeName): this
Switches to a named colour theme and recolors in-flight particles and rockets.
Returns: this.
fireworks.setColorTheme('iceBlue');enableSound()enableSound(): this
Enables procedural audio synthesis and fires up the AudioContext.
Returns: this.
button.addEventListener('click', () => fireworks.enableSound());disableSound()disableSound(): this
Suspends audio and tears down the ambience source.
Returns: this.
fireworks.disableSound();setMuted()setMuted(muted?: boolean): this
Sets master volume to 0 (muted) or restores the previous level.
Returns: this.
fireworks.setMuted(true);
fireworks.setMuted(false); // restore previous volumefeelingLucky()feelingLucky(): GrandFireworksOptions & { transition?: TransitionOptions }
Randomizes the visual configuration and applies it live. Returns the generated configuration.
Returns: GrandFireworksOptions & { transition?: TransitionOptions }.
const generated = fireworks.feelingLucky();getOptions()getOptions(): GrandFireworksOptions
Deep-cloned snapshot of the current resolved options.
Returns: GrandFireworksOptions.
const settings = fireworks.getOptions();getStats()getStats(): Stats
A snapshot of the current runtime statistics.
Returns: Stats.
const stats = fireworks.getStats();
console.log(stats.state, stats.fps);setRenderPass()setRenderPass(callback: RenderPass | null): this
Registers a host render pass — the engine lends its canvas and the host draws the scene. The callback runs each frame after the canvas has been cleared (or trail-faded) and before the fireworks are drawn, so host artwork sits behind them. Attaching a pass makes the host responsible for frame pacing: the engine stops starting its own animation loop (including from start() and stop()) and expects renderFrame(dt) to be called each frame. Pass null to detach.
Returns: this.
fireworks.setRenderPass(frame => {
// Draw your scene with frame.ctx or frame.gl; do not clear the frame.
});renderFrame()renderFrame(dt?: number): this
Advances the simulation by dt milliseconds and draws one frame. For hosts that own the animation loop alongside a render pass. dt is capped at 50ms internally. Pass 0 to render the current frame without advancing anything. A show `duration` and a `stop()` wind-down are carried out here, so the stop() promise resolves; the canvas stays visible afterwards because the host's scene is drawn on it.
Returns: this.
fireworks.renderFrame(16.67); // milliseconds since the last frameOmitted option objects default to an empty object and inherit the instance settings where applicable. pause() and resume() default to a manual pause reason; ordinary callers should omit their internal argument. setMuted() defaults to true; renderFrame() defaults to 0; setRenderPass() defaults to null. Text overrides use the text configuration options; World Ender overrides use the World Ender options.
| Field | Type | Meaning |
|---|---|---|
duration? | number | Runtime duration override, in ms. |
| Field | Type | Meaning |
|---|---|---|
immediate? | boolean | Skip the wind-down and fade immediately. |
finale? | boolean | Force or suppress the finale. |
| Field | Type | Meaning |
|---|---|---|
type? | ShellType | 'grand-finale-carrier' | 'text' | Shell type for launches, or regular shell type for point bursts; see shell choices. |
x? | number | Launch x is a width fraction; burst/launchTo x is CSS pixels from the container’s left. |
y? | number | CSS pixels from the container’s top for placeburst/launchTo. |
burstHeight? | number | Burst y as a height fraction from the top; depth staging can adjust it. |
colors? | ColorString[] | Hex colour palette for this effect. |
angle? | number | Rocket angle in degrees. |
apparentScale? | number | Per-shell apparent size multiplier. |
finale? | boolean | Mark the shell as a finale shell. |
syncAt? | number | Target arrival time in the engine’s effect clock; advanced scheduling. |
| Field | Type | Meaning |
|---|---|---|
x? | number | CSS pixels from the container's left edge. |
y? | number | CSS pixels from the container's top edge. |
element? | Element | string | Burst at this element's centre instead of at x/y. |
radius? | number | Target on-screen burst radius in CSS pixels. The sparks are fitted to it by scaling velocity and gravity together, so the shell keeps its shape. The fit targets the rim of the break, so a few of the fastest stars travel past the radius. Omit for the shell's natural size. |
reachTime? | number | Milliseconds for the stars to reach `radius`. Omit it and the fit targets the asymptotic reach, so the break keeps coasting outward for well over a second — which lets a game that damages on impact kill things the visible explosion has not reached. Set it to your blast's rise time so the rim arrives on schedule. Star types that override their own drag (willow, palm, horsetail) keep the asymptotic fit. |
gravityScale? | number | Multiplies the spark fall after the radius fit. `0.1` makes the break drift down at a tenth of the usual rate instead of dropping. |
lifeScale? | number | Multiplies how long the sparks live. Below 1 they fade over the fall rather than outliving the explosion. |
type? | ShellType | (string & {}) | Shell type. Structural types (text, finale carriers) fall back to grand_peony. |
colors? | ColorString[] | Palette for the burst. |
density? | number | Spark multiplier; 1 is normal. |
sound? | boolean | false silences this burst only, leaving the engine's sound setting alone. |
| Field | Type | Meaning |
|---|---|---|
x | number | Launch point, CSS pixels relative to the container. |
y | number | Launch point, CSS pixels relative to the container. |
targetX | number | Detonation point, CSS pixels relative to the container. |
targetY | number | Detonation point, CSS pixels relative to the container. |
duration? | number | Flight time in milliseconds. Defaults to 600. |
| Field | Type | Meaning |
|---|---|---|
interval? | number | Time between items, in ms. |
startDelay? | number | Delay before the first item, in ms. |
overrides? | Partial<TextFireworkOptions> | Global overrides applied to every item. |
clearBetween? | boolean | Clear the previous text between items. |
clearOnComplete? | boolean | Clear text effects when the sequence ends. |
clearExisting? | boolean | Clear any existing text effects before starting. |
| Field | Type | Meaning |
|---|---|---|
stopAfter? | boolean | Stop automatic launches after the finale; manual finales stay live by default. |
forceSuper? | boolean | Force the super-grand-finale even when finale.type is 'world-ender'. |
worldEnder? | WorldEnderOptions | Overrides forwarded to launchWorldEnder() when finale.type is 'world-ender'. |
launchTextSequence() accepts a string, an item object, or an array. Item objects use { text, overrides?, duration? }; duration is the interval until the next item in ms. It resolves to { status: "completed" | "cancelled", completed, total }. cancelTextSequence({ clear: true }) also clears active text; clear defaults to true. The runtime additionally accepts gap (extra ms in automatic sequencing), which is currently absent from the TypeScript declarations.
The declarations expose methods and static catalogues. Runtime instance properties exist, but are not declared as a stable public property contract. Use snapshots and setters rather than assigning internal arrays, timers, renderer state or fireworks.options directly.
rendererfallbackActivecontextLossCountstateparticlesrocketsfpsdurationRemainingqualitygetOptions() returns a deep-cloned resolved configuration. Editing it does not apply settings: call setOptions() to apply changes. getStats() returns a snapshot, not a live object.
GrandFireworks.VERSIONGrandFireworks.DEFAULTSGrandFireworks.PRESETSGrandFireworks.TYPESGrandFireworks.STYLESGrandFireworks.COLOR_THEMESStatic catalogues are shared runtime objects; treat them as read-only. To customize an instance, pass your own options.
Lifecycle events use ordinary Event objects without a detail payload: start fires when the show starts; pause when a manual pause changes the pause state; resume when a manual resume changes it; stop when shutdown finishes. Custom events below carry detail.
The instance extends EventTarget. Use addEventListener(), removeEventListener() and dispatchEvent() with normal browser EventTarget semantics. Read engine event payloads through event.detail.
rendererchangefinalestagetextlaunchtextsequencestarttextsequenceitemtextsequenceendtextsequencecancelfunction onRendererChange(event) {
console.log(event.detail.from, event.detail.to);
}
fireworks.addEventListener('rendererchange', onRendererChange);
// Before discarding your host component:
fireworks.removeEventListener('rendererchange', onRendererChange);A render pass receives { gl, ctx, canvas, width, height, dpr }. Exactly one context is non-null. Width and height are CSS pixels; dpr describes the drawing buffer. Draw your scene after the engine clears the frame and before its fireworks. Attaching a pass stops the engine’s own loop; continue calling renderFrame during a stop wind-down so its Promise can resolve. Frame deltas are capped at 50 ms. Detach with setRenderPass(null).
let last = performance.now();
let frameId;
function frame(now) {
fireworks.renderFrame(now - last);
last = now;
frameId = requestAnimationFrame(frame);
}
frameId = requestAnimationFrame(frame);
// When the host is disposed: cancelAnimationFrame(frameId); fireworks.destroy();