0.1.3 • Published 4 years ago

funcurve v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Funcurve

🚀🚀Using bezier curve to build animation easily.

Build Status

Usage

Install

npm i funcurve

or

yarn add funcurve

Demo

import funcurve from 'funcurve';

const fc = funcurve({
  controlPoints: [
    { x: 100, y: 200 },
    { x: 400, y: 500 },
  ],
  onUpdate({ point }) {
    console.log(point.x, point.y);
  },
  onEnd({ point, finished }) {
    console.log(point.x, point.y, finished);
  },
}).start();

If you want't stop current running process, call stop(), after that onEnd callback will be fired with finished being false.

fc.stop();

A funcuve instance can call start serveral times. Before next process start, previous process will be stopped and call onEnd callback immediately.

fc.start();

setTimeout(() => {
  fc.start();
}, 500);

API

funcurve

funcurve(config: FuncurveConfig):IFuncurve returns a funcure instance.

config

keytypedescription
controlPointsPoint[]bezier control point array.
durationnumberthe duration(ms) of process, default value is 1000
onUpdateUpdateInfothe callback of each animation frame
onEndUpdateInfo&{finished:boolean}the callback of the end of process
export interface Point {
  x: number;
  y: number;
}

interface UpdateInfo {
  point: Point;
  progress: number;
}

export interface FuncurveConfig {
  controlPoints: Point[];
  duration?: number;
  onUpdate?(res: UpdateInfo): void;
  onEnd?(res: UpdateInfo & { finished?: boolean }): void;
}

UpdateInfo

keytypedescription
pointPointcurrent point of curve.
progressnumbercurrent progress. 0 - 1
finishedbooleanonEnd callback has an extra finished prop to indicate whether the process has finished.

IFuncurve

start()

Stop previous process and Start a new process.

stop()

Stop current process.

Principle

See Realize bezier curve

License

MIT

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago