math

v0.1.7
randomSeed(seed);

Set a random seed.

Arguments

seedThe seed value

Returns

numberThe random value

See randomSeed in lu5_math.h
random();

Get a random number.

random(max);

Arguments

maxThe maximum of the range
random()      -- random number between 0 and 1
random(3)     -- random number between 0 and 3
random(min, max);

Arguments

minThe minimum of the range
maxThe maximum of the range
random(3, 12) -- random number between 3 and 12
random(arr);

Arguments

arrThe array to randomly select an item from
random({ 'A', 'B', 'C' }) -- random element in table

Returns

numberThe random value

See random in lu5_math.h
round(x);

Round a number to the nearest integer.

Arguments

xThe value to round

Returns

intThe rounded value

See round in lu5_math.h
floor(x);

floor is a function that takes in a number, and returns the greatest integer less or equal to x.

Arguments

xThe value to floor

Returns

intgreatest integer less than or equals to x

See floor in lu5_math.h
ceil(x);

ceil is a function that takes in a number, and returns the smallest integer greater or equal to x.

Arguments

xThe value to floor

Returns

intThe floored value

See ceil in lu5_math.h
min(a, b);

Return the smallest value.
Can also take any number of arguments, or a table.

Arguments

aThe first value
bThe second value

Returns

numberThe smallest value

min(6, 7); -- returns 6

min(6, 7, 4); -- returns 4

min({ 6, 7, 4 }); -- returns 4
See min in lu5_math.h
max(a, b);

Return the largest value.
Can also take any number of arguments, or a table.

Arguments

aThe first value
bThe second value

Returns

numberThe largest value

max(2, 5); -- returns 5

max(2, 5, 7); -- returns 7

max({ 2, 5, 7 }); -- returns 7
See max in lu5_math.h
abs(x);

Returns the absolute value of x.

Arguments

xThe input value

Returns

numberThe absolote value of the input

See abs in lu5_math.h
map(value, start, end, target_start, target_end);

Maps x from an original range to a target range.

Arguments

valueThe value to map
startThe start of the initial range
endThe end of the initial range
target_startThe start of the target range
target_endThe end of the target range

Returns

numberThe mapped value

local mouseX_mapped = map(mouseX, 0, width, 0, 100);
-- mapped mouseX between 0 and 100
See map in lu5_math.h
dist();

Calculates the distance between 2 points in 2D or 3D space.

dist(x1, y1, x2, y2);

Arguments

x1The x coordinate of the first point
y1The y coordinate of the first point
x2The x coordinate of the second point
y2The y coordinate of the second point
local d = dist(0, 0, 3, 4);
print(d) -- 5
dist(x1, y1, z1, x2, y2, z2);

Arguments

x1The x coordinate of the first point
y1The y coordinate of the first point
z1The z coordinate of the first point
x2The x coordinate of the second point
y2The y coordinate of the second point
z2The z coordinate of the second point
local d = dist(0, 0, 0, 2, 3, 6);
print(d) -- 7
dist(v1, v2);

Arguments

v1The first vector
v2The second vector
local a = createVector(-1, -1);
local b = createVector( 2,  3);

local d = dist(a, b);
print(d) -- 5

Returns

numberThe distance between the points

See dist in lu5_math.h
constrain(x, min, max);

Limits x to a minimum and maximum value.

Arguments

xThe input value
minThe minimum value
maxThe maximum value

Returns

numberThe constrained value

See constrain in lu5_math.h
sin(x);

Sine function (Trigonometry).

Arguments

xThe input value

Returns

numberThe output value

See sin in lu5_math.h
cos(x);

Cosine function (Trigonometry).

Arguments

xThe input value

Returns

numberThe output value

See cos in lu5_math.h
tan(x);

Tangent function (Trigonometry).

Arguments

xThe input value

Returns

numberThe output value

See tan in lu5_math.h
PIConstant

No description

See PI in lu5_math.h
TWO_PIConstant

No description

See TWO_PI in lu5_math.h
HALF_PIConstant

No description

See HALF_PI in lu5_math.h
QUARTER_PIConstant

No description

See QUARTER_PI in lu5_math.h