-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasings.jl
179 lines (141 loc) · 4.73 KB
/
easings.jl
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
# The variable x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
# https://easings.net/#easeInSine
function ease_in_sine(x::Float64) :: Float64
return 1 - cos((x * π) / 2)
end
# https://easings.net/#easeOutSine
function ease_out_sine(x::Float64) :: Float64
return sin((x * π) / 2)
end
# https://easings.net/#easeInOutSine
function ease_in_out_sine(x::Float64) :: Float64
return -(cos(π * x) - 1) / 2
end
# https://easings.net/#easeInQuad
function ease_in_quad(x::Float64) :: Float64
return x ^ 2
end
# https://easings.net/#easeOutQuad
function ease_out_quad(x::Float64) :: Float64
return 1 - (1 - x) ^ 2
end
# https://easings.net/#easeInOutQuad
function ease_in_out_quad(x::Float64) :: Float64
return x < 0.5 ? 2 * x ^ 2 : 1 - (-2 * x + 2) ^ 2 / 2
end
# https://easings.net/#easeInCubic
function ease_in_cubic(x::Float64) :: Float64
return x ^ 3
end
# https://easings.net/#easeOutCubic
function ease_out_cubic(x::Float64) :: Float64
return 1 - (1 - x) ^ 3
end
# https://easings.net/#easeInOutCubic
function ease_in_out_cubic(x::Float64) :: Float64
return x < 0.5 ? 4 * x ^ 3 : 1 - (-2 * x + 2) ^ 3 / 2
end
# https://easings.net/#easeInQuart
function ease_in_quart(x::Float64) :: Float64
return x ^ 4
end
# https://easings.net/#easeOutQuart
function ease_out_quart(x::Float64) :: Float64
return 1 - (1 - x) ^ 4
end
# https://easings.net/#easeInOutQuart
function ease_in_out_quart(x::Float64) :: Float64
return x < 0.5 ? 8 * x ^ 4 : 1 - (-2 * x + 2) ^ 4 / 2
end
# https://easings.net/#easeInQuint
function ease_in_quint(x::Float64) :: Float64
return x ^ 5
end
# https://easings.net/#easeOutQuint
function ease_out_quint(x::Float64) :: Float64
return 1 - (1 - x) ^ 5
end
# https://easings.net/#easeInOutQuint
function ease_in_out_quint(x::Float64) :: Float64
return x < 0.5 ? 16 * x ^ 5 : 1 - (-2 * x + 2) ^ 5 / 2
end
# https://easings.net/#easeInExpo
function ease_in_expo(x::Float64) :: Float64
return x == 0 ? 0 : 2 ^ (10 * x - 10)
end
# https://easings.net/#easeOutExpo
function ease_out_expo(x::Float64) :: Float64
return x == 1 ? 1 : 1 - 2 ^ (-10 * x)
end
# https://easings.net/#easeInOutExpo
function ease_in_out_expo(x::Float64) :: Float64
return x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? 2 ^ (20 * x - 10) / 2 : (2 - 2 ^ (-20 * x + 10)) / 2
end
# https://easings.net/#easeInCirc
function ease_in_circ(x::Float64) :: Float64
return 1 - sqrt(1 - x ^ 2)
end
# https://easings.net/#easeOutCirc
function ease_out_circ(x::Float64) :: Float64
return sqrt(1 - (x - 1) ^ 2)
end
# https://easings.net/#easeInOutCirc
function ease_in_out_circ(x::Float64) :: Float64
return x < 0.5 ? (1 - sqrt(1 - (2 * x) ^ 2)) / 2 : (sqrt(1 - (-2 * x + 2) ^ 2) + 1) / 2
end
# https://easings.net/#easeInBack
function ease_in_back(x::Float64) :: Float64
c1 = 1.70158
c3 = c1 + 1
return c3 * x ^ 3 - c1 * x ^ 2
end
################################
# https://easings.net/#easeOutBack
function ease_out_back(x::Float64) :: Float64
c1 = 1.70158
c3 = c1 + 1
return 1 + c3 * (x - 1) ^ 3 + c1 * (x - 1) ^ 2
end
# https://easings.net/#easeInOutBack
function ease_in_out_back(x::Float64) :: Float64
c1 = 1.70158
c2 = c1 * 1.525
return x < 0.5 ? (2 * x) ^ 2 * ((c2 + 1) * 2 * x - c2) / 2 : ((2 * x - 2) ^ 2 * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2
end
# https://easings.net/#easeInElastic
function ease_in_elastic(x::Float64) :: Float64
c4 = (2 * π) / 3
return x == 0 ? 0 : x == 1 ? 1 : -(2 ^ (10 * x - 10) * sin((x * 10 - 0.75) * c4))
end
# https://easings.net/#easeOutElastic
function ease_out_elastic(x::Float64) :: Float64
c4 = (2 * π) / 3
return x == 0 ? 0 : x == 1 ? 1 : 2 ^ (-10 * x) * sin((x * 10 - 0.75) * c4) + 1
end
# https://easings.net/#easeInOutElastic
function ease_in_out_elastic(x::Float64) :: Float64
c5 = (2 * π) / 4.5
return x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? -(2 ^ (20 * x - 10) * sin((20 * x - 11.125) * c5)) / 2 : 2 ^ (-20 * x + 10) * sin((20 * x - 11.125) * c5) / 2 + 1
end
# https://easings.net/#easeInBounce
function ease_in_bounce(x::Float64) :: Float64
return 1 - ease_out_bounce(1 - x)
end
# https://easings.net/#easeOutBounce
function ease_out_bounce(x::Float64) :: Float64
n1 = 7.5625
d1 = 2.75
if x < 1 / d1
return n1 * x ^ 2
elseif x < 2 / d1
return n1 * (x - 1.5 / d1) ^ 2 + 0.75
elseif x < 2.5 / d1
return n1 * (x - 2.25 / d1) ^ 2 + 0.9375
else
return n1 * (x - 2.625 / d1) ^ 2 + 0.984375
end
end
# https://easings.net/#easeInOutBounce
function ease_in_out_bounce(x::Float64) :: Float64
return x < 0.5 ? (1 - ease_out_bounce(1 - 2 * x)) / 2 : (1 + ease_out_bounce(2 * x - 1)) / 2
end