@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
12 lines (11 loc) • 535 B
JavaScript
function spring(targetValue, currentValue, currentVelocity, stiffness = 0.1, damping = 0.6, mass = 1, precision = 1 / 1e4) {
const force = (targetValue - currentValue) * stiffness;
const acceleration = force / mass;
const velocity = currentVelocity * damping + acceleration;
const value = Math.abs(targetValue - currentValue) < precision && Math.abs(velocity) < precision ? targetValue : currentValue + velocity;
return [value, value === targetValue ? 0 : velocity];
}
export {
spring
};
//# sourceMappingURL=spring.js.map