anim-curve-debug.js revision 5977f41bf2914e3174de1e275499c5ccb36e8bae
1281N/AYUI.add('anim-curve', function(Y) {
1281N/A
1281N/A/**
1281N/A * Adds support for the <code>curve</code> property for the <code>to</code>
1281N/A * attribute. A curve is zero or more control points and an end point.
1281N/A * @module anim
1281N/A * @submodule anim-curve
1281N/A */
1281N/A
1281N/AY.Anim.behaviors.curve = {
1281N/A set: function(anim, att, from, to, elapsed, duration, fn) {
1281N/A from = from.slice.call(from);
1281N/A to = to.slice.call(to);
1281N/A var t = fn(elapsed, 0, 100, duration) / 100;
1281N/A to.unshift(from);
1281N/A anim._node.setXY(Y.Anim.getBezier(to, t));
1281N/A },
1281N/A
1281N/A get: function(anim, att) {
1281N/A return anim._node.getXY();
1281N/A }
1281N/A};
1281N/A
1281N/A/**
1281N/A * Get the current position of the animated element based on t.
1281N/A * Each point is an array of "x" and "y" values (0 = x, 1 = y)
1281N/A * At least 2 points are required (start and end).
1281N/A * First point is start. Last point is end.
1281N/A * Additional control points are optional.
1281N/A * @for Anim
1281N/A * @method getBezier
1281N/A * @static
1281N/A * @param {Array} points An array containing Bezier points
1281N/A * @param {Number} t A number between 0 and 1 which is the basis for determining current position
1281N/A * @return {Array} An array containing int x and y member data
1281N/A */
1281N/AY.Anim.getBezier = function(points, t) {
1281N/A var n = points.length;
1281N/A var tmp = [];
1281N/A
1281N/A for (var i = 0; i < n; ++i){
1281N/A tmp[i] = [points[i][0], points[i][1]]; // save input
1281N/A }
1281N/A
1281N/A for (var j = 1; j < n; ++j) {
1281N/A for (i = 0; i < n - j; ++i) {
1281N/A tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
1281N/A tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
1281N/A }
1281N/A }
1281N/A
1281N/A return [ tmp[0][0], tmp[0][1] ];
1281N/A
1281N/A};
1281N/A
1281N/A
}, '@VERSION@' ,{requires:['anim-base', 'node-screen']});