Skip to content

Instantly share code, notes, and snippets.

@yiwenl
Last active Oct 15, 2019
Embed
What would you like to do?
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