-
-
Save Carter2307/c3917e6f0f3fc2d2601112d7ff002fe9 to your computer and use it in GitHub Desktop.
JavaScript Math helper
This file contains hidden or 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
| 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