~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/build/anim-easing/anim-easing.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

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