Skip to content

Instantly share code, notes, and snippets.

@Carter2307
Forked from demonixis/MathHelper.js
Created April 3, 2022 13:35
Show Gist options
  • Select an option

  • Save Carter2307/c3917e6f0f3fc2d2601112d7ff002fe9 to your computer and use it in GitHub Desktop.

Select an option

Save Carter2307/c3917e6f0f3fc2d2601112d7ff002fe9 to your computer and use it in GitHub Desktop.
JavaScript Math helper
var MathHelper = {
// Get a value between two values
clamp: function (value, min, max) {
if (value < min) {
return min;
}
else if (value > max) {
return max;
}
return value;
},
// Get the linear interpolation between two value
lerp: function (value1, value2, amount) {
amount = amount < 0 ? 0 : amount;
amount = amount > 1 ? 1 : amount;
return value1 + (value2 - value1) * amount;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment