diff options
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 }; |