mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
[added] some randomness helper functions to mathx
This commit is contained in:
parent
7c975e8c4a
commit
d9da4749e2
21
mathx.lua
21
mathx.lua
@ -88,7 +88,26 @@ function mathx.smootherstep(v)
|
||||
return v * v * v * (v * (v * 6 - 15) + 10)
|
||||
end
|
||||
|
||||
--todo: various other easing curves
|
||||
--todo: various other easing curves (bounce etc)
|
||||
|
||||
--randomness helpers
|
||||
|
||||
--(internal; use a provided random generator object, or not)
|
||||
local function _random(_r, ...)
|
||||
if _r then return _r:random(...) end
|
||||
if love then return love.math.random(...) end
|
||||
return math.random(...)
|
||||
end
|
||||
|
||||
--return a random sign
|
||||
function mathx.random_sign(_r)
|
||||
return _random(_r) < 0.5 and -1 or 1
|
||||
end
|
||||
|
||||
--return a random value between two numbers (continuous)
|
||||
function mathx.random_lerp(min, max, _r)
|
||||
return math.lerp(min, max, _random(_r))
|
||||
end
|
||||
|
||||
--nan checking
|
||||
function mathx.isnan(v)
|
||||
|
Loading…
Reference in New Issue
Block a user