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

canvas-image

v0.0.7

Published

CanvasImage - scripting animation on canvas

Downloads

17

Readme

CanvasImage

Create animations with indepedent movements out of images.

Example

<canvas id='canvas' width=240 height=120></canvas>

var CanvasImage = require('canvas-image');
$(window).ready(function() {
    var anim = new CanvasImage.Animation;
    var canvas = document.getElementById('canvas');
    var bar = new CanvasImage;
    bar
    .setDimensions(canvas)
    .setFrames(100)
    .setImg('foo.png',401,436)
    .setAnchor('center')
    .setScaling({easing:'sinusoidal',start:0.5,end:1});
    anim.animate([bar],canvas);
});

.setFrames(num)

Set the number of frames to specify the duration of the effects

.setFrames(40) // 40 frames worth of effects

.setDimensions(canvas)

Pass this function with a canvas element that has the width and height you intend to draw on.

.setImg('imgsrc.png',width,height)

Pass the img path, the width, and the height of the image.

.setAnchor

Achor will affect the rotate, scaling, and movement animations such that they occur around the anchor point instead of the midpoint. You can either call .setAnchor('center') or .setAnchor({x:24,y:155}) for example to anchor at (24,155).

.setRotate

Specify start rotation and end rotation in degrees.

.setRotate({start:0, end:180}); // start at 0 degrees and end at 180degrees.

// or

.setRotate({start:0, end:45, easing:'linear'})


// Check out [node-easing](https://github.com/rook2pawn/node-easing)

You can also pass an "endToEnd" flag to tell the easer to go back and forth, i.e. {start:0, end: 45, easing:'linear', endToEnd:true}

.setOpacity

Governs opacity. start values can range from 0 to 1 and end values can range from 0 to 1.

.setScaling

Governs scaling. start values can range from 0 to any number, and end values can range from 0 to any number. 1 = 100% scaling (no scaling).

.setMovement

.setMovement({start:{x:0,y:0},end:{x:100,y:100}});

// goes from 0,0, to 100,100

ANIMATION PACKAGE

var anim = new CanvasImage.Animation

ANIMATION Methods

anim.animate(list,canvasElement,cb)

.animate will take a list of CanvasImage elements, draw them on the supplied canvasElement, then when the animation is finished, will execute the supplied callback if there is one. Here's an example

var CanvasImage = require('canvas-image');
var bar = new CanvasImage;
var cat = new CanvasImage;
var anim = new CanvasImage.Animation;
bar
.setDimensions(canv)
.setFrames(15)
.setImg('foo.png',199,32)
.setAnchor('center')
.setRotate({easing:'linear',start:0,end:360})
.setMovement({start:{x:-100,y:-100},end:{x:0,y:0}})
.setScaling({easing:'linear',start:0.2,end:1});
cat
.setDimensions(canv)
.setFrames(15)
.setImg('bar.png',135,32)
.setAnchor('center')
.setMovement({start:{x:100,y:100},end:{x:-200,y:0}})
.setScaling({easing:'linear',start:0.2,end:1});

var mycanvas = document.getElementById('mycanvas');
anim.animate([bar,cat],mycanvas,function() {
    anim.dimmer(mycanvas);
});

In this example, bar and cat are two indepedent CanvasImage elements that have positional, rotationl, and movement, and scaling elements over time. anim.animate takes these two and renders them onto a canvas with id mycanvas. Then, when the animation is finished, the callback is called and there is a convenience method called .dimmer that takes a canvas element and quickly reduces the opacity to 0 in a brief animation.

anim.dimmer(canvasElement)

Takes a canvas element and reduces the opacity from 100% to 0% in a brief animation.