diff --git a/README.md b/README.md index 26a8af4..2aec81a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ lume.lerp(100, 200, .5) -- Returns 150 ``` ### 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. ### lume.pingpong(x) diff --git a/lume.lua b/lume.lua index 1d2f3a2..83e6c5d 100644 --- a/lume.lua +++ b/lume.lua @@ -59,7 +59,8 @@ end 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 end @@ -136,7 +137,7 @@ end function lume.map(t, fn) - local rtn = {} + local rtn = {} for k, v in pairs(t) do rtn[k] = fn(v) end return rtn end @@ -170,7 +171,7 @@ end function lume.set(t, retainkeys) 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 end return rtn @@ -253,7 +254,7 @@ function lume.fn(fn, ...) local args = {...} return function(...) local a = lume.merge(lume.clone(args), {...}) - return fn(unpack(a)) + return fn(unpack(a)) end end @@ -363,8 +364,8 @@ end function lume.format(str, vars) if not vars then return str end - local f = function(x) - return tostring(vars[x] or vars[tonumber(x)] or "{" .. x .. "}") + local f = function(x) + return tostring(vars[x] or vars[tonumber(x)] or "{" .. x .. "}") end return (str:gsub("{(.-)}", f)) end @@ -401,7 +402,7 @@ function lume.hotswap(modname) local oldglobal = lume.clone(_G) local updated = {} local function update(old, new) - if updated[old] then return end + if updated[old] then return end updated[old] = true local oldmt, newmt = getmetatable(old), getmetatable(new) if oldmt and newmt then update(oldmt, newmt) end @@ -421,7 +422,7 @@ function lume.hotswap(modname) local newmod = require(modname) if type(oldmod) == "table" then update(oldmod, newmod) end 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]) _G[k] = v end @@ -434,9 +435,9 @@ end function lume.rgba(color) - local a = math_floor((color / 2 ^ 24) % 256) - local r = math_floor((color / 2 ^ 16) % 256) - local g = math_floor((color / 2 ^ 08) % 256) + local a = math_floor((color / 16777216) % 256) + local r = math_floor((color / 65536) % 256) + local g = math_floor((color / 256) % 256) local b = math_floor((color) % 256) return r, g, b, a end @@ -457,4 +458,4 @@ function lume.chain(value) end -return lume +return lume \ No newline at end of file