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

keyframe-animator

v1.0.2

Published

Created programmatically with a list of actions, timings, and easings

Downloads

56

Readme

Keyframe Animator

build status stability NPM version Downloads

Create keyframe animations programmatically with a list of actions, timings, and easings.

Live Example

Pentagons keyframe animated

Creating the Animator

var animator = require('keyframe-animator')
var update = animator( sceneGraph, keyframes, runOnce )
update( elapsedMilliseconds )

sceneGraph

The scene graph can be any type of object that represents your scene. The individual properties on this graph are accessed in the scene graph using "key.path[0]" syntax.

keyframes

Keyframes are a list of keyframe objects as defined below.

runOnce (optional)

Set to true if the animation should only run through once.

Keyframe Object

{
	duration:  <float in seconds>,
	easing:    <string|function>,
	actions:  [
		[ "path.in.object", [<start>, <end>] ],
		[ "path.in.object", <value> ],
		[ "path.in.object" ],
	],
	
	// Relative frames
	subframes: [ keyframe, keyframe, ... ],
	
	//Debug parameters:
	isolate:   <true|false>,
	startHere: <true|false>,
},

duration

The length in seconds of the keyframe.

easing (optional)

Either the easing function name or a custom function. See the available functions in the eases package.

isolate (optional)

A flag on whether or to only play this keyframe. Useful for debugging and live-reloading.

startHere (optional)

Ignores all of the keyframes before this one. Useful for debugging and live-reloading.

actions

An array of actions to perform. Each action is composed of a keypath into the main scene graph object, and the values of the action. The keypath can include dot separated values like "key.path.position.x" and array values like "key.path.position[0]". The value at the keypath can either be a value or a function. If it's a value then the actions will be applied like scene.key.path = value. If the keypath points to a function then it will invoked with the value like scene.key.path(value).

[ 'key.path', [valueStart, valueEnd] ]

If the action value is an array, then the start and end values will be run through an easing function based on the elapsed time. So for instance if the action was equal to ['key.path', [0, 10]], then the scene.key.path would be eased between 0 and 10 based on the elapsed time.

[ 'key.path', value ]

If the action is a single value or undefined, then for the first frame that the keyframe is in range, the property will be set to that value, or the function will be invoked with that value.

Example usage

var animator = require('animator')
var drawScene = require('./draw-scene')

var scene = {
	square : new Square()
}

var keyframes = [
	{
		duration : 2,
		easing : "elastic-in",
		actions : {
			[ "square.position.x", [ 0, 100 ] ],
			[ "square.position.y", [ 0, 100 ] ],
			[ "square.opacity", [ 0, 1 ] ],
		},
	},
	{
		duration : 2,
		easing : "elastic-out",
		actions : {
			[ "square.color[0]", [ 0, 1 ] ],
			[ "square.color[1]", [ 1, 0 ] ],
			[ "square.addStroke" ],
			[ "square.setTextContents", "I'm trapped in a box!" ],
		},
	}
]

var update = animator( sceneGraph, keyframes, runOnce )

var start = Date.now()
function loop() {
	update( Date.now() - start )
	requestAnimationFrame(loop)
}
loop()