GlyEngine 0.0.17
Create games and apps with lua
Loading...
Searching...
No Matches
Math

Functions

local function abs (value)
 std.math.abs
 
local function clamp (value, value_min, value_max)
 std.math.clamp
 
local function clamp2 (value, value_min, value_max)
 std.math.clamp2
 
local function cycle (passed, duration)
 std.math.cycle
 
local function dir (value, alpha)
 std.math.dir
 
local function dis (x1, y1, x2, y2)
 std.math.dis
 
local function dis2 (x1, y1, x2, y2)
 std.math.dis2
 
local function lerp (a, b, alpha)
 std.math.lerp
 
local function map (value, in_min, in_max, out_min, out_max)
 std.math.map
 
local function max (...)
 std.math.max
 
local function min (...)
 std.math.min
 
local function saw (value)
 std.math.saw
 

Detailed Description

Function Documentation

◆ abs()

local function abs ( value )

module

Equation
Parameters
[in]value
Return values
valueas positive number

◆ clamp()

local function clamp ( value ,
value_min ,
value_max  )
Parameters
[in]valueThe value to clamp
[in]value_minThe minimum value that value can be clamped to.
[in]value_maxThe maximum value that value can be clamped to.
Return values
value
if value_min <= value <= value_max
value_min
if value < value_min
value_max
if value > value_max

◆ clamp2()

local function clamp2 ( value ,
value_min ,
value_max  )
Note
similar to std.math.clamp but cyclical.
Equation
Parameters
[in]valueThe value to clamp
[in]value_minThe minimum value that value can be clamped to.
[in]value_maxThe maximum value that value can be clamped to.

◆ cycle()

local function cycle ( passed ,
duration  )

periodic cycle

Equation
Deprecated
simplify, rename, move or even remove cycle
Parameters
[in]passed
[in]duration
Return values
0start of period
0.5middle of period
1end of period
Example
local anim = std.math.cycle(game.millis, 1000) * 5
std.draw.text(x, y + anim, 'hello!')

◆ dir()

local function dir ( value ,
alpha  )

direction

Parameters
[in]value
[in]alphadefault=0
Return values
-1less than alpha
if value < -alpha
1greater than alpha
if value > alpha
0when is in alpha
if abs(alpha) <= aplha
Example
local sprites = {
[-1] = game.spr_player_left,
[1] = game.spr_player_right,
[0] = game.player_sprite
}
game.player_sprite = sprites[std.math.dir(game.player_speed_x)]

◆ dis()

local function dis ( x1 ,
y1 ,
x2 ,
y2  )

euclidean distance

Equation
Parameters
[in]x1The x coordinate of the first point.
[in]y1The y coordinate of the first point.
[in]x2The x coordinate of the second point.
[in]y2The y coordinate of the second point.
Returns
distance between the two points (x1, y1) and (x2, y2).

◆ dis2()

local function dis2 ( x1 ,
y1 ,
x2 ,
y2  )

quadratic distance

Note
this is an optimization of std.math.dist but it cannot be used to calculate collisions.
Equation
Parameters
[in]x1The x coordinate of the first point.
[in]y1The y coordinate of the first point.
[in]x2The x coordinate of the second point.
[in]y2The y coordinate of the second point.
Returns
distance between the two points (x1, y1) and (x2, y2).

◆ lerp()

local function lerp ( a ,
b ,
alpha  )

linear interpolation

Equation
Parameters
[in]aThe starting value
[in]bThe ending value
[in]alphaThe interpolation parameter, typically in the range [0, 1].
Returns
The interpolated value between 'a' and 'b' based on 'alpha'.

◆ map()

local function map ( value ,
in_min ,
in_max ,
out_min ,
out_max  )

re-maps

Equation
Parameters
[in]valueThe value to be mapped from the input range to the output range.
[in]in_minThe minimum value of the input range.
[in]in_maxThe maximum value of the input range.
[in]out_minThe minimum value of the output range.
[in]out_maxThe maximum value of the output range.
Returns
The mapped value in the output range corresponding to 'value' in the input range.

◆ max()

local function max ( ...)

biggest number

Example
local one = std.math.max(0, 1)
local two = std.math.max({0, 1, 2})

◆ min()

local function min ( ...)

smallest number

Example
local one = std.math.max(1, 2, 3)
local two = std.math.max({2, 3, 4})

◆ saw()

local function saw ( value )

sawtooth

Deprecated
simplify, rename, move or even remove saw