Giter VIP home page Giter VIP logo

easing-coordinates's Introduction

Easing Coordinates

NPM Version NPM Monthly Downloads Build Status Code Coverage Dependency status
MIT License Code Style: Prettier Follow Larsenwork on Twitter

Utility to turn steps and cubic-bezier single-transition-timing-functions into an array of "low-poly" xy-coordinates.

Usage

import { easingCoordinates } from 'easing-coordinates'

easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1)')
/* =>
[
  { x: 0, y: 0 },
  { x: 0.136, y: 0.028 },
  { x: 0.248, y: 0.104 },
  { x: 0.342, y: 0.216 },
  { x: 0.424, y: 0.352 },
  { x: 0.5, y: 0.5 },
  { x: 0.576, y: 0.648 },
  { x: 0.658, y: 0.784 },
  { x: 0.752, y: 0.896 },
  { x: 0.864, y: 0.972 },
  { x: 1, y: 1 },
]
*/

easingCoordinates('steps(4)')
/* =>
[
  { x: 0, y: 0 },
  { x: 0.25, y: 0 },
  { x: 0.25, y: 0.25 },
  { x: 0.5, y: 0.25 },
  { x: 0.5, y: 0.5 },
  { x: 0.75, y: 0.5 },
  { x: 0.75, y: 0.75 },
  { x: 1, y: 0.75 },
]
*/

Use stepsCoordinates and cubicCoordinates methods directly depending on your data:

import { cubicCoordinates, easingCoordinates, stepsCoordinates } from 'easing-coordinates'

cubicCoordinates(0.42, 0, 1, 1) === easingCoordinates('cubic-bezier(0.42, 0, 1, 1)')
stepsCoordinates(4, 'skip-end') === easingCoordinates('steps(4, skip-end)')

Increase polySteps (default = 10, min = 2) to get a "higer-poly" version of your cubic-bezier functions.

interface ICoordinate {
  x: number
  y: number
}

function easingCoordinates(easingFunction: string, polySteps?: number): ICoordinate[]

function stepsCoordinates(steps: number, skip = 'skip-end'): ICoordinate[]

function cubicCoordinates(
  x1: number,
  y1: number,
  x2: number,
  y2: number,
  polySteps = 10
): ICoordinate[]

Build

(See package.json for more scripts)

# Checkout and then
npm install

# Compile and watch the .ts files
npm run watch

# Run test
npm run test

easing-coordinates's People

Contributors

larsenwork avatar

Stargazers

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