/sproing

Primary LanguageJavaScript

sproing

A minimal physical spring implementation. Can operate on a scalar number or an array of numbers.

NPM JavaScript Style Guide

Demo

Demo

Install

npm install --save sproing

Usage

Initialization

// A scalar spring with initial value 0, target 1, and default spring params
const scalarSproing = new Sproing(0, 1);

// A scalar spring with cutsomized spring param
const vectorSproing = new Sproing([0, 0, 1], {
  springParams: {
    tension: 40,
    damping: 20,
    mass: 2
  }
});

Change target

scalarSproing.setTarget(2);

vectorSproing.setTarget([0, 1, 4]);

Update step (call in requestAnimationFrame or similar)

const newScalar = scalarSproing.update();
// x

const newVector = vectorSproing.update();
// [ x, y, z ]

License

MIT © gpascale

Demo