diff options
author | sanine <sanine.not@pm.me> | 2022-05-31 20:52:15 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-05-31 20:52:15 -0500 |
commit | 5efc7885e1c3959aa165be640858ffb3f8a5860b (patch) | |
tree | 6865327d6affd6df2c4f61ed3b9d5ab446e2b23e /src/Util/Util.js | |
parent | 8aa6645f2311de78f74b35f804cc45c7fcf38f57 (diff) |
refactor: remove modules/ folder
Diffstat (limited to 'src/Util/Util.js')
-rw-r--r-- | src/Util/Util.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Util/Util.js b/src/Util/Util.js new file mode 100644 index 0000000..165d1d0 --- /dev/null +++ b/src/Util/Util.js @@ -0,0 +1,20 @@ +function useAverage() { + var avg = 0; + let weight = 0; + const append = value => { + avg = (weight * avg) + value; + weight += 1; + avg = avg/weight; + } + + return [() => avg, append]; +} + +function clamp(value, min, max) { + return Math.min(Math.max(value, min), max); +} + +function lerp(a, b, alpha) { + return ((1-alpha)*a) + (alpha*b); +} +export { useAverage, clamp, lerp }; |