Skip to content

Instantly share code, notes, and snippets.

@victornpb
Last active March 28, 2020 06:56
Show Gist options
  • Save victornpb/51b0c17241ea483dee2c3a20d0f710eb to your computer and use it in GitHub Desktop.
Save victornpb/51b0c17241ea483dee2c3a20d0f710eb to your computer and use it in GitHub Desktop.
/**
* Create a function that maps a value to a range
* @param {Number} inMin Input range minimun value
* @param {Number} inMax Input range maximun value
* @param {Number} outMin Output range minimun value
* @param {Number} outMax Output range maximun value
* @return {function} A function that converts a value
*
* @author Victor N. wwww.victorborges.com
* @see https://gist.github.com/victornpb/51b0c17241ea483dee2c3a20d0f710eb/
*/
function createRemap(inMin, inMax, outMin, outMax) {
return function remaper(x) {
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment