-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
27 lines (27 loc) · 824 Bytes
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// # Map (map interval)
// Ease function can be a interpolation function as below
function map ( input, inputMin, inputMax, outputMin, outputMax, clamp, ease ) {
input = ( input - inputMin ) / ( inputMax - inputMin );
if ( ease ) {
input = ease(input);
}
var output = input * ( outputMax - outputMin ) + outputMin;
if ( !!clamp ) {
if ( outputMax < outputMin ) {
if ( output < outputMax ) {
output = outputMax;
}
else if ( output > outputMin ) {
output = outputMin;
}
} else {
if ( output > outputMax ) {
output = outputMax;
}
else if ( output < outputMin ) {
output = outputMin;
}
}
}
return output;
}