Giter VIP home page Giter VIP logo

eased's Introduction

eased

Yet another library for creating simple animations with easing functions. Things that make it stand out from alternatives is a pure functional API & type safety via flow static type checker.

Library is a direct port of a wonderful [Easing][Easing Elm] library for an exciting Elm programing language (that is worth checking out). It is designed around the idea of: Easing functions interpolate a value over time. Where value can be a value of any type, including numbers, points and colors. In fact you can easily introduce your own value to the mix!

You can find graphical examples of easing functions on easings.net.

import {ease, easeInCubic, easeInOutQuad, float} from "eased"

const second = 1000

const sampleAnimation = currentTime =>
    ease(easeInCubic, float, 0, 10, second, currentTime)

// Transition from blue to red using custom `Easing` function
const customAnimation = currentTime =
    ease(x => x ^ 2.4, color, blue, red, second, currentTime)

// Animate between 0 and 5 with the easeInOutQuad Easing
const animation1 = currentTime =>
  ease(easeInOutQuad, float, 0, 5, second, currentTime)

// Animation with bezier curve
const bezierAnimation = currentTime =>
  ease(bezier(0.65, 0.06, 0.99, 0), float, 0, 5, second, currentTime)

// Create your own Interpolation functions
const vec = (from, to, progress) =>
  add(from, scale(sub(to, from), progress))

// Use your Easing and Interpolation functions
const vec3movement = currentTime =>
  ease(easeInQuad, vec, (vec3 0 0 0),
       (vec3 10 10 10), (3 * second), currentTime)

If you happen to type check your JS code with flow you can take further advantage of this library:

import type {Time, Float, Color, Interpolation} from "eased/type"
import {ease, easeInCubic, easeInOutQuad, float} from "eased"

const second = 1000

type $sampleAnimation = (currentTime:Time) => Float
const sampleAnimation:$sampleAnimation = currentTime =>
    ease(easeInCubic, float, 0, 10, second, currentTime)

// Transition from blue to red using custom `Easing` function
type $customAnimation = (currentTime:Time) => Color
const customAnimation:$customAnimation = currentTime =
    ease(x => x ^ 2.4, color, blue, red, second, currentTime)

// Animate between 0 and 5 with the easeInOutQuad Easing
type $animation1 = (currentTime:Time) => Float
const animation1:$animation1 = currentTime =>
  ease(easeInOutQuad, float, 0, 5, second, currentTime)

// Animation with bezier curve
type $bezierAnimation = (currentTime:Time) => Float
const bezierAnimation:$bezierAnimation = currentTime =>
  ease(bezier(0.65, 0.06, 0.99, 0), float, 0, 5, second, currentTime)

// Create your own Interpolation functions
type $vec = Interpolation<Vec3>
const vec:$vec = (from, to, progress) =>
  add(from, scale(sub(to, from), progress))

// Use your Easing and Interpolation functions
type $vec3movement = (currentTime:Time) => Vec3
const vec3movement = currentTime =>
  ease(easeInQuad, vec, (vec3 0 0 0),
       (vec3 10 10 10), (3 * second), currentTime)

eased's People

Contributors

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