Skip to content

Instantly share code, notes, and snippets.

@DrummerHead
Created June 8, 2013 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrummerHead/5734149 to your computer and use it in GitHub Desktop.
Save DrummerHead/5734149 to your computer and use it in GitHub Desktop.
Ruby implementation of Processing's map function
# Ruby implementation of Processing's map function
# http://processing.org/reference/map_.html
def map(value, v_min, v_max, d_min, d_max) # v for value, d for desired
v_value = value.to_f # so it returns float
v_range = v_max - v_min
d_range = d_max - d_min
d_value = (v_value - v_min) * d_range / v_range + d_min
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment