Members
(constant) PAPER :Object.<string, Paper>
Pre-defined paper sizes.
Type:
- Object.<string, Paper>
Methods
decToHex(dec, lengthopt) → {string}
Convert a decimal number into a hexadecimal string.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dec |
number | A decimal number. |
||
length |
number |
<optional> |
8 | The number of digits the string should be padded to. |
Returns:
- The hexadecimal string equivalent of the decimal number.
- Type
- string
fract(x) → {number}
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
The fractional part of x
- Type
- number
Examples
// returns 0.42
fract(1.42)
// returns 0.77
fract(-42.23)
hexToDec(hex) → {number}
Convert a hexadecimal string to a decimal number.
Parameters:
Name | Type | Description |
---|---|---|
hex |
string | A hexacimal string. |
Returns:
- The decimal equivalent of the hex string.
- Type
- number
lerp(a, b, amount)
Linear interpolation between two values
Parameters:
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.
Parameters:
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. |
Returns:
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.
- Source:
- See:
Returns:
- 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
Parameters:
Name | Type | Description |
---|---|---|
n |
number | Number of digits |
Returns:
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)
Type Definitions
PRNGAlgorithm
A PRNGAlgorithm is a class that implements some technique for random number generation. It should have a seed and max value, as well as a next function.
Properties:
Name | Type | Description |
---|---|---|
seed |
number | The initial state of the PRNG. |
max |
number | The maximum possible value of the PRNG. |
next |
function | The next psuedo-random number between 0 and 1. |