summaryrefslogtreecommitdiff
path: root/src/modules/Util.js
blob: 165d1d0876d11d663bc91a7edaa4eda7cbba210b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 };