Skip to content

Instantly share code, notes, and snippets.

@anabelle2001
Created October 28, 2016 02:25
Show Gist options
  • Save anabelle2001/28e9dc658e2c14f1ab11fa77ecc1ab87 to your computer and use it in GitHub Desktop.
Save anabelle2001/28e9dc658e2c14f1ab11fa77ecc1ab87 to your computer and use it in GitHub Desktop.
// Math normalize - By Beau Vandenburgh (MIT Licensed)
Math.normalize = function(value, min, max) { //converts range from min - max to 0 - 1
* return (value - min) / (max - min)
}
Math.map = function(value, minin, maxin, minout, maxout) { //convers value from range minin,maxin to range minout,maxout
return Math.denormalize(Math.normalize(value, minin, maxin), minout, maxout);
}
Math.denormalize = function(value, start, stop) { //converts range from 0 - 1 to start - stop
return value * (stop - start) + start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment