GithubHelp home page GithubHelp logo

ps10475 / fireworks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tswaters/fireworks

0.0 0.0 0.0 445 KB

Fireworks Canvas Example

Home Page: https://tswaters.github.io/fireworks/

License: Do What The F*ck You Want To Public License

HTML 17.48% TypeScript 70.19% JavaScript 12.33%

fireworks's Introduction

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


  // array of points, defaults to []
  // when x is null or not defined, uses random position between 0 -> container width
  // when y is null or not defined, uses container height
  cannons: [{ x: width * 0.2 }, { x: width * 0.8 }],

  // defines a single cannon with null for height and provided value for X.
  // will be apended to provided cannons
  rocketInitialPoint: width * 0.5,

}

// 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
fireworks.onFinish(() => container.remove()) // callback when the last firework disappears

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

fireworks's People

Contributors

tswaters avatar kyle1320 avatar daileytj avatar tugrik avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.