Methods
decToHex(dec, lengthopt) → {string}
Convert a decimal number into a hexadecimal string.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dec | number | A decimal number. | ||
length | number | <optional> | 8 | The number of digits the string should be padded to. |
- The hexadecimal string equivalent of the decimal number.
- Type:
- string
fract(x) → {number}
Name | Type | Description |
---|---|---|
x | number |
The fractional part of x
- Type:
- number
// returns 0.42
fract(1.42)
// returns 0.77
fract(-42.23)
hexToDec(hex) → {number}
Convert a hexadecimal string to a decimal number.
Name | Type | Description |
---|---|---|
hex | string | A hexacimal string. |
- The decimal equivalent of the hex string.
- Type:
- number
lerp(a, b, amount)
Linear interpolation between two values
Name | Type | Description |
---|---|---|
a | number | |
b | number | |
amount | number |
map(value, min1, max1, min2, max2, withinBoundsopt) → {number}
Re-maps a number from one range to another.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value | number | The number to be re-mapped. | ||
min1 | number | The minimum value of the original range. | ||
max1 | number | The maximum value of the original range. | ||
min2 | number | The minimum value of the target range. | ||
max2 | number | The maximum value of the target range. | ||
withinBounds | boolean | <optional> | false | Whether the remapped value should be constrained within the target range. |
The re-mapped value.
- Type:
- number
sinFract() → {number}
Generates pseudo-random numbers from x
and y
co-ordinates. This technique is adapted from The Art of Code's YouTube video on value noise.
- A floating point number between 0 and 1
- Type:
- number
unseededRandomHex(n) → {string}
Create a random hexadecimal string of a specified length.
Uses Math.random() to make a hexadecimal string for setting the seed of a Plot to be used in a seedable PRNG such as LCG
Name | Type | Description |
---|---|---|
n | number | Number of digits |
- Hexadecimal string of length n
- Type:
- string
wrap()
Constrain an input number to within a specified range, and wrapping it around to min when it exceeds max (and vice versa)