forked from ar2rsawseen/GiderosCodingEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easing.lua
181 lines (179 loc) · 4.35 KB
/
easing.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
--[[
Author of this easing functions for Lua is Josh Tynjala
https://github.com/joshtynjala/gtween.lua
Licensed under the MIT license.
Easing functions adapted from Robert Penner's AS3 tweening equations.
]]
local backS = 1.70158
easing = {};
easing.inBack = function(ratio)
return ratio*ratio*((backS+1)*ratio-backS)
end
easing.outBack = function(ratio)
ratio = ratio - 1
return ratio*ratio*((backS+1)*ratio+backS)+1
end
easing.inOutBack = function(ratio)
ratio = ratio * 2
if ratio < 1 then
return 0.5*(ratio*ratio*((backS*1.525+1)*ratio-backS*1.525))
else
ratio = ratio - 2
return 0.5*(ratio*ratio*((backS*1.525+1)*ratio+backS*1.525)+2)
end
end
easing.inBounce = function(ratio)
return 1-easing.outBounce(1-ratio,0,0,0)
end
easing.outBounce = function(ratio)
if ratio < 1/2.75 then
return 7.5625*ratio*ratio
elseif ratio < 2/2.75 then
ratio = ratio - 1.5/2.75
return 7.5625*ratio*ratio+0.75
elseif ratio < 2.5/2.75 then
ratio= ratio - 2.25/2.75
return 7.5625*ratio*ratio+0.9375
else
ratio = ratio - 2.625/2.75
return 7.5625*ratio*ratio+0.984375
end
end
easing.inOutBounce = function(ratio)
ratio = ratio * 2
if ratio < 1 then
return 0.5*easing.inBounce(ratio,0,0,0)
else
return 0.5*easing.outBounce(ratio-1,0,0,0)+0.5
end
end
easing.inCircular = function(ratio)
return -(math.sqrt(1-ratio*ratio)-1)
end
easing.outCircular = function(ratio)
return math.sqrt(1-(ratio-1)*(ratio-1))
end
easing.inOutCircular = function(ratio)
ratio = ratio * 2
if ratio < 1 then
return -0.5*(math.sqrt(1-ratio*ratio)-1)
else
ratio = ratio - 2
return 0.5*(math.sqrt(1-ratio*ratio)+1)
end
end
easing.inCubic = function(ratio)
return ratio*ratio*ratio
end
easing.outCubic = function(ratio)
ratio = ratio - 1
return ratio*ratio*ratio+1
end
easing.inOutCubic = function(ratio)
if ratio < 0.5 then
return 4*ratio*ratio*ratio
else
ratio = ratio - 1
return 4*ratio*ratio*ratio+1
end
end
local elasticA = 1;
local elasticP = 0.3;
local elasticS = elasticP/4;
easing.inElastic = function(ratio)
if ratio == 0 or ratio == 1 then
return ratio
end
ratio = ratio - 1
return -(elasticA * math.pow(2, 10 * ratio) * math.sin((ratio - elasticS) * (2 * math.pi) / elasticP));
end
easing.outElastic = function(ratio)
if ratio == 0 or ratio == 1 then
return ratio
end
return elasticA * math.pow(2, -10 * ratio) * math.sin((ratio - elasticS) * (2 * math.pi) / elasticP) + 1;
end
easing.inOutElastic = function(ratio)
if ratio == 0 or ratio == 1 then
return ratio
end
ratio = ratio*2-1
if ratio < 0 then
return -0.5 * (elasticA * math.pow(2, 10 * ratio) * math.sin((ratio - elasticS*1.5) * (2 * math.pi) /(elasticP*1.5)));
end
return 0.5 * elasticA * math.pow(2, -10 * ratio) * math.sin((ratio - elasticS*1.5) * (2 * math.pi) / (elasticP*1.5)) + 1;
end
easing.inExponential = function(ratio)
if ratio == 0 then
return 0
end
return math.pow(2, 10 * (ratio - 1))
end
easing.outExponential = function(ratio)
if ratio == 1 then
return 1
end
return 1-math.pow(2, -10 * ratio)
end
easing.inOutExponential = function(ratio)
if ratio == 0 or ratio == 1 then
return ratio
end
ratio = ratio*2-1
if 0 > ratio then
return 0.5*math.pow(2, 10*ratio)
end
return 1-0.5*math.pow(2, -10*ratio)
end
easing.linear = function(ratio)
return ratio
end
easing.inQuadratic = function(ratio)
return ratio*ratio
end
easing.outQuadratic = function(ratio)
return -ratio*(ratio-2)
end
easing.inOutQuadratic = function(ratio)
if ratio < 0.5 then
return 2*ratio*ratio
end
return -2*ratio*(ratio-2)-1
end
easing.inQuartic = function(ratio)
return ratio*ratio*ratio*ratio
end
easing.outQuartic = function(ratio)
ratio = ratio - 1
return 1-ratio*ratio*ratio*ratio
end
easing.inOutQuartic = function(ratio)
if ratio < 0.5 then
return 8*ratio*ratio*ratio*ratio
end
ratio = ratio - 1
return -8*ratio*ratio*ratio*ratio+1
end
easing.inQuintic = function(ratio)
return ratio*ratio*ratio*ratio*ratio
end
easing.outQuintic = function(ratio)
ratio = ratio - 1
return 1+ratio*ratio*ratio*ratio*ratio
end
easing.inOutQuintic = function(ratio)
if ratio < 0.5 then
return 16*ratio*ratio*ratio*ratio*ratio
end
ratio = ratio - 1
return 16*ratio*ratio*ratio*ratio*ratio+1
end
easing.inSine = function(ratio)
return 1-math.cos(ratio * (math.pi / 2))
end
easing.outSine = function(ratio)
return math.sin(ratio * (math.pi / 2))
end
easing.inOutSine = function(ratio)
return -0.5*(math.cos(ratio*math.pi)-1)
end