Skip to content

Instantly share code, notes, and snippets.

@gpiffault
Created July 23, 2021 07:05
Show Gist options
  • Save gpiffault/6c49ee8fa622714e3bae91415e7d8e42 to your computer and use it in GitHub Desktop.
Save gpiffault/6c49ee8fa622714e3bae91415e7d8e42 to your computer and use it in GitHub Desktop.
function wrap(min, max, value) {
while (value < min) value += max - min
while (value > max) value -= max - min
return value
}
function clamp(min, max, value) {
return Math.min(Math.max(min, value), max)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment