Methods
(static) clamp(val, min, max) → {number}
Clamp a value to a range
- Source:
Parameters:
Name | Type | Description |
---|---|---|
val |
number
|
Input value |
min |
number
|
Minimum range value |
max |
number
|
Maximum range value |
Returns:
- Type:
-
number
Clamped value within range
Example
Calc.clamp(3, 10, 150);
// -> 10
Calc.clamp(400, 10, 150);
// -> 150
Calc.clamp(75, 10, 100);
// -> 75
(static) rand(min, max) → {number}
Get a random float within a range. If only one argument is passed, it is used as the max and the min becomes zero.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
min |
number
|
Minimum range value |
max |
number
|
Maximum range value |
Returns:
- Type:
-
number
Random float within the range
Example
// two arguments
Calc.rand(2, 18);
// -> random float between 2 and 18
// single argument
Calc.rand(42.5);
// -> random float between 0 and 42.5