Skip to content

brambex/fireworks

This branch is 28 commits behind tswaters/fireworks:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

728bc0e · Jan 5, 2020

History

56 Commits
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 27, 2018
Jul 4, 2016
Jan 4, 2020
Jan 4, 2020
Jan 5, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020
Jan 4, 2020

Repository files navigation

Fireworks Canvas Example

Take a look at the live example!

install

bower install --save fireworks-canvas
npm install --save fireworks-canvas

usage

import * as Fireworks from 'fireworks-canvas' // mjs

const Fireworks = require('fireworks-canvas') // cjs

requirejs(['Fireworks'], Fireworks => {}) // amd

const Fireworks = window.Fireworks // browser global

// needs at least a container element, you can provide options
// (options are optional, defaults defined below)
const container = document.getElementById('container')
const options = {
  maxRockets: 3, // max # of rockets to spawn
  rocketSpawnInterval: 150, // millisends to check if new rockets should spawn
  numParticles: 100, // number of particles to spawn when rocket explodes (+0-10)
  explosionMinHeight: 0.2, // percentage. min height at which rockets can explode
  explosionMaxHeight: 0.9, // percentage. max height before a particle is exploded
  explosionChance: 0.08, // chance in each tick the rocket will explode
  width: container.clientWidth, // override the width, defaults to container width
  height: container.clientHeight // override the height, defaults to container height
}

// instantiate the class and call start
// this returns a disposable - calling it will stop fireworks.
const fireworks = new Fireworks(container, options)
const stop = fireworks.start()
stop() // stop rockets from spawning
fireworks.stop() // also stops fireworks.
fireworks.kill() // forcibly stop fireworks
fireworks.fire() // fire a single rocket.
fireworks.resetSize() // resets the size to the containers dimensions
fireworks.setSize(100, 100) // sets the size to the specified dimensions

usage with typscript

import * as FireworksCanvas from 'fireworks-canvas'
const fireworks = new FireworksCanvas(container)

OR

import FireworksCanvas = require('fireworks-canvas')
const fireworks = new FireworksCanvas(container)

support

Should work in most browsers.

Note that you'll need a polyfill for Set to support iexplore 11.

development

npm i
npm start
# open localhost:8001 in your favourite browser

Packages

No packages published

Languages

  • TypeScript 82.3%
  • JavaScript 14.1%
  • HTML 3.6%