src/cm/media/js/lib/yui/yui_3.0.0b1/build/anim/anim-easing-debug.js
changeset 0 40c8f766c9b8
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 /*
       
     2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
       
     3 Code licensed under the BSD License:
       
     4 http://developer.yahoo.net/yui/license.txt
       
     5 version: 3.0.0b1
       
     6 build: 1163
       
     7 */
       
     8 YUI.add('anim-easing', function(Y) {
       
     9 
       
    10 /*
       
    11 TERMS OF USE - EASING EQUATIONS
       
    12 Open source under the BSD License.
       
    13 Copyright 2001 Robert Penner All rights reserved.
       
    14 
       
    15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
    16 
       
    17  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
       
    18  * 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.
       
    19  * 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.
       
    20 
       
    21 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.
       
    22 */
       
    23 
       
    24 /**
       
    25  * The easing module provides methods for customizing
       
    26  * how an animation behaves during each run.
       
    27  * @class Easing
       
    28  * @module anim
       
    29  * @submodule anim-easing
       
    30  */
       
    31 
       
    32 Y.Easing = {
       
    33 
       
    34     /**
       
    35      * Uniform speed between points.
       
    36      * @for Easing
       
    37      * @method easeNone
       
    38      * @param {Number} t Time value used to compute current value
       
    39      * @param {Number} b Starting value
       
    40      * @param {Number} c Delta between start and end values
       
    41      * @param {Number} d Total length of animation
       
    42      * @return {Number} The computed value for the current animation frame
       
    43      */
       
    44     easeNone: function (t, b, c, d) {
       
    45         return c*t/d + b;
       
    46     },
       
    47     
       
    48     /**
       
    49      * Begins slowly and accelerates towards end. (quadratic)
       
    50      * @method easeIn
       
    51      * @param {Number} t Time value used to compute current value
       
    52      * @param {Number} b Starting value
       
    53      * @param {Number} c Delta between start and end values
       
    54      * @param {Number} d Total length of animation
       
    55      * @return {Number} The computed value for the current animation frame
       
    56      */
       
    57     easeIn: function (t, b, c, d) {
       
    58         return c*(t/=d)*t + b;
       
    59     },
       
    60 
       
    61     /**
       
    62      * Begins quickly and decelerates towards end.  (quadratic)
       
    63      * @method easeOut
       
    64      * @param {Number} t Time value used to compute current value
       
    65      * @param {Number} b Starting value
       
    66      * @param {Number} c Delta between start and end values
       
    67      * @param {Number} d Total length of animation
       
    68      * @return {Number} The computed value for the current animation frame
       
    69      */
       
    70     easeOut: function (t, b, c, d) {
       
    71         return -c *(t/=d)*(t-2) + b;
       
    72     },
       
    73     
       
    74     /**
       
    75      * Begins slowly and decelerates towards end. (quadratic)
       
    76      * @method easeBoth
       
    77      * @param {Number} t Time value used to compute current value
       
    78      * @param {Number} b Starting value
       
    79      * @param {Number} c Delta between start and end values
       
    80      * @param {Number} d Total length of animation
       
    81      * @return {Number} The computed value for the current animation frame
       
    82      */
       
    83     easeBoth: function (t, b, c, d) {
       
    84         if ((t/=d/2) < 1) {
       
    85             return c/2*t*t + b;
       
    86         }
       
    87         
       
    88         return -c/2 * ((--t)*(t-2) - 1) + b;
       
    89     },
       
    90     
       
    91     /**
       
    92      * Begins slowly and accelerates towards end. (quartic)
       
    93      * @method easeInStrong
       
    94      * @param {Number} t Time value used to compute current value
       
    95      * @param {Number} b Starting value
       
    96      * @param {Number} c Delta between start and end values
       
    97      * @param {Number} d Total length of animation
       
    98      * @return {Number} The computed value for the current animation frame
       
    99      */
       
   100     easeInStrong: function (t, b, c, d) {
       
   101         return c*(t/=d)*t*t*t + b;
       
   102     },
       
   103     
       
   104     /**
       
   105      * Begins quickly and decelerates towards end.  (quartic)
       
   106      * @method easeOutStrong
       
   107      * @param {Number} t Time value used to compute current value
       
   108      * @param {Number} b Starting value
       
   109      * @param {Number} c Delta between start and end values
       
   110      * @param {Number} d Total length of animation
       
   111      * @return {Number} The computed value for the current animation frame
       
   112      */
       
   113     easeOutStrong: function (t, b, c, d) {
       
   114         return -c * ((t=t/d-1)*t*t*t - 1) + b;
       
   115     },
       
   116     
       
   117     /**
       
   118      * Begins slowly and decelerates towards end. (quartic)
       
   119      * @method easeBothStrong
       
   120      * @param {Number} t Time value used to compute current value
       
   121      * @param {Number} b Starting value
       
   122      * @param {Number} c Delta between start and end values
       
   123      * @param {Number} d Total length of animation
       
   124      * @return {Number} The computed value for the current animation frame
       
   125      */
       
   126     easeBothStrong: function (t, b, c, d) {
       
   127         if ((t/=d/2) < 1) {
       
   128             return c/2*t*t*t*t + b;
       
   129         }
       
   130         
       
   131         return -c/2 * ((t-=2)*t*t*t - 2) + b;
       
   132     },
       
   133 
       
   134     /**
       
   135      * Snap in elastic effect.
       
   136      * @method elasticIn
       
   137      * @param {Number} t Time value used to compute current value
       
   138      * @param {Number} b Starting value
       
   139      * @param {Number} c Delta between start and end values
       
   140      * @param {Number} d Total length of animation
       
   141      * @param {Number} a Amplitude (optional)
       
   142      * @param {Number} p Period (optional)
       
   143      * @return {Number} The computed value for the current animation frame
       
   144      */
       
   145 
       
   146     elasticIn: function (t, b, c, d, a, p) {
       
   147         var s;
       
   148         if (t === 0) {
       
   149             return b;
       
   150         }
       
   151         if ( (t /= d) === 1 ) {
       
   152             return b+c;
       
   153         }
       
   154         if (!p) {
       
   155             p = d* 0.3;
       
   156         }
       
   157         
       
   158         if (!a || a < Math.abs(c)) {
       
   159             a = c; 
       
   160             s = p/4;
       
   161         }
       
   162         else {
       
   163             s = p/(2*Math.PI) * Math.asin (c/a);
       
   164         }
       
   165         
       
   166         return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
       
   167     },
       
   168 
       
   169     /**
       
   170      * Snap out elastic effect.
       
   171      * @method elasticOut
       
   172      * @param {Number} t Time value used to compute current value
       
   173      * @param {Number} b Starting value
       
   174      * @param {Number} c Delta between start and end values
       
   175      * @param {Number} d Total length of animation
       
   176      * @param {Number} a Amplitude (optional)
       
   177      * @param {Number} p Period (optional)
       
   178      * @return {Number} The computed value for the current animation frame
       
   179      */
       
   180     elasticOut: function (t, b, c, d, a, p) {
       
   181         var s;
       
   182         if (t === 0) {
       
   183             return b;
       
   184         }
       
   185         if ( (t /= d) === 1 ) {
       
   186             return b+c;
       
   187         }
       
   188         if (!p) {
       
   189             p=d * 0.3;
       
   190         }
       
   191         
       
   192         if (!a || a < Math.abs(c)) {
       
   193             a = c;
       
   194             s = p / 4;
       
   195         }
       
   196         else {
       
   197             s = p/(2*Math.PI) * Math.asin (c/a);
       
   198         }
       
   199         
       
   200         return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
       
   201     },
       
   202     
       
   203     /**
       
   204      * Snap both elastic effect.
       
   205      * @method elasticBoth
       
   206      * @param {Number} t Time value used to compute current value
       
   207      * @param {Number} b Starting value
       
   208      * @param {Number} c Delta between start and end values
       
   209      * @param {Number} d Total length of animation
       
   210      * @param {Number} a Amplitude (optional)
       
   211      * @param {Number} p Period (optional)
       
   212      * @return {Number} The computed value for the current animation frame
       
   213      */
       
   214     elasticBoth: function (t, b, c, d, a, p) {
       
   215         var s;
       
   216         if (t === 0) {
       
   217             return b;
       
   218         }
       
   219         
       
   220         if ( (t /= d/2) === 2 ) {
       
   221             return b+c;
       
   222         }
       
   223         
       
   224         if (!p) {
       
   225             p = d*(0.3*1.5);
       
   226         }
       
   227         
       
   228         if ( !a || a < Math.abs(c) ) {
       
   229             a = c; 
       
   230             s = p/4;
       
   231         }
       
   232         else {
       
   233             s = p/(2*Math.PI) * Math.asin (c/a);
       
   234         }
       
   235         
       
   236         if (t < 1) {
       
   237             return -0.5*(a*Math.pow(2,10*(t-=1)) * 
       
   238                     Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
       
   239         }
       
   240         return a*Math.pow(2,-10*(t-=1)) * 
       
   241                 Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
       
   242     },
       
   243 
       
   244 
       
   245     /**
       
   246      * Backtracks slightly, then reverses direction and moves to end.
       
   247      * @method backIn
       
   248      * @param {Number} t Time value used to compute current value
       
   249      * @param {Number} b Starting value
       
   250      * @param {Number} c Delta between start and end values
       
   251      * @param {Number} d Total length of animation
       
   252      * @param {Number} s Overshoot (optional)
       
   253      * @return {Number} The computed value for the current animation frame
       
   254      */
       
   255     backIn: function (t, b, c, d, s) {
       
   256         if (s === undefined) {
       
   257             s = 1.70158;
       
   258         }
       
   259         if (t === d) {
       
   260             t -= 0.001;
       
   261         }
       
   262         return c*(t/=d)*t*((s+1)*t - s) + b;
       
   263     },
       
   264 
       
   265     /**
       
   266      * Overshoots end, then reverses and comes back to end.
       
   267      * @method backOut
       
   268      * @param {Number} t Time value used to compute current value
       
   269      * @param {Number} b Starting value
       
   270      * @param {Number} c Delta between start and end values
       
   271      * @param {Number} d Total length of animation
       
   272      * @param {Number} s Overshoot (optional)
       
   273      * @return {Number} The computed value for the current animation frame
       
   274      */
       
   275     backOut: function (t, b, c, d, s) {
       
   276         if (typeof s === 'undefined') {
       
   277             s = 1.70158;
       
   278         }
       
   279         return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
       
   280     },
       
   281     
       
   282     /**
       
   283      * Backtracks slightly, then reverses direction, overshoots end, 
       
   284      * then reverses and comes back to end.
       
   285      * @method backBoth
       
   286      * @param {Number} t Time value used to compute current value
       
   287      * @param {Number} b Starting value
       
   288      * @param {Number} c Delta between start and end values
       
   289      * @param {Number} d Total length of animation
       
   290      * @param {Number} s Overshoot (optional)
       
   291      * @return {Number} The computed value for the current animation frame
       
   292      */
       
   293     backBoth: function (t, b, c, d, s) {
       
   294         if (typeof s === 'undefined') {
       
   295             s = 1.70158; 
       
   296         }
       
   297         
       
   298         if ((t /= d/2 ) < 1) {
       
   299             return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
       
   300         }
       
   301         return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
       
   302     },
       
   303 
       
   304     /**
       
   305      * Bounce off of start.
       
   306      * @method bounceIn
       
   307      * @param {Number} t Time value used to compute current value
       
   308      * @param {Number} b Starting value
       
   309      * @param {Number} c Delta between start and end values
       
   310      * @param {Number} d Total length of animation
       
   311      * @return {Number} The computed value for the current animation frame
       
   312      */
       
   313     bounceIn: function (t, b, c, d) {
       
   314         return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
       
   315     },
       
   316     
       
   317     /**
       
   318      * Bounces off end.
       
   319      * @method bounceOut
       
   320      * @param {Number} t Time value used to compute current value
       
   321      * @param {Number} b Starting value
       
   322      * @param {Number} c Delta between start and end values
       
   323      * @param {Number} d Total length of animation
       
   324      * @return {Number} The computed value for the current animation frame
       
   325      */
       
   326     bounceOut: function (t, b, c, d) {
       
   327         if ((t/=d) < (1/2.75)) {
       
   328                 return c*(7.5625*t*t) + b;
       
   329         } else if (t < (2/2.75)) {
       
   330                 return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
       
   331         } else if (t < (2.5/2.75)) {
       
   332                 return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
       
   333         }
       
   334         return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
       
   335     },
       
   336     
       
   337     /**
       
   338      * Bounces off start and end.
       
   339      * @method bounceBoth
       
   340      * @param {Number} t Time value used to compute current value
       
   341      * @param {Number} b Starting value
       
   342      * @param {Number} c Delta between start and end values
       
   343      * @param {Number} d Total length of animation
       
   344      * @return {Number} The computed value for the current animation frame
       
   345      */
       
   346     bounceBoth: function (t, b, c, d) {
       
   347         if (t < d/2) {
       
   348             return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
       
   349         }
       
   350         return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
       
   351     }
       
   352 };
       
   353 
       
   354 
       
   355 
       
   356 }, '3.0.0b1' ,{requires:['anim-base']});