Skip to content

Instantly share code, notes, and snippets.

@lmarti17
Created September 29, 2021 09:41
Show Gist options
  • Save lmarti17/07653d7953717f187e39f65ad4d12ff0 to your computer and use it in GitHub Desktop.
Save lmarti17/07653d7953717f187e39f65ad4d12ff0 to your computer and use it in GitHub Desktop.
Function to interpolate a value between a min and a max value.
function scaleToRange(
num: number,
in_min: number,
in_max: number,
out_min: number,
out_max: number
) {
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment