math.js 523 B

123456789101112131415161718192021222324
  1. export const math = (function() {
  2. return {
  3. rand_range: function (a, b) {
  4. return Math.random() * (b - a) + a;
  5. },
  6. rand_normalish: function () {
  7. const r = Math.random() + Math.random() + Math.random() + Math.random();
  8. return (r / 4.0) * 2.0 - 1;
  9. },
  10. lerp: function (x, a, b) {
  11. return x * (b - a) + a;
  12. },
  13. clamp: function (x, a, b) {
  14. return Math.min(Math.max(x, a), b);
  15. },
  16. sat: function (x) {
  17. return Math.min(Math.max(x, 0.0), 1.0);
  18. },
  19. };
  20. })();