npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dropping-canvas

v1.0.4

Published

[![npm](https://img.shields.io/npm/v/dropping-canvas)](https://www.npmjs.com/package/dropping-canvas) ![GitHub file size in bytes](https://img.shields.io/github/size/Gwokhov/dropping-canvas/dist/dropping.js)

Downloads

8

Readme

DroppingCanvas

npm GitHub file size in bytes

Introduction

💧 DroppingCanvas is a lightweight (5 KB) physics tool which can help you generate random motive image object simply on canvas. It is inspired by sprinkler, and DroppingCanvas also provide more flexible and modern APIs.

Demo

Demo

Install

npm install dropping-canvas
# or
yarn add dropping-canvas

or just include the compiled file to your page:

<script src="./dropping.js"></script>

Get Started

Just a few code to run:

var canvas = document.getElementById('canvas')
var images = ['./images/1.png', './images/2.png', './images/3.png']
var droppingCanvas = new DroppingCanvas(canvas, images)

droppingCanvas.start()

If you want to modify the motion of objects, you can pass an option as param to the constructor or use method updateOptions. For exmple:

...
var options = {
  dropPerSecond: 15,
  r: 2,
  vY: [200, 400],
  aA: [-0.2, -0.1]
}
// for more options check Option Properties

var droppingCanvas = new DroppingCanvas(canvas, images, options)
...

Now the vertical speed is in the range of 200-400 (random).

For more options, you can see the Demo or check below 👇.

Option Properties

| Property | Type | Description | Default | | -------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------ | | dropPerSecond | Number, String | Number of objects generate in a second. | 20 | | isBoundingSize | Boolean | Restrict the object rebound when z(size) is negative. | true | | x | null, Array, Number | (Range of) initial horizontal position. null: object will generate randomly in the range of canvas width. | null | | y | null, Array, Number | (Range of) initial vertical position. null: object will generate over the top of canvas.(cal the maximum radius) | null | | z | Array, Number | (Range of) initial size(scale). | [0.2 , 0.3 ] | | a | Array, Number | (Range of) initial transparency(alpha). | a: [1 , 1 ] | | r | Array, Number | (Range of) initial rotation. | [0 , 2 * Math .PI] | | vX | Array, Number | (Range of) horizontal velocity. | [-60 , 60 ] | | vY | Array, Number | (Range of) vertical velocity. | [200 , 500 ] | | vZ | Array, Number | (Range of) scale velocity. | [0 , 0 ] | | vA | Array, Number | (Range of) transparency(alpha) velocity. | [0 , 0 ] | | vR | Array, Number | (Range of) rotation velocity. | [-1 , 1 ] | | aX | Array, Number | (Range of) horizontal acceleration. | [0 , 0 ] | | aY | Array, Number | (Range of) vertical acceleration. | [80 , 200 ] | | aZ | Array, Number | (Range of) scale acceleration. | [-0.3 , 0 ] | | aA | Array, Number | (Range of) transparency(alpha) acceleration. | [-1 , -0.6 ] | | aR | Array, Number | (Range of) rotation acceleration. | [0 , 0 ] |

Methods

| Method | Arguments | Description | | ------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | start | | Activate the animation. | | pause | | Pause the animation. | | stop | isImmediateClean=false | Stop the animation. If isImmediateClean is true, objects will fade out immediately, otherwise the animation will stop after objects disappear from canvas. | | updateOptions | options, isCover=false | Update the physics options of object. If isCover is true, it will just update the options you pass, otherwise other options will replace by default options. | | updateImages | images | Update the Images of generate object. It accepts Array, String, FileList. |