From 5fdd6f2f0148a0a10f90094cae1d4e19940b0e91 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Sun, 17 Apr 2022 01:29:21 -0500 Subject: [PATCH] Added linear easing function. --- src/mapping/easings.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/mapping/easings.js diff --git a/src/mapping/easings.js b/src/mapping/easings.js new file mode 100644 index 0000000..fbde227 --- /dev/null +++ b/src/mapping/easings.js @@ -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); + }; +} \ No newline at end of file