Skip to content

Instantly share code, notes, and snippets.

@jordandobson
Forked from assassinave/utils-modulate-framerx.tsx
Last active April 20, 2023 21:00
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 jordandobson/3aff53bd195387539e223c1f5df130b9 to your computer and use it in GitHub Desktop.
Save jordandobson/3aff53bd195387539e223c1f5df130b9 to your computer and use it in GitHub Desktop.
Framer - Utils Modulate
// 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