|
602
|
1 |
YUI.add('anim-curve', function (Y, NAME) { |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* Adds support for the <code>curve</code> property for the <code>to</code> |
|
|
5 |
* attribute. A curve is zero or more control points and an end point. |
|
|
6 |
* @module anim |
|
|
7 |
* @submodule anim-curve |
|
|
8 |
*/ |
|
|
9 |
|
|
|
10 |
Y.Anim.behaviors.curve = { |
|
|
11 |
set: function(anim, att, from, to, elapsed, duration, fn) { |
|
|
12 |
from = from.slice.call(from); |
|
|
13 |
to = to.slice.call(to); |
|
|
14 |
var t = fn(elapsed, 0, 100, duration) / 100; |
|
|
15 |
to.unshift(from); |
|
|
16 |
anim._node.setXY(Y.Anim.getBezier(to, t)); |
|
|
17 |
}, |
|
|
18 |
|
|
|
19 |
get: function(anim) { |
|
|
20 |
return anim._node.getXY(); |
|
|
21 |
} |
|
|
22 |
}; |
|
|
23 |
|
|
|
24 |
/** |
|
|
25 |
* Get the current position of the animated element based on t. |
|
|
26 |
* Each point is an array of "x" and "y" values (0 = x, 1 = y) |
|
|
27 |
* At least 2 points are required (start and end). |
|
|
28 |
* First point is start. Last point is end. |
|
|
29 |
* Additional control points are optional. |
|
|
30 |
* @for Anim |
|
|
31 |
* @method getBezier |
|
|
32 |
* @static |
|
|
33 |
* @param {Number[]} points An array containing Bezier points |
|
|
34 |
* @param {Number} t A number between 0 and 1 which is the basis for determining current position |
|
|
35 |
* @return {Number[]} An array containing int x and y member data |
|
|
36 |
*/ |
|
|
37 |
Y.Anim.getBezier = function(points, t) { |
|
|
38 |
var n = points.length, |
|
|
39 |
tmp = [], |
|
|
40 |
i, |
|
|
41 |
j; |
|
|
42 |
|
|
|
43 |
for (i = 0; i < n; ++i){ |
|
|
44 |
tmp[i] = [points[i][0], points[i][1]]; // save input |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
for (j = 1; j < n; ++j) { |
|
|
48 |
for (i = 0; i < n - j; ++i) { |
|
|
49 |
tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; |
|
|
50 |
tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; |
|
|
51 |
} |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
return [ tmp[0][0], tmp[0][1] ]; |
|
|
55 |
|
|
|
56 |
}; |
|
|
57 |
|
|
|
58 |
|
|
|
59 |
}, '@VERSION@', {"requires": ["anim-xy"]}); |