Last active
October 15, 2019 14:07
-
-
Save yiwenl/4bd4dc31bdc31b14ad6e95651ee7437b to your computer and use it in GitHub Desktop.
Mapping 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
float map(float value, float start, float end, float newStart, float newEnd) { | |
float percent = (value - start) / (end - start); | |
if (percent < 0.0) { | |
percent = 0.0; | |
} | |
if (percent > 1.0) { | |
percent = 1.0; | |
} | |
float newValue = newStart + (newEnd - newStart) * percent; | |
return newValue; | |
} |
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
function map (value, start, end, newStart, newEnd) { | |
var percent = (value - start) / (end - start) | |
if (percent < 0) { | |
percent = 0 | |
} | |
if (percent > 1) { | |
percent = 1 | |
} | |
var newValue = newStart + (newEnd - newStart) * percent | |
return newValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment