Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / anim-curve / anim-curve.js
blob0f718032a11b4b1a39f1e1366362eb0b27d32b2a
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('anim-curve', function(Y) {
9 /**
10  * Adds support for the <code>curve</code> property for the <code>to</code> 
11  * attribute.  A curve is zero or more control points and an end point.
12  * @module anim
13  * @submodule anim-curve
14  */
16 Y.Anim.behaviors.curve = {
17     set: function(anim, att, from, to, elapsed, duration, fn) {
18         from = from.slice.call(from);
19         to = to.slice.call(to);
20         var t = fn(elapsed, 0, 100, duration) / 100;
21         to.unshift(from);
22         anim._node.setXY(Y.Anim.getBezier(to, t));
23     },
25     get: function(anim, att) {
26         return anim._node.getXY();
27     }
30 /**
31  * Get the current position of the animated element based on t.
32  * Each point is an array of "x" and "y" values (0 = x, 1 = y)
33  * At least 2 points are required (start and end).
34  * First point is start. Last point is end.
35  * Additional control points are optional.     
36  * @for Anim
37  * @method getBezier
38  * @static
39  * @param {Array} points An array containing Bezier points
40  * @param {Number} t A number between 0 and 1 which is the basis for determining current position
41  * @return {Array} An array containing int x and y member data
42  */
43 Y.Anim.getBezier = function(points, t) {  
44     var n = points.length;
45     var tmp = [];
47     for (var i = 0; i < n; ++i){
48         tmp[i] = [points[i][0], points[i][1]]; // save input
49     }
50     
51     for (var j = 1; j < n; ++j) {
52         for (i = 0; i < n - j; ++i) {
53             tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
54             tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; 
55         }
56     }
58     return [ tmp[0][0], tmp[0][1] ]; 
63 }, '3.5.0' ,{requires:['anim-xy']});