Methods

decToHex(dec, lengthopt) → {string}

Convert a decimal number into a hexadecimal string.

Parameters:
NameTypeAttributesDefaultDescription
decnumber

A decimal number.

lengthnumber<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:
NameTypeDescription
xnumber
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:
NameTypeDescription
hexstring

A hexacimal string.

Returns:
  • The decimal equivalent of the hex string.
Type: 
number

lerp(a, b, amount)

Linear interpolation between two values

Parameters:
NameTypeDescription
anumber
bnumber
amountnumber

map(value, min1, max1, min2, max2, withinBoundsopt) → {number}

Re-maps a number from one range to another.

Parameters:
NameTypeAttributesDefaultDescription
valuenumber

The number to be re-mapped.

min1number

The minimum value of the original range.

max1number

The maximum value of the original range.

min2number

The minimum value of the target range.

max2number

The maximum value of the target range.

withinBoundsboolean<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.

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:
NameTypeDescription
nnumber

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)