Math

Members

# (static, constant) average

Return the average of all values

Example
sum(1, 2, 3); // => 2

# (static, constant) constrain

Constrain a number between two limits.

Example
constrain(999, 0, 50); // => 50
constrain(-999, 0, 50); // => 0

# (static, constant) degreeCircle :Number

Full rotation on degree circle

Type:
  • Number

# (static, constant) distribute

Returns an array of evenly distributed value across a range

Example
distribute(10); // => Number[10] evenly distributed across [0, 1]
distribute(5, 10, 20); // => Number[5] evenly distributed across [10, 20]

# (static, constant) equals

Determine if two number can considered equals accounting for JS precision.

Example
equals(0.1 + 0.2, 0.3); // => true

# (static, constant) lerp

Linear extrapolation computation, useful when doing animation

# (static, constant) map

Return the equivalent of a value from a scale to another

Example
map(5, 0, 10, 100, 200); // => 150

# (static, constant) modulo

Return modulo with the same sign as the divisor (Floored division)

Example
modulo(10, 3); // => 1
modulo(10, -3); // => -2

# (static, constant) phi :Number

Golden ratio number

Type:
  • Number

# (static, constant) radianCircle :Number

Full rotation on radian circle

Type:
  • Number

# (static, constant) random

Return a random number between limits

Example
random(); // => 0.5918807307648482
random(10); // => 4.4856764978326735
random(100, 200); // => 134.57047268453047

# (static, constant) sum

Add up all values passed as argument

Example
sum(1, 2, 3); // => 6

# (static, constant) truncate

Truncate a number to its integer part.

Example
truncate(12.3); // => 12
truncate(-4.9); // => -4