Global

Methods

clamp(value, min_valopt, max_valopt) → {number}

Clamps (constrains) a value into an interval
Parameters:
Name Type Attributes Default Description
value number value to be clamped
min_val number <optional>
0 minimum value in the interval
max_val number <optional>
1 maximum value in the interval
Source:
Returns:
Type
number
Example
clamp(-5, -3, 10);
// => -3

dec_to_hex(dec, paddingopt, prefixopt, roundopt) → {string}

Returns the hexadecimal conversion of a decimal number
Parameters:
Name Type Attributes Default Description
dec number the base 10 number
padding number <optional>
0 digits of zero padding in front of the hex number
prefix boolean <optional>
false if true, 0x gets added in front of the hex number
round boolean <optional>
true if true, the number gets rounded before conversion
Source:
Returns:
Type
string
Examples
dec_to_hex(232);
// => "E8"
dec_to_hex(12, 2);
// => "0C"
dec_to_hex(14, 2, true);
// => "0x0E"

dist(x1, y1, x2, y2) → {number}

Returns the distance between two coordinates
Parameters:
Name Type Description
x1 number first coordinate x value
y1 number first coordinate y value
x2 number second coordinate x value
y2 number second coordinate y value
Source:
Returns:
distance between the coordinates
Type
number

dist_sq(x1, y1, x2, y2) → {number}

Returns the square distance between two coordinates
Parameters:
Name Type Description
x1 number first coordinate x value
y1 number first coordinate y value
x2 number second coordinate x value
y2 number second coordinate y value
Source:
Returns:
square distance between the coordinates
Type
number

get_css_var(property) → {string}

Returns the value of a CSS variable used in the current page
Parameters:
Name Type Description
property string CSS property name
Source:
Returns:
CSS property value
Type
string

hex_to_dec(hex) → {number}

Returns the decimal conversion of a hexadecimal number
Parameters:
Name Type Description
hex number the base 16 number
Source:
Returns:
Type
number
Examples
hex_to_dec("E8");
// => 232
hex_to_dec("0xF6");
// => 246
hex_to_dec("64h");
 100

index_from_xy(x, y, width) → {number}

Returns the index corresponding to the (x, y) coordinates of a 2D data structure (a grid) treated as a 1D structure
Parameters:
Name Type Description
x number x coordinate of the point
y number y coordinate of the point
width number width of the data structure
Source:
Returns:
Type
number
Example
index_from_xy(7, 4, 12);
// => 55

is_mobile() → {boolean}

Returns true if the function is called by a mobile browser
Source:
Returns:
Type
boolean

manhattan_dist(x1, y1, x2, y2) → {number}

Returns the manhattan distance between two coordinates
Parameters:
Name Type Description
x1 number
y1 number
x2 number
y2 number
Source:
Returns:
manhattan distance between the coordinates
Type
number

map(value, old_min, old_max, new_min, new_max) → {number}

Maps (rescales) a value from an old interval to a new interval
Parameters:
Name Type Description
value number value in the old interval
old_min number minimum value of the old interval
old_max number maximum value of the old interval
new_min number minimum value of the new interval
new_max number maximum value of the new interval
Source:
Returns:
mapped value
Type
number
Example
map(192, 0, 255, 1024, 2048);
// => 1795.0117647058823

poly_ease_in(x, nopt)

In polynomial easing
Parameters:
Name Type Attributes Default Description
x number in range [0, 1]
n number <optional>
2 degree of the polynomial
Source:
Returns:
x smoothed

poly_ease_inout(x, nopt)

In and out polynomial easing
Parameters:
Name Type Attributes Default Description
x number in range [0, 1]
n number <optional>
2 degree of the polynomial
Source:
Returns:
x smoothed

poly_ease_out(x, nopt)

Out polynomial easing
Parameters:
Name Type Attributes Default Description
x number in range [0, 1]
n number <optional>
2 degree of the polynomial
Source:
Returns:
x smoothed

random(aopt, bopt) → {number}

Returns a random number in range [a, b) (i.e. a included, b excluded) If only one parameter is passed, the random number will be generated in range [0, a) If no parameters are passed, the random number will be generated in range [0, 1)
Parameters:
Name Type Attributes Default Description
a number | null <optional>
null if two parameters are passed, minimum range value; maximum range value otherwise
b number | null <optional>
null maximum range value
Source:
Returns:
random number
Type
number

random_from_array(a) → {*}

Returns a random item from the provided array
Parameters:
Name Type Description
a Array an array
Source:
Returns:
item from input array
Type
*

random_int(aopt, bopt) → {number}

Return a random integer in range [a, b) (i.e. a included, b excluded) If only one parameter is passed, the random number will be generated in range [0, a) If no parameters are passed, the random number will be generated in range [0, 1]
Parameters:
Name Type Attributes Default Description
a number | null <optional>
null if two parameters are passed, minimum range value; maximum range value otherwise
b number | null <optional>
null maximum range value
Source:
Returns:
random number
Type
number

random_interval(averageopt, intervalopt) → {number}

Return a random integer in range (average - interval, average + interval) If only one parameter is passed, the random number will be generated in range (average - 0.5, average + 0.5) If no parameters are passed, the random number will be generated in range [0, 1]
Parameters:
Name Type Attributes Default Description
average number <optional>
0.5 average value of the random numbers
interval number <optional>
0.5 semi interval of the random numbers
Source:
Returns:
random number
Type
number

random_normal(minopt, maxopt, skewopt) → {number}

Return a random number generated with a gaussian distribution
Parameters:
Name Type Attributes Default Description
min number <optional>
0 minimum value of the random numbers
max number <optional>
1 minimum value of the random numbers
skew number <optional>
0 skew of the gaussian function
Source:
Returns:
random number
Type
number

random_string(len) → {string}

Generates a random alphanumeric string of set length
Parameters:
Name Type Description
len number length of the random string
Source:
Returns:
Type
string

shuffle_array(a)

Shuffles the provided array in place (the original array gets shuffled)
Parameters:
Name Type Description
a Array an array
Source:

shuffle_string(string) → {string}

Shuffles and returns a string
Parameters:
Name Type Description
string string the string to be shuffled
Source:
Returns:
Type
string

wrap(value, min_valopt, max_valopt) → {number}

Wraps a value into an interval, like the modulo expression but in both directions of the interval
Parameters:
Name Type Attributes Default Description
value number value to be wrapped
min_val number <optional>
0 minimum value in the interval
max_val number <optional>
1 maximum value in the interval
Source:
Returns:
Type
number
Example
wrap(65, 0, 60);
// => 5

xy_from_index(i, width) → {Object}

Returns the (x, y) coordinates of a 1D data structure treated as a 2D structure (a grid)
Parameters:
Name Type Description
i number index of the item
width number width of the data structure
Source:
Returns:
Type
Object
Example
xy_from_index(25, 10);
// => {x: 5, y: 2}