Skip to content

Instantly share code, notes, and snippets.

@kunukn
Created March 31, 2019 11:26
Show Gist options
  • Select an option

  • Save kunukn/c350c9c7950f7a56271db2f9695b76f8 to your computer and use it in GitHub Desktop.

Select an option

Save kunukn/c350c9c7950f7a56271db2f9695b76f8 to your computer and use it in GitHub Desktop.
rangeMap
// map value x in range [a,b] to [c,d]
function rangeMap(x, a, b, c, d) {
if (a === b) return c;
if (c === d) return c;
return (x - a) / (b - a) * (d - c) + c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment