Add easing functions normalized to [0, 1] range
This commit is contained in:
parent
5ba653509a
commit
a5c9ca93f6
52
lib/utils/easing.lua
Normal file
52
lib/utils/easing.lua
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
---- Функции смягчения, нормализованные к [0, 1]
|
||||||
|
|
||||||
|
---@alias ease fun(x: number): number
|
||||||
|
|
||||||
|
local easing = {}
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInSine(x)
|
||||||
|
return 1 - math.cos((x * math.pi) / 2);
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeOutSine(x)
|
||||||
|
return math.sin((x * math.pi) / 2);
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInOutSine(x)
|
||||||
|
return -(math.cos(x * math.pi) - 1) / 2;
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInQuad(x)
|
||||||
|
return x * x
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeOutQuad(x)
|
||||||
|
return 1 - (1 - x) * (1 - x)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInOutQuad(x)
|
||||||
|
return x < 0.5 and 2 * x * x or 1 - math.pow(-2 * x + 2, 2) / 2;
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInCubic(x)
|
||||||
|
return x * x * x
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeOutCubic(x)
|
||||||
|
return 1 - math.pow(1 - x, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @type ease
|
||||||
|
function easing.easeInOutCubic(x)
|
||||||
|
return x < 0.5 and 4 * x * x * x or 1 - math.pow(-2 * x + 2, 3) / 2;
|
||||||
|
end
|
||||||
|
|
||||||
|
return easing
|
||||||
Loading…
x
Reference in New Issue
Block a user