mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Merge pull request #3 from icrawler/Dev2
Stripped all trailing whitespace, changed ease function, and pre-computed po2
This commit is contained in:
commit
95c3f8960d
@ -38,7 +38,7 @@ lume.lerp(100, 200, .5) -- Returns 150
|
|||||||
```
|
```
|
||||||
|
|
||||||
### lume.smooth(a, b, amount)
|
### lume.smooth(a, b, amount)
|
||||||
Similar to `lume.lerp()` but uses cosine interpolation instead of linear
|
Similar to `lume.lerp()` but uses cubic interpolation instead of linear
|
||||||
interpolation.
|
interpolation.
|
||||||
|
|
||||||
### lume.pingpong(x)
|
### lume.pingpong(x)
|
||||||
|
25
lume.lua
25
lume.lua
@ -59,7 +59,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.smooth(a, b, amount)
|
function lume.smooth(a, b, amount)
|
||||||
local m = (1 - math_cos(lume.clamp(amount, 0, 1) * math_pi)) / 2
|
local t = lume.clamp(amount, 0, 1)
|
||||||
|
local m = t*t*(3-2*t)
|
||||||
return a + (b - a) * m
|
return a + (b - a) * m
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.map(t, fn)
|
function lume.map(t, fn)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for k, v in pairs(t) do rtn[k] = fn(v) end
|
for k, v in pairs(t) do rtn[k] = fn(v) end
|
||||||
return rtn
|
return rtn
|
||||||
end
|
end
|
||||||
@ -170,7 +171,7 @@ end
|
|||||||
|
|
||||||
function lume.set(t, retainkeys)
|
function lume.set(t, retainkeys)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for k, v in pairs(lume.invert(t)) do
|
for k, v in pairs(lume.invert(t)) do
|
||||||
rtn[retainkeys and v or (#rtn + 1)] = k
|
rtn[retainkeys and v or (#rtn + 1)] = k
|
||||||
end
|
end
|
||||||
return rtn
|
return rtn
|
||||||
@ -253,7 +254,7 @@ function lume.fn(fn, ...)
|
|||||||
local args = {...}
|
local args = {...}
|
||||||
return function(...)
|
return function(...)
|
||||||
local a = lume.merge(lume.clone(args), {...})
|
local a = lume.merge(lume.clone(args), {...})
|
||||||
return fn(unpack(a))
|
return fn(unpack(a))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -363,8 +364,8 @@ end
|
|||||||
|
|
||||||
function lume.format(str, vars)
|
function lume.format(str, vars)
|
||||||
if not vars then return str end
|
if not vars then return str end
|
||||||
local f = function(x)
|
local f = function(x)
|
||||||
return tostring(vars[x] or vars[tonumber(x)] or "{" .. x .. "}")
|
return tostring(vars[x] or vars[tonumber(x)] or "{" .. x .. "}")
|
||||||
end
|
end
|
||||||
return (str:gsub("{(.-)}", f))
|
return (str:gsub("{(.-)}", f))
|
||||||
end
|
end
|
||||||
@ -401,7 +402,7 @@ function lume.hotswap(modname)
|
|||||||
local oldglobal = lume.clone(_G)
|
local oldglobal = lume.clone(_G)
|
||||||
local updated = {}
|
local updated = {}
|
||||||
local function update(old, new)
|
local function update(old, new)
|
||||||
if updated[old] then return end
|
if updated[old] then return end
|
||||||
updated[old] = true
|
updated[old] = true
|
||||||
local oldmt, newmt = getmetatable(old), getmetatable(new)
|
local oldmt, newmt = getmetatable(old), getmetatable(new)
|
||||||
if oldmt and newmt then update(oldmt, newmt) end
|
if oldmt and newmt then update(oldmt, newmt) end
|
||||||
@ -421,7 +422,7 @@ function lume.hotswap(modname)
|
|||||||
local newmod = require(modname)
|
local newmod = require(modname)
|
||||||
if type(oldmod) == "table" then update(oldmod, newmod) end
|
if type(oldmod) == "table" then update(oldmod, newmod) end
|
||||||
for k, v in pairs(oldglobal) do
|
for k, v in pairs(oldglobal) do
|
||||||
if v ~= _G[k] and type(v) == "table" then
|
if v ~= _G[k] and type(v) == "table" then
|
||||||
update(v, _G[k])
|
update(v, _G[k])
|
||||||
_G[k] = v
|
_G[k] = v
|
||||||
end
|
end
|
||||||
@ -434,9 +435,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.rgba(color)
|
function lume.rgba(color)
|
||||||
local a = math_floor((color / 2 ^ 24) % 256)
|
local a = math_floor((color / 16777216) % 256)
|
||||||
local r = math_floor((color / 2 ^ 16) % 256)
|
local r = math_floor((color / 65536) % 256)
|
||||||
local g = math_floor((color / 2 ^ 08) % 256)
|
local g = math_floor((color / 256) % 256)
|
||||||
local b = math_floor((color) % 256)
|
local b = math_floor((color) % 256)
|
||||||
return r, g, b, a
|
return r, g, b, a
|
||||||
end
|
end
|
||||||
@ -457,4 +458,4 @@ function lume.chain(value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return lume
|
return lume
|
Loading…
Reference in New Issue
Block a user