Added linear easing function.

This commit is contained in:
Harrison Deng 2022-04-17 01:29:21 -05:00
parent 0543efccd8
commit 5fdd6f2f01

25
src/mapping/easings.js Normal file
View File

@ -0,0 +1,25 @@
/**
* @callback interpolator
* @param {number} current the current value.
* @param {number} dest the destination value.
* @param {number} frameDelta the time elapsed since the last update.
* @returns {number} the new current value.
*/
// TODO: Add some interpolation functions.
/**
*
* @param {number} rate the number of frequency values to shift by per second.
* @returns {interpolator} the interpolation function with the given rate.
*/
export function createEaseLinear(rate) {
return (current, dest, frameDelta) => {
let direction = 1;
if (dest < current) {
direction = -1;
}
return current + (Math.min(rate * frameDelta, dest) * direction);
};
}