Skip to content

Instantly share code, notes, and snippets.

@yiwenl
Last active October 15, 2019 14:07
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 yiwenl/4bd4dc31bdc31b14ad6e95651ee7437b to your computer and use it in GitHub Desktop.
Save yiwenl/4bd4dc31bdc31b14ad6e95651ee7437b to your computer and use it in GitHub Desktop.
Mapping function
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;
}
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