Skip to content

Instantly share code, notes, and snippets.

@jkosoy
Created May 23, 2012 18:34
Show Gist options
  • Save jkosoy/2776908 to your computer and use it in GitHub Desktop.
Save jkosoy/2776908 to your computer and use it in GitHub Desktop.
Port of Processing's map() function to JS. See: http://processing.org/reference/map_.html
function map(val, a1, a2, b1, b2) { return ((val - a1) * (b2 -b1)/(a2 - a1)) + b1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment