source: code/Website/open-flash-chart/caurina/transitions/Equations.as@ 7937

Last change on this file since 7937 was 7849, checked in by dennisw, 15 years ago
File size: 29.4 KB
Line 
1/**
2 * Equations
3 * Main equations for the Tweener class
4 *
5 * @author Zeh Fernando, Nate Chatellier
6 * @version 1.0.2
7 */
8
9/*
10Disclaimer for Robert Penner's Easing Equations license:
11
12TERMS OF USE - EASING EQUATIONS
13
14Open source under the BSD License.
15
16Copyright © 2001 Robert Penner
17All rights reserved.
18
19Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
20
21 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
23 * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28package caurina.transitions {
29
30 public class Equations {
31
32 /**
33 * There's no constructor.
34 * @private
35 */
36 public function Equations () {
37 trace ("Equations is a static class and should not be instantiated.")
38 }
39
40 /**
41 * Registers all the equations to the Tweener class, so they can be found by the direct string parameters.
42 * This method doesn't actually have to be used - equations can always be referenced by their full function
43 * names. But "registering" them make them available as their shorthand string names.
44 */
45 public static function init():void {
46 Tweener.registerTransition("easenone", easeNone);
47 Tweener.registerTransition("linear", easeNone); // mx.transitions.easing.None.easeNone
48
49 Tweener.registerTransition("easeinquad", easeInQuad); // mx.transitions.easing.Regular.easeIn
50 Tweener.registerTransition("easeoutquad", easeOutQuad); // mx.transitions.easing.Regular.easeOut
51 Tweener.registerTransition("easeinoutquad", easeInOutQuad); // mx.transitions.easing.Regular.easeInOut
52 Tweener.registerTransition("easeoutinquad", easeOutInQuad);
53
54 Tweener.registerTransition("easeincubic", easeInCubic);
55 Tweener.registerTransition("easeoutcubic", easeOutCubic);
56 Tweener.registerTransition("easeinoutcubic", easeInOutCubic);
57 Tweener.registerTransition("easeoutincubic", easeOutInCubic);
58
59 Tweener.registerTransition("easeinquart", easeInQuart);
60 Tweener.registerTransition("easeoutquart", easeOutQuart);
61 Tweener.registerTransition("easeinoutquart", easeInOutQuart);
62 Tweener.registerTransition("easeoutinquart", easeOutInQuart);
63
64 Tweener.registerTransition("easeinquint", easeInQuint);
65 Tweener.registerTransition("easeoutquint", easeOutQuint);
66 Tweener.registerTransition("easeinoutquint", easeInOutQuint);
67 Tweener.registerTransition("easeoutinquint", easeOutInQuint);
68
69 Tweener.registerTransition("easeinsine", easeInSine);
70 Tweener.registerTransition("easeoutsine", easeOutSine);
71 Tweener.registerTransition("easeinoutsine", easeInOutSine);
72 Tweener.registerTransition("easeoutinsine", easeOutInSine);
73
74 Tweener.registerTransition("easeincirc", easeInCirc);
75 Tweener.registerTransition("easeoutcirc", easeOutCirc);
76 Tweener.registerTransition("easeinoutcirc", easeInOutCirc);
77 Tweener.registerTransition("easeoutincirc", easeOutInCirc);
78
79 Tweener.registerTransition("easeinexpo", easeInExpo); // mx.transitions.easing.Strong.easeIn
80 Tweener.registerTransition("easeoutexpo", easeOutExpo); // mx.transitions.easing.Strong.easeOut
81 Tweener.registerTransition("easeinoutexpo", easeInOutExpo); // mx.transitions.easing.Strong.easeInOut
82 Tweener.registerTransition("easeoutinexpo", easeOutInExpo);
83
84 Tweener.registerTransition("easeinelastic", easeInElastic); // mx.transitions.easing.Elastic.easeIn
85 Tweener.registerTransition("easeoutelastic", easeOutElastic); // mx.transitions.easing.Elastic.easeOut
86 Tweener.registerTransition("easeinoutelastic", easeInOutElastic); // mx.transitions.easing.Elastic.easeInOut
87 Tweener.registerTransition("easeoutinelastic", easeOutInElastic);
88
89 Tweener.registerTransition("easeinback", easeInBack); // mx.transitions.easing.Back.easeIn
90 Tweener.registerTransition("easeoutback", easeOutBack); // mx.transitions.easing.Back.easeOut
91 Tweener.registerTransition("easeinoutback", easeInOutBack); // mx.transitions.easing.Back.easeInOut
92 Tweener.registerTransition("easeoutinback", easeOutInBack);
93
94 Tweener.registerTransition("easeinbounce", easeInBounce); // mx.transitions.easing.Bounce.easeIn
95 Tweener.registerTransition("easeoutbounce", easeOutBounce); // mx.transitions.easing.Bounce.easeOut
96 Tweener.registerTransition("easeinoutbounce", easeInOutBounce); // mx.transitions.easing.Bounce.easeInOut
97 Tweener.registerTransition("easeoutinbounce", easeOutInBounce);
98 }
99
100 // ==================================================================================================================================
101 // TWEENING EQUATIONS functions -----------------------------------------------------------------------------------------------------
102 // (the original equations are Robert Penner's work as mentioned on the disclaimer)
103
104 /**
105 * Easing equation function for a simple linear tweening, with no easing.
106 *
107 * @param t Current time (in frames or seconds).
108 * @param b Starting value.
109 * @param c Change needed in value.
110 * @param d Expected easing duration (in frames or seconds).
111 * @return The correct value.
112 */
113 public static function easeNone (t:Number, b:Number, c:Number, d:Number):Number {
114 return c*t/d + b;
115 }
116
117 /**
118 * Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
119 *
120 * @param t Current time (in frames or seconds).
121 * @param b Starting value.
122 * @param c Change needed in value.
123 * @param d Expected easing duration (in frames or seconds).
124 * @return The correct value.
125 */
126 public static function easeInQuad (t:Number, b:Number, c:Number, d:Number):Number {
127 return c*(t/=d)*t + b;
128 }
129
130 /**
131 * Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
132 *
133 * @param t Current time (in frames or seconds).
134 * @param b Starting value.
135 * @param c Change needed in value.
136 * @param d Expected easing duration (in frames or seconds).
137 * @return The correct value.
138 */
139 public static function easeOutQuad (t:Number, b:Number, c:Number, d:Number):Number {
140 return -c *(t/=d)*(t-2) + b;
141 }
142
143 /**
144 * Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
145 *
146 * @param t Current time (in frames or seconds).
147 * @param b Starting value.
148 * @param c Change needed in value.
149 * @param d Expected easing duration (in frames or seconds).
150 * @return The correct value.
151 */
152 public static function easeInOutQuad (t:Number, b:Number, c:Number, d:Number):Number {
153 if ((t/=d/2) < 1) return c/2*t*t + b;
154 return -c/2 * ((--t)*(t-2) - 1) + b;
155 }
156
157 /**
158 * Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
159 *
160 * @param t Current time (in frames or seconds).
161 * @param b Starting value.
162 * @param c Change needed in value.
163 * @param d Expected easing duration (in frames or seconds).
164 * @return The correct value.
165 */
166 public static function easeOutInQuad (t:Number, b:Number, c:Number, d:Number):Number {
167 if (t < d/2) return easeOutQuad (t*2, b, c/2, d);
168 return easeInQuad((t*2)-d, b+c/2, c/2, d);
169 }
170
171 /**
172 * Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
173 *
174 * @param t Current time (in frames or seconds).
175 * @param b Starting value.
176 * @param c Change needed in value.
177 * @param d Expected easing duration (in frames or seconds).
178 * @return The correct value.
179 */
180 public static function easeInCubic (t:Number, b:Number, c:Number, d:Number):Number {
181 return c*(t/=d)*t*t + b;
182 }
183
184 /**
185 * Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
186 *
187 * @param t Current time (in frames or seconds).
188 * @param b Starting value.
189 * @param c Change needed in value.
190 * @param d Expected easing duration (in frames or seconds).
191 * @return The correct value.
192 */
193 public static function easeOutCubic (t:Number, b:Number, c:Number, d:Number):Number {
194 return c*((t=t/d-1)*t*t + 1) + b;
195 }
196
197 /**
198 * Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
199 *
200 * @param t Current time (in frames or seconds).
201 * @param b Starting value.
202 * @param c Change needed in value.
203 * @param d Expected easing duration (in frames or seconds).
204 * @return The correct value.
205 */
206 public static function easeInOutCubic (t:Number, b:Number, c:Number, d:Number):Number {
207 if ((t/=d/2) < 1) return c/2*t*t*t + b;
208 return c/2*((t-=2)*t*t + 2) + b;
209 }
210
211 /**
212 * Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
213 *
214 * @param t Current time (in frames or seconds).
215 * @param b Starting value.
216 * @param c Change needed in value.
217 * @param d Expected easing duration (in frames or seconds).
218 * @return The correct value.
219 */
220 public static function easeOutInCubic (t:Number, b:Number, c:Number, d:Number):Number {
221 if (t < d/2) return easeOutCubic (t*2, b, c/2, d);
222 return easeInCubic((t*2)-d, b+c/2, c/2, d);
223 }
224
225 /**
226 * Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
227 *
228 * @param t Current time (in frames or seconds).
229 * @param b Starting value.
230 * @param c Change needed in value.
231 * @param d Expected easing duration (in frames or seconds).
232 * @return The correct value.
233 */
234 public static function easeInQuart (t:Number, b:Number, c:Number, d:Number):Number {
235 return c*(t/=d)*t*t*t + b;
236 }
237
238 /**
239 * Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
240 *
241 * @param t Current time (in frames or seconds).
242 * @param b Starting value.
243 * @param c Change needed in value.
244 * @param d Expected easing duration (in frames or seconds).
245 * @return The correct value.
246 */
247 public static function easeOutQuart (t:Number, b:Number, c:Number, d:Number):Number {
248 return -c * ((t=t/d-1)*t*t*t - 1) + b;
249 }
250
251 /**
252 * Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
253 *
254 * @param t Current time (in frames or seconds).
255 * @param b Starting value.
256 * @param c Change needed in value.
257 * @param d Expected easing duration (in frames or seconds).
258 * @return The correct value.
259 */
260 public static function easeInOutQuart (t:Number, b:Number, c:Number, d:Number):Number {
261 if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
262 return -c/2 * ((t-=2)*t*t*t - 2) + b;
263 }
264
265 /**
266 * Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
267 *
268 * @param t Current time (in frames or seconds).
269 * @param b Starting value.
270 * @param c Change needed in value.
271 * @param d Expected easing duration (in frames or seconds).
272 * @return The correct value.
273 */
274 public static function easeOutInQuart (t:Number, b:Number, c:Number, d:Number):Number {
275 if (t < d/2) return easeOutQuart (t*2, b, c/2, d);
276 return easeInQuart((t*2)-d, b+c/2, c/2, d);
277 }
278
279 /**
280 * Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
281 *
282 * @param t Current time (in frames or seconds).
283 * @param b Starting value.
284 * @param c Change needed in value.
285 * @param d Expected easing duration (in frames or seconds).
286 * @return The correct value.
287 */
288 public static function easeInQuint (t:Number, b:Number, c:Number, d:Number):Number {
289 return c*(t/=d)*t*t*t*t + b;
290 }
291
292 /**
293 * Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
294 *
295 * @param t Current time (in frames or seconds).
296 * @param b Starting value.
297 * @param c Change needed in value.
298 * @param d Expected easing duration (in frames or seconds).
299 * @return The correct value.
300 */
301 public static function easeOutQuint (t:Number, b:Number, c:Number, d:Number):Number {
302 return c*((t=t/d-1)*t*t*t*t + 1) + b;
303 }
304
305 /**
306 * Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
307 *
308 * @param t Current time (in frames or seconds).
309 * @param b Starting value.
310 * @param c Change needed in value.
311 * @param d Expected easing duration (in frames or seconds).
312 * @return The correct value.
313 */
314 public static function easeInOutQuint (t:Number, b:Number, c:Number, d:Number):Number {
315 if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
316 return c/2*((t-=2)*t*t*t*t + 2) + b;
317 }
318
319 /**
320 * Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
321 *
322 * @param t Current time (in frames or seconds).
323 * @param b Starting value.
324 * @param c Change needed in value.
325 * @param d Expected easing duration (in frames or seconds).
326 * @return The correct value.
327 */
328 public static function easeOutInQuint (t:Number, b:Number, c:Number, d:Number):Number {
329 if (t < d/2) return easeOutQuint (t*2, b, c/2, d);
330 return easeInQuint((t*2)-d, b+c/2, c/2, d);
331 }
332
333 /**
334 * Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
335 *
336 * @param t Current time (in frames or seconds).
337 * @param b Starting value.
338 * @param c Change needed in value.
339 * @param d Expected easing duration (in frames or seconds).
340 * @return The correct value.
341 */
342 public static function easeInSine (t:Number, b:Number, c:Number, d:Number):Number {
343 return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
344 }
345
346 /**
347 * Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
348 *
349 * @param t Current time (in frames or seconds).
350 * @param b Starting value.
351 * @param c Change needed in value.
352 * @param d Expected easing duration (in frames or seconds).
353 * @return The correct value.
354 */
355 public static function easeOutSine (t:Number, b:Number, c:Number, d:Number):Number {
356 return c * Math.sin(t/d * (Math.PI/2)) + b;
357 }
358
359 /**
360 * Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
361 *
362 * @param t Current time (in frames or seconds).
363 * @param b Starting value.
364 * @param c Change needed in value.
365 * @param d Expected easing duration (in frames or seconds).
366 * @return The correct value.
367 */
368 public static function easeInOutSine (t:Number, b:Number, c:Number, d:Number):Number {
369 return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
370 }
371
372 /**
373 * Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
374 *
375 * @param t Current time (in frames or seconds).
376 * @param b Starting value.
377 * @param c Change needed in value.
378 * @param d Expected easing duration (in frames or seconds).
379 * @return The correct value.
380 */
381 public static function easeOutInSine (t:Number, b:Number, c:Number, d:Number):Number {
382 if (t < d/2) return easeOutSine (t*2, b, c/2, d);
383 return easeInSine((t*2)-d, b+c/2, c/2, d);
384 }
385
386 /**
387 * Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
388 *
389 * @param t Current time (in frames or seconds).
390 * @param b Starting value.
391 * @param c Change needed in value.
392 * @param d Expected easing duration (in frames or seconds).
393 * @return The correct value.
394 */
395 public static function easeInExpo (t:Number, b:Number, c:Number, d:Number):Number {
396 return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b - c * 0.001;
397 }
398
399 /**
400 * Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
401 *
402 * @param t Current time (in frames or seconds).
403 * @param b Starting value.
404 * @param c Change needed in value.
405 * @param d Expected easing duration (in frames or seconds).
406 * @return The correct value.
407 */
408 public static function easeOutExpo (t:Number, b:Number, c:Number, d:Number):Number {
409 return (t==d) ? b+c : c * 1.001 * (-Math.pow(2, -10 * t/d) + 1) + b;
410 }
411
412 /**
413 * Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
414 *
415 * @param t Current time (in frames or seconds).
416 * @param b Starting value.
417 * @param c Change needed in value.
418 * @param d Expected easing duration (in frames or seconds).
419 * @return The correct value.
420 */
421 public static function easeInOutExpo (t:Number, b:Number, c:Number, d:Number):Number {
422 if (t==0) return b;
423 if (t==d) return b+c;
424 if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b - c * 0.0005;
425 return c/2 * 1.0005 * (-Math.pow(2, -10 * --t) + 2) + b;
426 }
427
428 /**
429 * Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
430 *
431 * @param t Current time (in frames or seconds).
432 * @param b Starting value.
433 * @param c Change needed in value.
434 * @param d Expected easing duration (in frames or seconds).
435 * @return The correct value.
436 */
437 public static function easeOutInExpo (t:Number, b:Number, c:Number, d:Number):Number {
438 if (t < d/2) return easeOutExpo (t*2, b, c/2, d);
439 return easeInExpo((t*2)-d, b+c/2, c/2, d);
440 }
441
442 /**
443 * Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
444 *
445 * @param t Current time (in frames or seconds).
446 * @param b Starting value.
447 * @param c Change needed in value.
448 * @param d Expected easing duration (in frames or seconds).
449 * @return The correct value.
450 */
451 public static function easeInCirc (t:Number, b:Number, c:Number, d:Number):Number {
452 return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
453 }
454
455 /**
456 * Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
457 *
458 * @param t Current time (in frames or seconds).
459 * @param b Starting value.
460 * @param c Change needed in value.
461 * @param d Expected easing duration (in frames or seconds).
462 * @return The correct value.
463 */
464 public static function easeOutCirc (t:Number, b:Number, c:Number, d:Number):Number {
465 return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
466 }
467
468 /**
469 * Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
470 *
471 * @param t Current time (in frames or seconds).
472 * @param b Starting value.
473 * @param c Change needed in value.
474 * @param d Expected easing duration (in frames or seconds).
475 * @return The correct value.
476 */
477 public static function easeInOutCirc (t:Number, b:Number, c:Number, d:Number):Number {
478 if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
479 return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
480 }
481
482 /**
483 * Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
484 *
485 * @param t Current time (in frames or seconds).
486 * @param b Starting value.
487 * @param c Change needed in value.
488 * @param d Expected easing duration (in frames or seconds).
489 * @return The correct value.
490 */
491 public static function easeOutInCirc (t:Number, b:Number, c:Number, d:Number):Number {
492 if (t < d/2) return easeOutCirc (t*2, b, c/2, d);
493 return easeInCirc((t*2)-d, b+c/2, c/2, d);
494 }
495
496 /**
497 * Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
498 *
499 * @param t Current time (in frames or seconds).
500 * @param b Starting value.
501 * @param c Change needed in value.
502 * @param d Expected easing duration (in frames or seconds).
503 * @param a Amplitude.
504 * @param p Period.
505 * @return The correct value.
506 */
507 public static function easeInElastic (t:Number, b:Number, c:Number, d:Number, a:Number = Number.NaN, p:Number = Number.NaN):Number {
508 if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
509 var s:Number;
510 if (!a || a < Math.abs(c)) { a=c; s=p/4; }
511 else s = p/(2*Math.PI) * Math.asin (c/a);
512 return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
513 }
514
515 /**
516 * Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
517 *
518 * @param t Current time (in frames or seconds).
519 * @param b Starting value.
520 * @param c Change needed in value.
521 * @param d Expected easing duration (in frames or seconds).
522 * @param a Amplitude.
523 * @param p Period.
524 * @return The correct value.
525 */
526 public static function easeOutElastic (t:Number, b:Number, c:Number, d:Number, a:Number = Number.NaN, p:Number = Number.NaN):Number {
527 if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
528 var s:Number;
529 if (!a || a < Math.abs(c)) { a=c; s=p/4; }
530 else s = p/(2*Math.PI) * Math.asin (c/a);
531 return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
532 }
533
534 /**
535 * Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
536 *
537 * @param t Current time (in frames or seconds).
538 * @param b Starting value.
539 * @param c Change needed in value.
540 * @param d Expected easing duration (in frames or seconds).
541 * @param a Amplitude.
542 * @param p Period.
543 * @return The correct value.
544 */
545 public static function easeInOutElastic (t:Number, b:Number, c:Number, d:Number, a:Number = Number.NaN, p:Number = Number.NaN):Number {
546 if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
547 var s:Number;
548 if (!a || a < Math.abs(c)) { a=c; s=p/4; }
549 else s = p/(2*Math.PI) * Math.asin (c/a);
550 if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
551 return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
552 }
553
554 /**
555 * Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
556 *
557 * @param t Current time (in frames or seconds).
558 * @param b Starting value.
559 * @param c Change needed in value.
560 * @param d Expected easing duration (in frames or seconds).
561 * @param a Amplitude.
562 * @param p Period.
563 * @return The correct value.
564 */
565 public static function easeOutInElastic (t:Number, b:Number, c:Number, d:Number, a:Number = Number.NaN, p:Number = Number.NaN):Number {
566 if (t < d/2) return easeOutElastic (t*2, b, c/2, d, a, p);
567 return easeInElastic((t*2)-d, b+c/2, c/2, d, a, p);
568 }
569
570 /**
571 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
572 *
573 * @param t Current time (in frames or seconds).
574 * @param b Starting value.
575 * @param c Change needed in value.
576 * @param d Expected easing duration (in frames or seconds).
577 * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
578 * @return The correct value.
579 */
580 public static function easeInBack (t:Number, b:Number, c:Number, d:Number, s:Number = Number.NaN):Number {
581 if (!s) s = 1.70158;
582 return c*(t/=d)*t*((s+1)*t - s) + b;
583 }
584
585 /**
586 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
587 *
588 * @param t Current time (in frames or seconds).
589 * @param b Starting value.
590 * @param c Change needed in value.
591 * @param d Expected easing duration (in frames or seconds).
592 * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
593 * @return The correct value.
594 */
595 public static function easeOutBack (t:Number, b:Number, c:Number, d:Number, s:Number = Number.NaN):Number {
596 if (!s) s = 1.70158;
597 return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
598 }
599
600 /**
601 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
602 *
603 * @param t Current time (in frames or seconds).
604 * @param b Starting value.
605 * @param c Change needed in value.
606 * @param d Expected easing duration (in frames or seconds).
607 * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
608 * @return The correct value.
609 */
610 public static function easeInOutBack (t:Number, b:Number, c:Number, d:Number, s:Number = Number.NaN):Number {
611 if (!s) s = 1.70158;
612 if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
613 return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
614 }
615
616 /**
617 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
618 *
619 * @param t Current time (in frames or seconds).
620 * @param b Starting value.
621 * @param c Change needed in value.
622 * @param d Expected easing duration (in frames or seconds).
623 * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
624 * @return The correct value.
625 */
626 public static function easeOutInBack (t:Number, b:Number, c:Number, d:Number, s:Number = Number.NaN):Number {
627 if (t < d/2) return easeOutBack (t*2, b, c/2, d, s);
628 return easeInBack((t*2)-d, b+c/2, c/2, d, s);
629 }
630
631 /**
632 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
633 *
634 * @param t Current time (in frames or seconds).
635 * @param b Starting value.
636 * @param c Change needed in value.
637 * @param d Expected easing duration (in frames or seconds).
638 * @return The correct value.
639 */
640 public static function easeInBounce (t:Number, b:Number, c:Number, d:Number):Number {
641 return c - easeOutBounce (d-t, 0, c, d) + b;
642 }
643
644 /**
645 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
646 *
647 * @param t Current time (in frames or seconds).
648 * @param b Starting value.
649 * @param c Change needed in value.
650 * @param d Expected easing duration (in frames or seconds).
651 * @return The correct value.
652 */
653 public static function easeOutBounce (t:Number, b:Number, c:Number, d:Number):Number {
654 if ((t/=d) < (1/2.75)) {
655 return c*(7.5625*t*t) + b;
656 } else if (t < (2/2.75)) {
657 return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
658 } else if (t < (2.5/2.75)) {
659 return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
660 } else {
661 return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
662 }
663 }
664
665 /**
666 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
667 *
668 * @param t Current time (in frames or seconds).
669 * @param b Starting value.
670 * @param c Change needed in value.
671 * @param d Expected easing duration (in frames or seconds).
672 * @return The correct value.
673 */
674 public static function easeInOutBounce (t:Number, b:Number, c:Number, d:Number):Number {
675 if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b;
676 else return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
677 }
678
679 /**
680 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
681 *
682 * @param t Current time (in frames or seconds).
683 * @param b Starting value.
684 * @param c Change needed in value.
685 * @param d Expected easing duration (in frames or seconds).
686 * @return The correct value.
687 */
688 public static function easeOutInBounce (t:Number, b:Number, c:Number, d:Number):Number {
689 if (t < d/2) return easeOutBounce (t*2, b, c/2, d);
690 return easeInBounce((t*2)-d, b+c/2, c/2, d);
691 }
692 }
693}
Note: See TracBrowser for help on using the repository browser.