2020-11-03 02:08:57 +00:00
|
|
|
module.exports = {
|
2022-01-04 03:39:53 +00:00
|
|
|
map:function(input, inputMin, inputMax, outputMin, outputMax) {
|
|
|
|
const newv = (input - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;
|
|
|
|
if (outputMin < outputMax) return this.constrain(newv, outputMin, outputMax);
|
|
|
|
else return this.constrain(newv, outputMax, outputMin);
|
|
|
|
},
|
2020-11-03 02:08:57 +00:00
|
|
|
|
2022-01-04 03:39:53 +00:00
|
|
|
constrain:function(input, low, high) {
|
|
|
|
return Math.max(Math.min(input, high), low);
|
|
|
|
},
|
2020-11-03 02:08:57 +00:00
|
|
|
|
2022-01-04 03:39:53 +00:00
|
|
|
randInt:function(from, to) {
|
|
|
|
return Math.round(this.map(Math.random(), 0, 1, from, to));
|
|
|
|
}
|
2020-11-03 02:08:57 +00:00
|
|
|
}
|