local function J(J,p,w,P,W,B)if J<P/2 then return outElastic(J*2,p,w/2,P,W,B)else return inElastic(J*2-P,p+w/2,w/2,P,W,B)end end local function p(J,p,w,P,W)if not W then W=1.70158 end J=J/P return((w*J)*J)*((W+1)*J-W)+p end local function w(J,p,w,P,W)if not W then W=1.70158 end J=J/P-1 return w*((J*J)*((W+1)*J+W)+1)+p end local function P(J,p,w,P,W)if not W then W=1.70158 end W=W*1.525 J=(J/P)*2 if J<1 then return(w/2)*((J*J)*((W+1)*J-W))+p else J=J-2 return(w/2)*((J*J)*((W+1)*J+W)+2)+p end end local function W(J,P,W,B,T)if J<B/2 then return w(J*2,P,W/2,B,T)else return p(J*2-B,P+W/2,W/2,B,T)end end local function B(J,p,w,P)J=J/P if J<.36363636363636 then return w*((7.5625*J)*J)+p elseif J<.72727272727273 then J=J-.54545454545455 return w*((7.5625*J)*J+.75)+p elseif J<.90909090909091 then J=J-.81818181818182 return w*((7.5625*J)*J+.9375)+p else J=J-.95454545454545 return w*((7.5625*J)*J+.984375)+p end end local function T(J,p,w,P)return(w-B(P-J,0,w,P))+p end local function L(J,p,w,P)if J<P/2 then return T(J*2,0,w,P)*.5+p else return(B(J*2-P,0,w,P)*.5+w*.5)+p end end local function t(J,p,w,P)if J<P/2 then return B(J*2,p,w/2,P)else return T(J*2-P,p+w/2,w/2,P)end end return{linear=linear;inQuad=inQuad,outQuad=outQuad;inOutQuad=inOutQuad;outInQuad=outInQuad,inCubic=inCubic;outCubic=outCubic,inOutCubic=inOutCubic;outInCubic=outInCubic;inQuart=inQuart,outQuart=outQuart;inOutQuart=inOutQuart;outInQuart=outInQuart;inQuint=inQuint,outQuint=outQuint;inOutQuint=inOutQuint,outInQuint=outInQuint;inSine=inSine,outSine=outSine,inOutSine=inOutSine,outInSine=outInSine,inExpo=inExpo,outExpo=outExpo,inOutExpo=inOutExpo,outInExpo=outInExpo,inCirc=inCirc;outCirc=outCirc,inOutCirc=inOutCirc;outInCirc=outInCirc,inElastic=inElastic,outElastic=outElastic,inOutElastic=inOutElastic,outInElastic=J,inBack=p;outBack=w,inOutBack=P,outInBack=W;inBounce=T,outBounce=B,inOutBounce=L,outInBounce=t}
-- a: amplitud
-- p: period
local function outInElastic(t, b, c, d, a, p)
	if t < d / 2 then
		return outElastic(t * 2, b, c / 2, d, a, p)
	else
		return inElastic((t * 2) - d, b + c / 2, c / 2, d, a, p)
	end
end

local function inBack(t, b, c, d, s)
	if not s then
		s = 1.70158
	end
	t = t / d
	return c * t * t * ((s + 1) * t - s) + b
end

local function outBack(t, b, c, d, s)
	if not s then
		s = 1.70158
	end
	t = t / d - 1
	return c * (t * t * ((s + 1) * t + s) + 1) + b
end

local function inOutBack(t, b, c, d, s)
	if not s then
		s = 1.70158
	end
	s = s * 1.525
	t = t / d * 2
	if t < 1 then
		return c / 2 * (t * t * ((s + 1) * t - s)) + b
	else
		t = t - 2
		return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b
	end
end

local function outInBack(t, b, c, d, s)
	if t < d / 2 then
		return outBack(t * 2, b, c / 2, d, s)
	else
		return inBack((t * 2) - d, b + c / 2, c / 2, d, s)
	end
end

local function outBounce(t, b, c, d)
	t = t / d
	if t < 1 / 2.75 then
		return c * (7.5625 * t * t) + b
	elseif t < 2 / 2.75 then
		t = t - (1.5 / 2.75)
		return c * (7.5625 * t * t + 0.75) + b
	elseif t < 2.5 / 2.75 then
		t = t - (2.25 / 2.75)
		return c * (7.5625 * t * t + 0.9375) + b
	else
		t = t - (2.625 / 2.75)
		return c * (7.5625 * t * t + 0.984375) + b
	end
end

local function inBounce(t, b, c, d)
	return c - outBounce(d - t, 0, c, d) + b
end

local function inOutBounce(t, b, c, d)
	if t < d / 2 then
		return inBounce(t * 2, 0, c, d) * 0.5 + b
	else
		return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b
	end
end

local function outInBounce(t, b, c, d)
	if t < d / 2 then
		return outBounce(t * 2, b, c / 2, d)
	else
		return inBounce((t * 2) - d, b + c / 2, c / 2, d)
	end
end

return {
	linear = linear,
	inQuad = inQuad,
	outQuad = outQuad,
	inOutQuad = inOutQuad,
	outInQuad = outInQuad,
	inCubic = inCubic,
	outCubic = outCubic,
	inOutCubic = inOutCubic,
	outInCubic = outInCubic,
	inQuart = inQuart,
	outQuart = outQuart,
	inOutQuart = inOutQuart,
	outInQuart = outInQuart,
	inQuint = inQuint,
	outQuint = outQuint,
	inOutQuint = inOutQuint,
	outInQuint = outInQuint,
	inSine = inSine,
	outSine = outSine,
	inOutSine = inOutSine,
	outInSine = outInSine,
	inExpo = inExpo,
	outExpo = outExpo,
	inOutExpo = inOutExpo,
	outInExpo = outInExpo,
	inCirc = inCirc,
	outCirc = outCirc,
	inOutCirc = inOutCirc,
	outInCirc = outInCirc,
	inElastic = inElastic,
	outElastic = outElastic,
	inOutElastic = inOutElastic,
	outInElastic = outInElastic,
	inBack = inBack,
	outBack = outBack,
	inOutBack = inOutBack,
	outInBack = outInBack,
	inBounce = inBounce,
	outBounce = outBounce,
	inOutBounce = inOutBounce,
	outInBounce = outInBounce,
}
