Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions AsymmetricTransformation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
-- AsymmetricTransformation(GuiObject Button, UDim2 EndSize)
-- @specs https://material.io/guidelines/motion/transforming-material.html#

local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Resources = require(ReplicatedStorage:WaitForChild("Resources"))

local Bezier = Resources:LoadLibrary("Bezier")
local Standard = Bezier.new(0.4, 0.0, 0.2, 1)

local Heartbeat = RunService.Heartbeat
local CurrentCamera = Workspace.CurrentCamera
local RenderStepped = RunService.RenderStepped
local math_ceil = math.ceil

local function AsymmetricTransformation(Button, EndSize)
Button.Size = UDim2_new(0, Button.AbsoluteSize.X, 0, Button.AbsoluteSize.Y)
EndSize = UDim2_new(0, EndSize.X.Scale * CurrentCamera.ViewportSize.X, 0, EndSize.Y.Scale * CurrentCamera.ViewportSize.Y)

local StartX = Button.Size.X
local StartY = Button.Size.Y
local EndX = EndSize.X
Expand Down Expand Up @@ -41,33 +47,33 @@ local function AsymmetricTransformation(Button, EndSize)
-- Expanding
Clone:Destroy()
local Duration = 0.375
local HeightStart = Duration*0.1
local WidthDuration = Duration*0.75
local HeightStart = Duration / 10
local WidthDuration = Duration * 0.75

Connection = Heartbeat:Connect(function(Step)
Connection = RenderStepped:Connect(function(Step)
ElapsedTime = ElapsedTime + Step
if Duration > ElapsedTime then
local XScale, XOffset, YScale, YOffset

if WidthDuration > ElapsedTime then
local WidthAlpha = Standard(ElapsedTime, 0, 1, WidthDuration)
XScale = XStartScale + WidthAlpha*XScaleChange
XOffset = StartX.Offset + WidthAlpha*XOffsetChange
XScale = XStartScale + WidthAlpha * XScaleChange
XOffset = StartX.Offset + WidthAlpha * XOffsetChange
else
XScale = Button.Size.X.Scale
XOffset = Button.Size.X.Offset
end

if ElapsedTime > HeightStart then
local HeightAlpha = Standard(ElapsedTime - HeightStart, 0, 1, Duration)
YScale = YStartScale + HeightAlpha*YScaleChange
YOffset = YStartOffset + HeightAlpha*YOffsetChange
YScale = YStartScale + HeightAlpha * YScaleChange
YOffset = YStartOffset + HeightAlpha * YOffsetChange
else
YScale = YStartScale
YOffset = YStartOffset
end

Button.Size = UDim2.new(math.ceil(XScale), math.ceil(XOffset), math.ceil(YScale), math.ceil(YOffset))
Button.Size = UDim2.new(math_ceil(XScale), math_ceil(XOffset), math_ceil(YScale), math_ceil(YOffset))
else
Connection:Disconnect()
Button.Size = EndSize
Expand All @@ -77,39 +83,36 @@ local function AsymmetricTransformation(Button, EndSize)
-- Shrinking
Clone:Destroy()
local Duration = 0.225
local WidthStart = Duration*0.15
local HeightDuration = Duration*0.95
local WidthStart = Duration * 0.15
local HeightDuration = Duration * 0.95

Connection = Heartbeat:Connect(function(Step)
Connection = RenderStepped:Connect(function(Step)
ElapsedTime = ElapsedTime + Step
if Duration > ElapsedTime then
local XScale, XOffset, YScale, YOffset

if HeightDuration > ElapsedTime then
local HeightAlpha = Standard(ElapsedTime, 0, 1, HeightDuration)
YScale = YStartScale + HeightAlpha*YScaleChange
YOffset = YStartOffset + HeightAlpha*YOffsetChange
YScale = YStartScale + HeightAlpha * YScaleChange
YOffset = YStartOffset + HeightAlpha * YOffsetChange
else
YScale = Button.Size.Y.Scale
YOffset = Button.Size.Y.Offset
end

if ElapsedTime > WidthStart then
local WidthAlpha = Standard(ElapsedTime - WidthStart, 0, 1, Duration)
XScale = XStartScale + WidthAlpha*XScaleChange
XOffset = XStartOffset + WidthAlpha*XOffsetChange
XScale = XStartScale + WidthAlpha * XScaleChange
XOffset = XStartOffset + WidthAlpha * XOffsetChange
else
XScale = XStartScale
XOffset = XStartOffset
end

Button.Size = UDim2.new(math.ceil(XScale), math.ceil(XOffset), math.ceil(YScale), math.ceil(YOffset))
Button.Size = UDim2.new(math_ceil(XScale), math_ceil(XOffset), math_ceil(YScale), math_ceil(YOffset))
else
Connection:Disconnect()
Button.Size = EndSize
--[[if EndSize == UDim2.new() then
Button.Visible = false
end]]
end
end)
end
Expand Down