Last active
September 1, 2015 19:40
-
-
Save chadgh/7be05558c4c07a69f308 to your computer and use it in GitHub Desktop.
Function to create an interpolate 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
def make_interpolation(from_range, to_range): | |
from_min, from_max = from_range | |
to_min, to_max = to_range | |
scale = float(to_max - to_min) / float(from_max - from_min) | |
def interpolate(value): | |
return to_min + (value - from_min) * scale | |
return interpolate | |
change = make_interpolation((0, 100), (0, 200)) | |
print(change(50)) # will print 100.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment