-
-
Save ajmalafif/1e0cc31447511da0cea6f6ce37c6dee1 to your computer and use it in GitHub Desktop.
Framer X - Utils Modulate
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
// Framer X Utils.modulate equivalent | |
function modulate(value, rangeA, rangeB, limit = false) { | |
const [fromLow, fromHigh] = rangeA; | |
const [toLow, toHigh] = rangeB; | |
const result = toLow + ((value - fromLow) / (fromHigh - fromLow)) * (toHigh - toLow); | |
if (limit === true) { | |
if (toLow < toHigh) { | |
if (result < toLow) { | |
return toLow; | |
} | |
if (result > toHigh) { | |
return toHigh; | |
} | |
} | |
else { | |
if (result > toLow) { | |
return toLow; | |
} | |
if (result < toHigh) { | |
return toHigh; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment