A minimal physical spring implementation. Can operate on a scalar number or an array of numbers.
npm install --save sproing
// 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
}
});
scalarSproing.setTarget(2);
vectorSproing.setTarget([0, 1, 4]);
const newScalar = scalarSproing.update();
// x
const newVector = vectorSproing.update();
// [ x, y, z ]
MIT © gpascale