Skip to content

Instantly share code, notes, and snippets.

@ronerlih
Forked from xposedbones/map.js
Created May 25, 2021 14:54
Show Gist options
  • Save ronerlih/2035a46ce49a9f1e675124643588db13 to your computer and use it in GitHub Desktop.
Save ronerlih/2035a46ce49a9f1e675124643588db13 to your computer and use it in GitHub Desktop.
Javascript Map range of number to another range
Number.prototype.map = function (in_min, in_max, out_min, out_max) {
return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment