inspired by the Map function in Processing. This module scales a number from one range to another
$ npm install range-map
var rangeMap = require("range-map");
var mapped = rangeMap(50, 0, 100, 0, 1000);
//mapped == 500
var clampMapped = rangeMap(500, 0, 100, 0, 1000, true);
//clampMapped == 1000
mapped(input, inputLowest, inputHighest, outputLowest, outputHighest, [clamped=false])
returns a number that has been rounded with Math.round()
The ranges will also work with negative numbers.
If clamped
is truthy then output value will be clamped to the minimum and maximum output values.