local e=math.pow local Q=math.sin local L=math.cos local Z=math.pi local C=math.sqrt local d=math.abs local r=math.asin local function q(e,Q,L)if e==nil then e=0 Q=1 L=1 end return e,Q,L end local function I(e,Q,L,Z)Q,L,Z=q(Q,L,Z)return(L*e)/Z+Q end local function o(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C return Z*e(Q,2)+L end local function J(e,Q,L,Z)Q,L,Z=q(Q,L,Z)e=e/Z return(-L*e)*(e-2)+Q end local function g(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=(Q/C)*2 if Q<1 then return(Z/2)*e(Q,2)+L else return(-Z/2)*((Q-1)*(Q-3)-1)+L end end local function t(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return J(e*2,Q,L/2,Z)else return o(e*2-Z,Q+L/2,L/2,Z)end end local function T(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C return Z*e(Q,3)+L end local function f(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C-1 return Z*(e(Q,3)+1)+L end local function W(e,Q,L,Z)Q,L,Z=q(Q,L,Z)e=(e/Z)*2 if e<1 then return(((L/2)*e)*e)*e+Q else e=e-2 return(L/2)*((e*e)*e+2)+Q end end local function x(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return f(e*2,Q,L/2,Z)else return T(e*2-Z,Q+L/2,L/2,Z)end end local function G(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C return Z*e(Q,4)+L end local function c(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C-1 return-Z*(e(Q,4)-1)+L end local function m(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=(Q/C)*2 if Q<1 then return(Z/2)*e(Q,4)+L else Q=Q-2 return(-Z/2)*(e(Q,4)-2)+L end end local function V(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return c(e*2,Q,L/2,Z)else return G(e*2-Z,Q+L/2,L/2,Z)end end local function l(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C return Z*e(Q,5)+L end local function O(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=Q/C-1 return Z*(e(Q,5)+1)+L end local function U(Q,L,Z,C)L,Z,C=q(L,Z,C)Q=(Q/C)*2 if Q<1 then return(Z/2)*e(Q,5)+L else Q=Q-2 return(Z/2)*(e(Q,5)+2)+L end end local function u(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return O(e*2,Q,L/2,Z)else return l(e*2-Z,Q+L/2,L/2,Z)end end local function N(e,Q,C,d)Q,C,d=q(Q,C,d)return(-C*L((e/d)*(Z/2))+C)+Q end local function X(e,L,C,d)L,C,d=q(L,C,d)return C*Q((e/d)*(Z/2))+L end local function S(e,Q,C,d)Q,C,d=q(Q,C,d)return(-C/2)*(L((Z*e)/d)-1)+Q end local function z(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return X(e*2,Q,L/2,Z)else return N(e*2-Z,Q+L/2,L/2,Z)end end local function s(Q,L,Z,C)L,Z,C=q(L,Z,C)if Q==0 then return L else return(Z*e(2,10*(Q/C-1))+L)-Z*.001 end end local function n(Q,L,Z,C)L,Z,C=q(L,Z,C)if Q==C then return L+Z else return(Z*1.001)*(-e(2,(-10*Q)/C)+1)+L end end local function P(Q,L,Z,C)L,Z,C=q(L,Z,C)if Q==0 then return L end if Q==C then return L+Z end Q=(Q/C)*2 if Q<1 then return((Z/2)*e(2,10*(Q-1))+L)-Z*.0005 else Q=Q-1 return((Z/2)*1.0005)*(-e(2,-10*Q)+2)+L end end local function E(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return n(e*2,Q,L/2,Z)else return s(e*2-Z,Q+L/2,L/2,Z)end end local function a(Q,L,Z,d)L,Z,d=q(L,Z,d)Q=Q/d return-Z*(C(1-e(Q,2))-1)+L end local function A(Q,L,Z,d)L,Z,d=q(L,Z,d)Q=Q/d-1 return Z*C(1-e(Q,2))+L end local function K(e,Q,L,Z)Q,L,Z=q(Q,L,Z)e=(e/Z)*2 if e<1 then return(-L/2)*(C(1-e*e)-1)+Q else e=e-2 return(L/2)*(C(1-e*e)+1)+Q end end local function D(e,Q,L,Z)Q,L,Z=q(Q,L,Z)if e<Z/2 then return A(e*2,Q,L/2,Z)else return a(e*2-Z,Q+L/2,L/2,Z)end end local function w(L,C,I,o,J,g)o,J,g=q(o,J,g)if L==0 then return o end L=L/g if L==1 then return o+J end if not I then I=g*.3 end local t if not C or C<d(J)then C=J t=I/4 else t=(I/(2*Z))*r(J/C)end L=L-1 return-((C*e(2,10*L))*Q(((L*g-t)*(2*Z))/I))+o end
-- For all easing functions:
-- t = elapsed time
-- b = begin
-- c = change == ending - beginning
-- d = duration (total time)

local pow = math.pow
local sin = math.sin
local cos = math.cos
local pi = math.pi
local sqrt = math.sqrt
local abs = math.abs
local asin = math.asin

local function default(b, c, d)
	if b == nil then
		b = 0
		c = 1
		d = 1
	end
	return b, c, d
end

local function linear(t, b, c, d)
	b, c, d = default(b, c, d)
	return c * t / d + b
end

local function inQuad(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return c * pow(t, 2) + b
end

local function outQuad(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return -c * t * (t - 2) + b
end

local function inOutQuad(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d * 2
	if t < 1 then
		return c / 2 * pow(t, 2) + b
	else
		return -c / 2 * ((t - 1) * (t - 3) - 1) + b
	end
end

local function outInQuad(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outQuad(t * 2, b, c / 2, d)
	else
		return inQuad((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inCubic(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return c * pow(t, 3) + b
end

local function outCubic(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d - 1
	return c * (pow(t, 3) + 1) + b
end

local function inOutCubic(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d * 2
	if t < 1 then
		return c / 2 * t * t * t + b
	else
		t = t - 2
		return c / 2 * (t * t * t + 2) + b
	end
end

local function outInCubic(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outCubic(t * 2, b, c / 2, d)
	else
		return inCubic((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inQuart(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return c * pow(t, 4) + b
end

local function outQuart(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d - 1
	return -c * (pow(t, 4) - 1) + b
end

local function inOutQuart(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d * 2
	if t < 1 then
		return c / 2 * pow(t, 4) + b
	else
		t = t - 2
		return -c / 2 * (pow(t, 4) - 2) + b
	end
end

local function outInQuart(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outQuart(t * 2, b, c / 2, d)
	else
		return inQuart((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inQuint(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return c * pow(t, 5) + b
end

local function outQuint(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d - 1
	return c * (pow(t, 5) + 1) + b
end

local function inOutQuint(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d * 2
	if t < 1 then
		return c / 2 * pow(t, 5) + b
	else
		t = t - 2
		return c / 2 * (pow(t, 5) + 2) + b
	end
end

local function outInQuint(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outQuint(t * 2, b, c / 2, d)
	else
		return inQuint((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inSine(t, b, c, d)
	b, c, d = default(b, c, d)
	return -c * cos(t / d * (pi / 2)) + c + b
end

local function outSine(t, b, c, d)
	b, c, d = default(b, c, d)
	return c * sin(t / d * (pi / 2)) + b
end

local function inOutSine(t, b, c, d)
	b, c, d = default(b, c, d)
	return -c / 2 * (cos(pi * t / d) - 1) + b
end

local function outInSine(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outSine(t * 2, b, c / 2, d)
	else
		return inSine((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inExpo(t, b, c, d)
	b, c, d = default(b, c, d)
	if t == 0 then
		return b
	else
		return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001
	end
end

local function outExpo(t, b, c, d)
	b, c, d = default(b, c, d)
	if t == d then
		return b + c
	else
		return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b
	end
end

local function inOutExpo(t, b, c, d)
	b, c, d = default(b, c, d)
	if t == 0 then
		return b
	end
	if t == d then
		return b + c
	end
	t = t / d * 2
	if t < 1 then
		return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005
	else
		t = t - 1
		return c / 2 * 1.0005 * (-pow(2, -10 * t) + 2) + b
	end
end

local function outInExpo(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outExpo(t * 2, b, c / 2, d)
	else
		return inExpo((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inCirc(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d
	return (-c * (sqrt(1 - pow(t, 2)) - 1) + b)
end

local function outCirc(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d - 1
	return (c * sqrt(1 - pow(t, 2)) + b)
end

local function inOutCirc(t, b, c, d)
	b, c, d = default(b, c, d)
	t = t / d * 2
	if t < 1 then
		return -c / 2 * (sqrt(1 - t * t) - 1) + b
	else
		t = t - 2
		return c / 2 * (sqrt(1 - t * t) + 1) + b
	end
end

local function outInCirc(t, b, c, d)
	b, c, d = default(b, c, d)
	if t < d / 2 then
		return outCirc(t * 2, b, c / 2, d)
	else
		return inCirc((t * 2) - d, b + c / 2, c / 2, d)
	end
end

local function inElastic(t, a, p, b, c, d)
	b, c, d = default(b, c, d)
	if t == 0 then
		return b
	end

	t = t / d

	if t == 1 then
		return b + c
	end

	if not p then
		p = d * 0.3
	end

	local s

	if not a or a < abs(c) then
		a = c
		s = p / 4
	else
		s = p / (2 * pi) * asin(c / a)
	end

	t = t - 1

	return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
end
