NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / anim-easing / anim-easing-debug.js
blob5023f60154d7dca6e75ff3c4280e28cc5fdb4d30
1 /*
2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('anim-easing', function (Y, NAME) {
11 TERMS OF USE - EASING EQUATIONS
12 Open source under the BSD License.
13 Copyright 2001 Robert Penner All rights reserved.
15 Redistribution and use in source and binary forms, with or without modification,
16 are permitted provided that the following conditions are met:
18  * Redistributions of source code must retain the above copyright notice, this
19     list of conditions and the following disclaimer.
20  * Redistributions in binary form must reproduce the above copyright notice,
21     this list of conditions and the following disclaimer in the documentation
22     and/or other materials provided with the distribution.
23  * Neither the name of the author nor the names of contributors may be used to
24     endorse or promote products derived from this software without specific prior
25     written permission.
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 OF THE POSSIBILITY OF SUCH DAMAGE.
39 /**
40  * The easing module provides methods for customizing
41  * how an animation behaves during each run.
42  * @class Easing
43  * @module anim
44  * @submodule anim-easing
45  */
47 var Easing = {
49     /**
50      * Uniform speed between points.
51      * @for Easing
52      * @method easeNone
53      * @param {Number} t Time value used to compute current value
54      * @param {Number} b Starting value
55      * @param {Number} c Delta between start and end values
56      * @param {Number} d Total length of animation
57      * @return {Number} The computed value for the current animation frame
58      */
59     easeNone: function (t, b, c, d) {
60         return c*t/d + b;
61     },
63     /**
64      * Begins slowly and accelerates towards end. (quadratic)
65      * @method easeIn
66      * @param {Number} t Time value used to compute current value
67      * @param {Number} b Starting value
68      * @param {Number} c Delta between start and end values
69      * @param {Number} d Total length of animation
70      * @return {Number} The computed value for the current animation frame
71      */
72     easeIn: function (t, b, c, d) {
73         return c*(t/=d)*t + b;
74     },
76     /**
77      * Begins quickly and decelerates towards end.  (quadratic)
78      * @method easeOut
79      * @param {Number} t Time value used to compute current value
80      * @param {Number} b Starting value
81      * @param {Number} c Delta between start and end values
82      * @param {Number} d Total length of animation
83      * @return {Number} The computed value for the current animation frame
84      */
85     easeOut: function (t, b, c, d) {
86         return -c *(t/=d)*(t-2) + b;
87     },
89     /**
90      * Begins slowly and decelerates towards end. (quadratic)
91      * @method easeBoth
92      * @param {Number} t Time value used to compute current value
93      * @param {Number} b Starting value
94      * @param {Number} c Delta between start and end values
95      * @param {Number} d Total length of animation
96      * @return {Number} The computed value for the current animation frame
97      */
98     easeBoth: function (t, b, c, d) {
99         if ((t /= d/2) < 1) {
100             return c/2*t*t + b;
101         }
103         return -c/2 * ((--t)*(t-2) - 1) + b;
104     },
106     /**
107      * Begins slowly and accelerates towards end. (quartic)
108      * @method easeInStrong
109      * @param {Number} t Time value used to compute current value
110      * @param {Number} b Starting value
111      * @param {Number} c Delta between start and end values
112      * @param {Number} d Total length of animation
113      * @return {Number} The computed value for the current animation frame
114      */
115     easeInStrong: function (t, b, c, d) {
116         return c*(t/=d)*t*t*t + b;
117     },
119     /**
120      * Begins quickly and decelerates towards end.  (quartic)
121      * @method easeOutStrong
122      * @param {Number} t Time value used to compute current value
123      * @param {Number} b Starting value
124      * @param {Number} c Delta between start and end values
125      * @param {Number} d Total length of animation
126      * @return {Number} The computed value for the current animation frame
127      */
128     easeOutStrong: function (t, b, c, d) {
129         return -c * ((t=t/d-1)*t*t*t - 1) + b;
130     },
132     /**
133      * Begins slowly and decelerates towards end. (quartic)
134      * @method easeBothStrong
135      * @param {Number} t Time value used to compute current value
136      * @param {Number} b Starting value
137      * @param {Number} c Delta between start and end values
138      * @param {Number} d Total length of animation
139      * @return {Number} The computed value for the current animation frame
140      */
141     easeBothStrong: function (t, b, c, d) {
142         if ((t /= d/2) < 1) {
143             return c/2*t*t*t*t + b;
144         }
146         return -c/2 * ((t-=2)*t*t*t - 2) + b;
147     },
149     /**
150      * Snap in elastic effect.
151      * @method elasticIn
152      * @param {Number} t Time value used to compute current value
153      * @param {Number} b Starting value
154      * @param {Number} c Delta between start and end values
155      * @param {Number} d Total length of animation
156      * @param {Number} a Amplitude (optional)
157      * @param {Number} p Period (optional)
158      * @return {Number} The computed value for the current animation frame
159      */
161     elasticIn: function (t, b, c, d, a, p) {
162         var s;
163         if (t === 0) {
164             return b;
165         }
166         if ( (t /= d) === 1 ) {
167             return b+c;
168         }
169         if (!p) {
170             p = d* 0.3;
171         }
173         if (!a || a < Math.abs(c)) {
174             a = c;
175             s = p/4;
176         }
177         else {
178             s = p/(2*Math.PI) * Math.asin (c/a);
179         }
181         return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
182     },
184     /**
185      * Snap out elastic effect.
186      * @method elasticOut
187      * @param {Number} t Time value used to compute current value
188      * @param {Number} b Starting value
189      * @param {Number} c Delta between start and end values
190      * @param {Number} d Total length of animation
191      * @param {Number} a Amplitude (optional)
192      * @param {Number} p Period (optional)
193      * @return {Number} The computed value for the current animation frame
194      */
195     elasticOut: function (t, b, c, d, a, p) {
196         var s;
197         if (t === 0) {
198             return b;
199         }
200         if ( (t /= d) === 1 ) {
201             return b+c;
202         }
203         if (!p) {
204             p=d * 0.3;
205         }
207         if (!a || a < Math.abs(c)) {
208             a = c;
209             s = p / 4;
210         }
211         else {
212             s = p/(2*Math.PI) * Math.asin (c/a);
213         }
215         return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
216     },
218     /**
219      * Snap both elastic effect.
220      * @method elasticBoth
221      * @param {Number} t Time value used to compute current value
222      * @param {Number} b Starting value
223      * @param {Number} c Delta between start and end values
224      * @param {Number} d Total length of animation
225      * @param {Number} a Amplitude (optional)
226      * @param {Number} p Period (optional)
227      * @return {Number} The computed value for the current animation frame
228      */
229     elasticBoth: function (t, b, c, d, a, p) {
230         var s;
231         if (t === 0) {
232             return b;
233         }
235         if ( (t /= d/2) === 2 ) {
236             return b+c;
237         }
239         if (!p) {
240             p = d*(0.3*1.5);
241         }
243         if ( !a || a < Math.abs(c) ) {
244             a = c;
245             s = p/4;
246         }
247         else {
248             s = p/(2*Math.PI) * Math.asin (c/a);
249         }
251         if (t < 1) {
252             return -0.5*(a*Math.pow(2,10*(t-=1)) *
253                     Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
254         }
255         return a*Math.pow(2,-10*(t-=1)) *
256                 Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
257     },
260     /**
261      * Backtracks slightly, then reverses direction and moves to end.
262      * @method backIn
263      * @param {Number} t Time value used to compute current value
264      * @param {Number} b Starting value
265      * @param {Number} c Delta between start and end values
266      * @param {Number} d Total length of animation
267      * @param {Number} s Overshoot (optional)
268      * @return {Number} The computed value for the current animation frame
269      */
270     backIn: function (t, b, c, d, s) {
271         if (s === undefined) {
272             s = 1.70158;
273         }
274         if (t === d) {
275             t -= 0.001;
276         }
277         return c*(t/=d)*t*((s+1)*t - s) + b;
278     },
280     /**
281      * Overshoots end, then reverses and comes back to end.
282      * @method backOut
283      * @param {Number} t Time value used to compute current value
284      * @param {Number} b Starting value
285      * @param {Number} c Delta between start and end values
286      * @param {Number} d Total length of animation
287      * @param {Number} s Overshoot (optional)
288      * @return {Number} The computed value for the current animation frame
289      */
290     backOut: function (t, b, c, d, s) {
291         if (typeof s === 'undefined') {
292             s = 1.70158;
293         }
294         return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
295     },
297     /**
298      * Backtracks slightly, then reverses direction, overshoots end,
299      * then reverses and comes back to end.
300      * @method backBoth
301      * @param {Number} t Time value used to compute current value
302      * @param {Number} b Starting value
303      * @param {Number} c Delta between start and end values
304      * @param {Number} d Total length of animation
305      * @param {Number} s Overshoot (optional)
306      * @return {Number} The computed value for the current animation frame
307      */
308     backBoth: function (t, b, c, d, s) {
309         if (typeof s === 'undefined') {
310             s = 1.70158;
311         }
313         if ((t /= d/2 ) < 1) {
314             return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
315         }
316         return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
317     },
319     /**
320      * Bounce off of start.
321      * @method bounceIn
322      * @param {Number} t Time value used to compute current value
323      * @param {Number} b Starting value
324      * @param {Number} c Delta between start and end values
325      * @param {Number} d Total length of animation
326      * @return {Number} The computed value for the current animation frame
327      */
328     bounceIn: function (t, b, c, d) {
329         return c - Y.Easing.bounceOut(d-t, 0, c, d) + b;
330     },
332     /**
333      * Bounces off end.
334      * @method bounceOut
335      * @param {Number} t Time value used to compute current value
336      * @param {Number} b Starting value
337      * @param {Number} c Delta between start and end values
338      * @param {Number} d Total length of animation
339      * @return {Number} The computed value for the current animation frame
340      */
341     bounceOut: function (t, b, c, d) {
342         if ((t/=d) < (1/2.75)) {
343                 return c*(7.5625*t*t) + b;
344         } else if (t < (2/2.75)) {
345                 return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
346         } else if (t < (2.5/2.75)) {
347                 return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
348         }
349         return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
350     },
352     /**
353      * Bounces off start and end.
354      * @method bounceBoth
355      * @param {Number} t Time value used to compute current value
356      * @param {Number} b Starting value
357      * @param {Number} c Delta between start and end values
358      * @param {Number} d Total length of animation
359      * @return {Number} The computed value for the current animation frame
360      */
361     bounceBoth: function (t, b, c, d) {
362         if (t < d/2) {
363             return Y.Easing.bounceIn(t * 2, 0, c, d) * 0.5 + b;
364         }
365         return Y.Easing.bounceOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
366     }
369 Y.Easing = Easing;
372 }, '3.13.0', {"requires": ["anim-base"]});