Created
June 8, 2013 05:13
-
-
Save DrummerHead/5734149 to your computer and use it in GitHub Desktop.
Ruby implementation of Processing's map function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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