path.js
A library for morphing between SVG paths, written at SamKnows.
Installation
$ npm install --save path-js
Usage
Has a fairly similar API to chroma.js, for some reason.
var path = ; ; // M100,100l100,100
To morph between paths, use path.scale()
:
var pathScale = path;; // M150,100l0,100
It takes a number between 0 and 1. It doesn't yet support .domain()
, although
I'll gladly accept a PR.
Only a subset of paths are supported - they have to have the same number of points, and the command types of each point has to match. For anything more complicated, check out GreenSock's MorphSVG plugin.
Looping mode
If you enable looping mode, the scale loops back to the first specified path, and numbers greater than 1 are accepted.
var pathScale = path; ; // M100,100l100,100; // M150,100l0,100; // M200,100l-100,100; // M150,100l0,100; // M100,100l100,100
path.mix()
If you don't want the complexity that comes with a scale, use path.mix()
instead. It takes three arguments: two paths, and a number between 0 and 1 that
says how much of each should be used.
Be aware that if you use this, you lose the performance gains from using a scale.
path.reverse()
This function simply reverses the points of a line - you get the same line, but backwards.
License
Released under the MIT license.