~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/anim-easing/anim-easing.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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