2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('anim-curve', function(Y) {
11 * Adds support for the <code>curve</code> property for the <code>to</code>
12 * attribute. A curve is zero or more control points and an end point.
14 * @submodule anim-curve
17 Y.Anim.behaviors.curve = {
18 set: function(anim, att, from, to, elapsed, duration, fn) {
19 from = from.slice.call(from);
20 to = to.slice.call(to);
21 var t = fn(elapsed, 0, 100, duration) / 100;
23 anim._node.setXY(Y.Anim.getBezier(to, t));
26 get: function(anim, att) {
27 return anim._node.getXY();
32 * Get the current position of the animated element based on t.
33 * Each point is an array of "x" and "y" values (0 = x, 1 = y)
34 * At least 2 points are required (start and end).
35 * First point is start. Last point is end.
36 * Additional control points are optional.
40 * @param {Array} points An array containing Bezier points
41 * @param {Number} t A number between 0 and 1 which is the basis for determining current position
42 * @return {Array} An array containing int x and y member data
44 Y.Anim.getBezier = function(points, t) {
45 var n = points.length;
48 for (var i = 0; i < n; ++i){
49 tmp[i] = [points[i][0], points[i][1]]; // save input
52 for (var j = 1; j < n; ++j) {
53 for (i = 0; i < n - j; ++i) {
54 tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
55 tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
59 return [ tmp[0][0], tmp[0][1] ];
64 }, '3.0.0' ,{requires:['anim-xy']});