#15 Реализовано втупую и всякие выравнивания с текстами надо добавлять вручную. Зато у нас есть поддержка анимаций и дерева матриц преобразования. Вообще UI - это просто иерархия прямоугольников на экране. Reviewed-on: #18
58 lines
1.0 KiB
Lua
58 lines
1.0 KiB
Lua
---- Функции смягчения, нормализованные к [0, 1]
|
|
|
|
---@alias ease fun(x: number): number
|
|
|
|
local easing = {}
|
|
|
|
--- @type ease
|
|
function easing.linear(x)
|
|
return x
|
|
end
|
|
|
|
--- @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
|