Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A very simple but powerful primitive that lets you make awesome UI or 2D/3D movement very quickly
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
You can’t perform that action at this time.