GithubHelp home page GithubHelp logo

react-voodoo / tween-axis Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 290 KB

Fast, delta based composition engine

License: MIT License

JavaScript 100.00%
tween vanilla-js reversible animation additive-animation

tween-axis's Introduction

tween-axis

Fast, additive, reversible, delta based, tween composition engine


Npm version

Description

Classic Tween engines can only output absolute values, which quickly results in very complex code when we have to gradually compose values from multiple sources (e.g. when merging multiple animations based on user drag interactions ) .

Tween Axis is a delta-based interpolation engine that solves this problem, it allows:

  • To apply forward and backward multiples tween values on same properties and multiple objects
  • To do additive tweening
  • Pre-generating frames of properties ( CSS, SVG properties, etc... )
  • Get the delta of multiples values basing a timeline position
  • Etc...

You... like it / it saved your day / you stole all the code / you want more?

contributions welcome

BTC : bc1qh43j8jh6dr8v3f675jwqq3nqymtsj8pyq0kh5a
Paypal : PayPal donate button

Really basic example :

import TweenAxis from "tween-axis";

// // Add the easing function if you want them :
// import * as D3Ease from "d3-ease";
// TweenAxis.EasingFunctions = D3Ease;

let axis    = new TweenAxis(
	    [
		    {
			    from    : 0,
			    duration: 100,
			    // easeFn  : "easePolyOut", // any fn of fn id from TweenAxis.EasingFunctions ( https://github.com/d3/d3-ease format )
			    target: "myTargetId",
			    apply : {
				    value: 200
			    }
		    },
		    {
			    from    : 0,
			    duration: 100,
			    // easeFn  : "easePolyIn", // any fn of fn id from TweenAxis.EasingFunctions ( https://github.com/d3/d3-ease format )
			    target: "myTargetId",
			    apply : {
				    value: -100
			    }
		    }
	    ]
    ),
    context = {
	    myTargetId: {
		    value: 0
	    }
    };

// Use the goTo method to set position basing real axis position
console.log(axis.goTo(50, context));
// { myTargetId: { value: 50 } }
console.log(axis.goTo(25, context));
// { myTargetId: { value: 25 } }
console.log(axis.goTo(75, context));
// { myTargetId: { value: 75 } }

// use the (axis).go method to set position using position/(axis total duration) value
console.log(axis.go(.5, context));
//{ myTargetId: { value: 50 } }
console.log(axis.go(.25, context));
//{ myTargetId: { value: 25 } }
console.log(axis.go(.75, context));
//{ myTargetId: { value: 75 } }

How to add custom tasks / lines

See the SVG Path sample here

tween-axis's People

Contributors

n8tz avatar

Stargazers

 avatar  avatar

Watchers

 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.