Last active
December 23, 2015 08:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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