Easing Functions Cheat Sheet

Hi guys! in this thread i want to share an easing functions i made. this easing functions can be used to lerp any value you want. pretty useful if you want to make stuff like bezier projectiles that can move smoothly.

all the methods here is taken from this website : Easing Functions Cheat Sheet (easings.net)

i translated it to luau to make it easier to use.

local function lerp(a,b,t)
	return a + (b-a) * t
end
local function linearin(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = x
		table.insert(tab,lerp(a,b,t))
		task.wait()
	end
	return tab
end
--[[ QUADS ]]
local function quadin(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = x * x
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function quadout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 - (1 - x) * (1 - x)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function quadinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 0.5 then
			t = 2 * x * x
		else
			t = 1 - math.pow(-2 * x + 2, 2) / 2
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end

--[[ SINE ]]
local function sinein(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 - math.cos((x * math.pi) / 2)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function sineout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = math.sin((x * math.pi) / 2)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function sineinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = -(math.cos(math.pi * x) - 1) / 2
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end

--[[ QUINT ]]
local function quintin(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = x * x * x * x * x
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function quintout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 - math.pow(1 - x, 5)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function quintinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 0.5 then
			t = 16 * x * x * x * x * x
		else
			t = 1 - math.pow(-2 * x + 2, 5) / 2
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end


--[[ Exponential ]]
local function expoin(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 0 then
			t = 0
		else
			t = math.pow(2, 10 * x - 10)
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function expoout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 1 then
			t = 1
		else
			t = 1 - math.pow(2, -10 * x)
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function expoinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 1 then
			t = 1
		elseif x == 0 then
			t = 0
		elseif x < 0.5 then
			t = math.pow(2, 20 * x - 10) / 2
		else
			t = (2 - math.pow(2, -20 * x + 10)) / 2
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end


--[[ Circle ]]
local function circin(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 - math.sqrt(1 - math.pow(x, 2))
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function circout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = math.sqrt(1 - math.pow(x - 1, 2))
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function circinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 0.5 then
			t = (1 - math.sqrt(1 - math.pow(2 * x, 2))) / 2
		else
			t = (math.sqrt(1 - math.pow(-2 * x + 2, 2)) + 1) / 2
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end

--[[ Back ]]
local function backin(a,b,totalframe)
	local tab = {}
	local c1,c3 = 1.70158,1 + 1.70158
	for i = 1,totalframe do
		x = i/totalframe
		local t = c3 * x * x * x - c1 * x * x
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function backout(a,b,totalframe)
	local tab = {}
	local c1,c3 = 1.70158,1 + 1.70158
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 + c3 * math.pow(x - 1, 3) + c1 * math.pow(x - 1, 2)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function backinout(a,b,totalframe)
	local tab = {}
	local c1,c2 = 1.70158,1.525 * 1.70158
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 0.5 then
			t = (math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
		else
			t = (math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end

--[[ Elastic ]]
local function elasticin(a,b,totalframe)
	local tab = {}
	local c4 = (2 * math.pi) / 3
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 0 then
			t = 0
		elseif x == 1 then
			t = 1
		else
			t = -math.pow(2, 10 * x - 10) * math.sin((x * 10 - 10.75) * c4)
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function elasticout(a,b,totalframe)
	local tab = {}
	local c4 = (2 * math.pi) / 3
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 0 then
			t = 0
		elseif x == 1 then
			t = 1
		else
			t = math.pow(2, -10 * x) * math.sin((x * 10 - 0.75) * c4) + 1
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function elasticinout(a,b,totalframe)
	local tab = {}
	local c5 = (2 * math.pi) / 4.5
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x == 0 then
			t = 0
		elseif x == 1 then
			t = 1
		elseif x < 0.5 then
			t = -(math.pow(2, 20 * x - 10) * math.sin((20 * x - 11.125) * c5)) / 2
		else
			t = (math.pow(2, -20 * x + 10) * math.sin((20 * x - 11.125) * c5)) / 2 + 1
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end

--[[ Bounce ]]
local function outbouncecalc(x)
	local n1,d1 = 7.5625,2.75
	if x < 1 / d1 then
		return n1 * x * x
	elseif x < 2 / d1 then
		local x2 = x - 1.5
		return n1 * (x2 / d1) * x + 0.75
	elseif x < 2.5 / d1 then
		local x2 = x - 2.25
		return n1 * (x2 / d1) * x + 0.9375
	else
		local x2 = x - 2.625
		return n1 * (x2 / d1) * x + 0.984375
	end
end
local function bouncein(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t = 1 - outbouncecalc(1 - x)
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function bounceout(a,b,totalframe)
	local tab = {}
	local n1,d1 = 7.5625,2.75
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 1 / d1 then
			t = n1 * x * x
		elseif x < 2 / d1 then
			local x2 = x - 1.5
			t = n1 * (x2 / d1) * x + 0.75
		elseif x < 2.5 / d1 then
			local x2 = x - 2.25
			t = n1 * (x2 / d1) * x + 0.9375
		else
			local x2 = x - 2.625
			t = n1 * (x2 / d1) * x + 0.984375
		end
		table.insert(tab,lerp(a,b,t))
	end
	return tab
end
local function bounceinout(a,b,totalframe)
	local tab = {}
	for i = 1,totalframe do
		x = i/totalframe
		local t
		if x < 0.5 then
			t = (1 - outbouncecalc(1 - 2 * x)) / 2
		else
			t = (1 + outbouncecalc(2 * x - 1)) / 2
		end
		table.insert(totalframe,t)
	end
	return tab
end
13 Likes

well in some way there isnt a use but in another THIS IS THE BEST RESOURCE EVER! THANKS!

1 Like

This isn’t useful when you know about TweenService:GetValue(), sorry.

5 Likes

??

Sure, the output might be the same, but having a visual of the actual function that processes input is wholly different. Ex: programming custom tween variations and having a legitimate basis to derive from versus a ‘feel’ of how it probably works/emulation of the generic alpha outputs.

1 Like

What? Why create 15-25 functions that all do the same thing over using the one liner TweenService:GetValue()?? The only exception is for customizing certain easing styles like Bounce, Elastic, and Circular.

3 Likes