-
Notifications
You must be signed in to change notification settings - Fork 1
/
Easings.avsi
261 lines (252 loc) · 6.93 KB
/
Easings.avsi
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#:
#: This is a port of the jQuery UI easings, which are licensed under the MIT
#: license. So I guess this is too.
#:
#: The jQuery easings are originally from Robert Panner (http://www.easings.net).
#:
#: Easings all take a value from 0.0-1.0. They then return a value that's
#: generally from 0.0-1.0 (although it may be outside that range). All easings
#: should return 0.0 when given 0.0 and 1.0 when given 1.0 but beyond those
#: restrictions may return anything for values in between.
#:
#: For a live demo of the easings in your browser, see easings.net, or take a
#: look at ``Examples\Easings.avs`` to see these effects.
#: The following easings are defined:
#:
#: * Linear
#: * Quad
#: * Cubic
#: * Quint
#: * Expo
#: * Sine
#: * Circ
#: * Elastic
#: * Back
#: * Bounce
#:
#: Each easing comes with four types:
#:
#: * Easing<NAME>, EaseIn<NAME> (these are identical)
#: * EaseOut<NAME> (the inverse of EaseIn)
#: * EaseInOut<NAME> (does EaseIn for the first half, then EaseOut for the second)
#:
#: So for Linear, the following functions are available:
#:
#: * ``EasingLinear``
#: * ``EaseInLinear``
#: * ``EaseOutLinear``
#: * ``EaseInOutLinear``
#:
#: (Although in the case of linear, they all do the exact same thing!)
#: .. function:: Clamp(v, vMin=0.0, vMax=1.0)
#:
#: :param float v: the value
#: :param float vMin: the minimum allowed value, defaults to 0.0
#: :param float vMax: the maximum allowed value, defaults to 1.0
#: :returns: the given value clamped to the given range
#:
#: Utility to clamp a value into a range. By default this clamps to 0.0-1.0,
#: which can be useful for certain transitions.
#:
#: This is simply ``Min(vMax, Max(vMin, v))`` but reads slightly less weirdly.
function Clamp(float v, float "vMin", float "vMax") {
return Min(Default(vMax, 1.0), Max(Default(vMin, 0.0), v))
}
#: .. function:: Easing(name, value)
#:
#: :param string name: the name of the easing function (one of those listed
#: above: e.g., ``"EaseInSine"`` or ``"EaseInOutBounce"``)
#: :param float value: the value (between 0.0 and 1.0 inclusive) to use
#: :returns: a value representing the current easing value. This may be outside
#: the 0.0-1.0 range for some easings.
#:
#: Utility function for calling an easing function by name.
#: Note that there doesn't appear to be any way to sanitize a string to ensure
#: you haven't put in anything invalid, so this function doesn't bother trying
#: to do that.
#:
function Easing(string f, float p) {
return Eval(f + "(" + String(p) + ")")
}
function EasingLinear(float p) {
return p
}
# There's never any difference in any of the linear variants
function EaseInLinear(float p) {
return p
}
function EaseOutLinear(float p) {
return p
}
function EaseInOutLinear(float p) {
return p
}
# Quad easing
function EasingQuad(float p) {
return Pow(p, 2)
}
function EasingCubic(float p) {
return Pow(p, 3)
}
function EasingQuart(float p) {
return Pow(p, 4)
}
function EasingQuint(float p) {
return Pow(p, 5)
}
function EasingExpo(float p) {
return Pow(p, 6)
}
function EasingSine(float p) {
return 1 - Cos(p * Pi() / 2)
}
function EasingCirc(float p) {
return 1 - Sqrt(1 - p * p)
}
function EasingElastic(float p) {
return p == 0 || p == 1 ? p : \
-Pow( 2, 8 * (p - 1) ) * Sin( ( (p - 1) * 80 - 7.5 ) * Pi() / 15 )
}
function EasingBack(float p) {
return p * p * ( 3 * p - 2 )
}
# Rather than try and port the jQuery version, these are based on Robert
# Penner's version found at
# http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js
function EasingBounce(p) {
# Technically this is timed backwards from the original, so flip it
p = 1 - p
return 1 - ( p < (1/2.75) ? (7.5625*p*p) : \
p < (2/2.75) ? 7.5625*Pow(p - 1.5/2.75, 2) + 0.75 : \
p < (2.5/2.75) ? 7.5625*Pow(p - 2.25/2.75, 2) + 0.9375 : \
7.5625*Pow(p- 2.625/2.75, 2) + 0.984375 )
}
/*
* Node script to create the ease in/ease in/out variants:
[
'Quad', 'Cubic', 'Quart', 'Quint', 'Expo', 'Sine', 'Circ', 'Elastic', 'Back', 'Bounce'
].forEach(function(easing) {
console.log('function EaseIn%s(float p) {', easing);
console.log('\treturn Easing%s(p)', easing);
console.log('}');
console.log('function EaseOut%s(float p) {', easing);
console.log('\treturn 1.0 - Easing%s(1.0 - p)', easing);
console.log('}');
console.log('function EaseInOut%s(float p) {', easing);
console.log('\treturn p < 0.5 ? \\');
console.log('\t\tEasing%s( p * 2 ) / 2 : \\', easing);
console.log('\t\t1 - Easing%s( p * -2 + 2 ) / 2', easing);
console.log('}');
});
*/
# THE FOLLOWING ARE GENERATED BY THE ABOVE SCRIPT:
function EaseInQuad(float p) {
return EasingQuad(p)
}
function EaseOutQuad(float p) {
return 1.0 - EasingQuad(1.0 - p)
}
function EaseInOutQuad(float p) {
return p < 0.5 ? \
EasingQuad( p * 2 ) / 2 : \
1 - EasingQuad( p * -2 + 2 ) / 2
}
function EaseInCubic(float p) {
return EasingCubic(p)
}
function EaseOutCubic(float p) {
return 1.0 - EasingCubic(1.0 - p)
}
function EaseInOutCubic(float p) {
return p < 0.5 ? \
EasingCubic( p * 2 ) / 2 : \
1 - EasingCubic( p * -2 + 2 ) / 2
}
function EaseInQuart(float p) {
return EasingQuart(p)
}
function EaseOutQuart(float p) {
return 1.0 - EasingQuart(1.0 - p)
}
function EaseInOutQuart(float p) {
return p < 0.5 ? \
EasingQuart( p * 2 ) / 2 : \
1 - EasingQuart( p * -2 + 2 ) / 2
}
function EaseInQuint(float p) {
return EasingQuint(p)
}
function EaseOutQuint(float p) {
return 1.0 - EasingQuint(1.0 - p)
}
function EaseInOutQuint(float p) {
return p < 0.5 ? \
EasingQuint( p * 2 ) / 2 : \
1 - EasingQuint( p * -2 + 2 ) / 2
}
function EaseInExpo(float p) {
return EasingExpo(p)
}
function EaseOutExpo(float p) {
return 1.0 - EasingExpo(1.0 - p)
}
function EaseInOutExpo(float p) {
return p < 0.5 ? \
EasingExpo( p * 2 ) / 2 : \
1 - EasingExpo( p * -2 + 2 ) / 2
}
function EaseInSine(float p) {
return EasingSine(p)
}
function EaseOutSine(float p) {
return 1.0 - EasingSine(1.0 - p)
}
function EaseInOutSine(float p) {
return p < 0.5 ? \
EasingSine( p * 2 ) / 2 : \
1 - EasingSine( p * -2 + 2 ) / 2
}
function EaseInCirc(float p) {
return EasingCirc(p)
}
function EaseOutCirc(float p) {
return 1.0 - EasingCirc(1.0 - p)
}
function EaseInOutCirc(float p) {
return p < 0.5 ? \
EasingCirc( p * 2 ) / 2 : \
1 - EasingCirc( p * -2 + 2 ) / 2
}
function EaseInElastic(float p) {
return EasingElastic(p)
}
function EaseOutElastic(float p) {
return 1.0 - EasingElastic(1.0 - p)
}
function EaseInOutElastic(float p) {
return p < 0.5 ? \
EasingElastic( p * 2 ) / 2 : \
1 - EasingElastic( p * -2 + 2 ) / 2
}
function EaseInBack(float p) {
return EasingBack(p)
}
function EaseOutBack(float p) {
return 1.0 - EasingBack(1.0 - p)
}
function EaseInOutBack(float p) {
return p < 0.5 ? \
EasingBack( p * 2 ) / 2 : \
1 - EasingBack( p * -2 + 2 ) / 2
}
function EaseInBounce(float p) {
return EasingBounce(p)
}
function EaseOutBounce(float p) {
return 1.0 - EasingBounce(1.0 - p)
}
function EaseInOutBounce(float p) {
return p < 0.5 ? \
EasingBounce( p * 2 ) / 2 : \
1 - EasingBounce( p * -2 + 2 ) / 2
}