Coder Social home page Coder Social logo

confetti.js's Introduction

Confetti.js Build Status

A library to meet your confetti needs.

Example

Check out this plunker for a live example of this library.

About

Need a festive celebration on your page? Confetti.js gives you the ability to control the confetti on your canvas tag with animation functions of your choosing for each piece of confetti while avoiding having to do the messy recursive logic of animating and garbage collecting.

Usage

  • Include confetti.js script
  • Follow demo/demo.js example for how to use the library
  • ????
  • Profit!

API

  • Confetti.DEFAULT_NUM: Default number of confetti pieces to assume - default value is 500
  • Confetti.color(): A helper function for randomly generating an rgba color using the Math.random function
  • Confetti.randomFrom(a, b, factor): A helper function which takes two numbers and returns a random number from a to b, not including b. If factor is present, it is equivalent to Math.floor(Math.random() * (b - a) * factor) / factor.
  • Confetti.createCanvas(element, canvas): Takes two arguments, the DOM node for the canvas to base its dimensions off of (or an object with offsetWidth & offsetHeight keys), and the canvas DOM node. Returns a Canvas instance, which has properties:
  • element: the first argument from createCanvas
  • canvas: the second argument from createCanvas
  • context: the 2d context of the canvas element
  • width: the width from the element
  • height: the height from the element
  • setDimensions(): a function that sets the canvas width and height to the same values as the element width and height
  • destroy(): a function that prepares the canvas for garbage collecting
  • step(confettiArray, config) - Arguments
    • confettiArray: array of ConfettiClass instances
    • config: object of key/values that are to be used to update the confetti
    • draw(confetti): function that takes ConfettiClass instance and renders confetti on canvas
    • updatePosition(confetti, index): function that takes ConfettiClass instance and index in confettiArray. It's purpose is to update the position of each confetti piece
    • updateState(): (optional) function whose purpose is to update the state before render
  • Confetti.create(config): Takes a config object and returns a new ConfettiClass instance
    • config.color: (optional) the color for the piece of confetti - defaults to Confetti.color()
    • config.d: (optional) the density for the piece of confetti - defaults to Confetti.randomFrom(10, 10 + Confetti.DEFAULT_NUM)
    • isFlakeExiting(canvas): Takes a Canvas instance and checks whether the confetti is exiting the canvas on the left, right, or bottom

confetti.js's People

Contributors

monir avatar wesleycho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.