Created
September 7, 2017 14:20
-
-
Save Martin-Pitt/6b05f2fed36ee1f3dc4c5b8f8407eac7 to your computer and use it in GitHub Desktop.
A very simple but powerful primitive that lets you make awesome UI or 2D/3D movement very quickly
This file contains hidden or 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 rescale(from_min, from_max, to_min, to_max, from) { | |
return to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max))); | |
} | |
rescale.clamped = function(fMin, fMax, tMin, tMax, f) { | |
f = this(fMin, fMax, tMin, tMax, f); | |
if(tMin < tMax) { if(f < tMin) return tMin; else if(f > tMax) return tMax; } | |
else { if(f < tMax) return tMax; else if(f > tMin) return tMin; } | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment