144 lines
4.3 KiB
Lua
144 lines
4.3 KiB
Lua
local self = {}
|
|
|
|
local sqrt = math.sqrt
|
|
local sin = math.sin
|
|
local asin = math.asin
|
|
local cos = math.cos
|
|
local pow = math.pow
|
|
local exp = math.exp
|
|
local pi = math.pi
|
|
local abs = math.abs
|
|
|
|
self = setmetatable(self, {
|
|
__index = function(s, i)
|
|
for _,v in ipairs(self) do
|
|
if v[1] == i then
|
|
return v[2]
|
|
end
|
|
end
|
|
end
|
|
})
|
|
|
|
table.insert(self, {'linear', function(t) return t end})
|
|
table.insert(self, {'instant', function() return 1 end})
|
|
|
|
table.insert(self, {'bounce', function(t) return 4 * t * (1 - t) end})
|
|
table.insert(self, {'tri', function(t) return 1 - abs(2 * t - 1) end})
|
|
table.insert(self, {'bell', function(t) return self.inOutQuint(self.tri(t)) end})
|
|
table.insert(self, {'pop', function(t) return 3.5 * (1 - t) * (1 - t) * sqrt(t) end})
|
|
table.insert(self, {'tap', function(t) return 3.5 * t * t * sqrt(1 - t) end})
|
|
table.insert(self, {'pulse', function(t) return t < .5 and self.tap(t * 2) or -self.pop(t * 2 - 1) end})
|
|
|
|
table.insert(self, {'spike', function(t) return exp(-10 * abs(2 * t - 1)) end})
|
|
table.insert(self, {'inverse', function(t) return t * t * (1 - t) * (1 - t) / (0.5 - t) end})
|
|
|
|
table.insert(self, {'inSine', function(x)
|
|
return 1 - cos(x * (pi * 0.5))
|
|
end})
|
|
|
|
table.insert(self, {'outSine', function(x)
|
|
return sin(x * (pi * 0.5))
|
|
end})
|
|
|
|
table.insert(self, {'inOutSine', function(x)
|
|
return 0.5 - 0.5 * cos(x * pi)
|
|
end})
|
|
|
|
table.insert(self, {'inQuad', function(t) return t * t end})
|
|
table.insert(self, {'outQuad', function(t) return -t * (t - 2) end})
|
|
table.insert(self, {'inOutQuad', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 * t ^ 2
|
|
else
|
|
return 1 - 0.5 * (2 - t) ^ 2
|
|
end
|
|
end})
|
|
table.insert(self, {'inCubic', function(t) return t * t * t end})
|
|
table.insert(self, {'outCubic', function(t) return 1 - (1 - t) ^ 3 end})
|
|
table.insert(self, {'inOutCubic', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 * t ^ 3
|
|
else
|
|
return 1 - 0.5 * (2 - t) ^ 3
|
|
end
|
|
end})
|
|
table.insert(self, {'inQuart', function(t) return t * t * t * t end})
|
|
table.insert(self, {'outQuart', function(t) return 1 - (1 - t) ^ 4 end})
|
|
table.insert(self, {'inOutQuart', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 * t ^ 4
|
|
else
|
|
return 1 - 0.5 * (2 - t) ^ 4
|
|
end
|
|
end})
|
|
table.insert(self, {'inQuint', function(t) return t ^ 5 end})
|
|
table.insert(self, {'outQuint', function(t) return 1 - (1 - t) ^ 5 end})
|
|
table.insert(self, {'inOutQuint', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 * t ^ 5
|
|
else
|
|
return 1 - 0.5 * (2 - t) ^ 5
|
|
end
|
|
end})
|
|
table.insert(self, {'inExpo', function(t) return 1000 ^ (t - 1) - 0.001 end})
|
|
table.insert(self, {'outExpo', function(t) return 1.001 - 1000 ^ -t end})
|
|
table.insert(self, {'inOutExpo', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 * 1000 ^ (t - 1) - 0.0005
|
|
else
|
|
return 1.0005 - 0.5 * 1000 ^ (1 - t)
|
|
end
|
|
end})
|
|
table.insert(self, {'inCirc', function(t) return 1 - sqrt(1 - t * t) end})
|
|
table.insert(self, {'outCirc', function(t) return sqrt(-t * t + 2 * t) end})
|
|
table.insert(self, {'inOutCirc', function(t)
|
|
t = t * 2
|
|
if t < 1 then
|
|
return 0.5 - 0.5 * sqrt(1 - t * t)
|
|
else
|
|
t = t - 2
|
|
return 0.5 + 0.5 * sqrt(1 - t * t)
|
|
end
|
|
end})
|
|
|
|
table.insert(self, {'inBounce', function(t) return 1 - self.outBounce(1 - t) end})
|
|
table.insert(self, {'outBounce', function(t)
|
|
if t < 1 / 2.75 then
|
|
return 7.5625 * t * t
|
|
elseif t < 2 / 2.75 then
|
|
t = t - 1.5 / 2.75
|
|
return 7.5625 * t * t + 0.75
|
|
elseif t < 2.5 / 2.75 then
|
|
t = t - 2.25 / 2.75
|
|
return 7.5625 * t * t + 0.9375
|
|
else
|
|
t = t - 2.625 / 2.75
|
|
return 7.5625 * t * t + 0.984375
|
|
end
|
|
end})
|
|
table.insert(self, {'inOutBounce', function(t)
|
|
if t < 0.5 then
|
|
return self.inBounce(t * 2) * 0.5
|
|
else
|
|
return self.outBounce(t * 2 - 1) * 0.5 + 0.5
|
|
end
|
|
end})
|
|
|
|
table.insert(self, {'inElastic', function(t, a, p)
|
|
return 1 - self.outElastic(1 - t, a, p)
|
|
end, {1, 4, 1, 'a'}, {0, 1, 0.3, 'p'}, overridemin = true})
|
|
table.insert(self, {'outElastic', function(t, a, p)
|
|
return a * pow(2, -10 * t) * sin((t - p / (2 * pi) * asin(1/a)) * 2 * pi / p) + 1
|
|
end, {1, 4, 1, 'a'}, {0, 1, 0.3, 'p'}, overridemin = true})
|
|
table.insert(self, {'inOutElastic', function(t, a, p)
|
|
return t < 0.5
|
|
and 0.5 * self.inElastic(t * 2, a, p)
|
|
or 0.5 + 0.5 * self.outElastic(t * 2 - 1, a, p)
|
|
end, {1, 4, 1, 'a'}, {0, 1, 0.3, 'p'}, overridemin = true})
|
|
|
|
return self
|