-
Notifications
You must be signed in to change notification settings - Fork 9
/
AsymmetricTransformation.lua
121 lines (101 loc) · 3.47 KB
/
AsymmetricTransformation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
-- Transform function for Paper
-- @author Validark
-- AsymmetricTransformation(GuiObject Button, UDim2 EndSize)
-- @specs https://material.io/guidelines/motion/transforming-material.html#
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
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 ceil = math.ceil
local function AsymmetricTransformation(Button, EndSize)
local StartX = Button.Size.X
local StartY = Button.Size.Y
local EndX = EndSize.X
local EndY = EndSize.Y
local XStartScale = StartX.Scale
local XStartOffset = StartX.Offset
local YStartScale = StartY.Scale
local YStartOffset = StartY.Offset
local XScaleChange = EndX.Scale - XStartScale
local XOffsetChange = EndX.Offset - XStartOffset
local YScaleChange = EndY.Scale - YStartScale
local YOffsetChange = EndY.Offset - YStartOffset
local ElapsedTime, Connection = 0
local Clone = Button:Clone()
Clone.Name = ""
Clone.Size = EndSize
Clone.Visible = false
Clone.Parent = Button.Parent
if Button.AbsoluteSize.X * Button.AbsoluteSize.Y < Clone.AbsoluteSize.X * Clone.AbsoluteSize.Y then
-- Expanding
Clone:Destroy()
local Duration = 0.375
local HeightStart = Duration*0.1
local WidthDuration = Duration*0.75
Connection = Heartbeat: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
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
else
YScale = YStartScale
YOffset = YStartOffset
end
Button.Size = UDim2.new(ceil(XScale), ceil(XOffset), ceil(YScale), ceil(YOffset))
else
Connection:Disconnect()
Button.Size = EndSize
end
end)
else
-- Shrinking
Clone:Destroy()
local Duration = 0.225
local WidthStart = Duration*0.15
local HeightDuration = Duration*0.95
Connection = Heartbeat: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
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
else
XScale = XStartScale
XOffset = XStartOffset
end
Button.Size = UDim2.new(ceil(XScale), ceil(XOffset), ceil(YScale), ceil(YOffset))
else
Connection:Disconnect()
Button.Size = EndSize
--[[if EndSize == UDim2.new() then
Button.Visible = false
end]]
end
end)
end
return Connection
end
return AsymmetricTransformation