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