Skip to content

Instantly share code, notes, and snippets.

@kevadsett
Last active December 23, 2015 08:39
Show Gist options
  • Save kevadsett/6609165 to your computer and use it in GitHub Desktop.
Save kevadsett/6609165 to your computer and use it in GitHub Desktop.
ValueMapper - normalise and transform - great for converting a number from one range to a different range
var ValueMapper = {
normalise: function(value, low, high) {
var range = high - low;
return (value - low) / range;
},
transform: function(value, inputLow, inputHigh, outputLow, outputHigh) {
var normal = this.normalise(value, inputLow, inputHigh);
return normal * (outputHigh - outputLow) + outputLow;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment