|
525
|
1 |
/* |
|
|
2 |
YUI 3.10.3 (build 2fb5187) |
|
|
3 |
Copyright 2013 Yahoo! Inc. All rights reserved. |
|
|
4 |
Licensed under the BSD License. |
|
|
5 |
http://yuilibrary.com/license/ |
|
|
6 |
*/ |
|
|
7 |
|
|
|
8 |
YUI.add('anim-curve', function (Y, NAME) { |
|
|
9 |
|
|
|
10 |
/** |
|
|
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. |
|
|
13 |
* @module anim |
|
|
14 |
* @submodule anim-curve |
|
|
15 |
*/ |
|
|
16 |
|
|
|
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; |
|
|
22 |
to.unshift(from); |
|
|
23 |
anim._node.setXY(Y.Anim.getBezier(to, t)); |
|
|
24 |
}, |
|
|
25 |
|
|
|
26 |
get: function(anim) { |
|
|
27 |
return anim._node.getXY(); |
|
|
28 |
} |
|
|
29 |
}; |
|
|
30 |
|
|
|
31 |
/** |
|
|
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. |
|
|
37 |
* @for Anim |
|
|
38 |
* @method getBezier |
|
|
39 |
* @static |
|
|
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 |
|
|
43 |
*/ |
|
|
44 |
Y.Anim.getBezier = function(points, t) { |
|
|
45 |
var n = points.length, |
|
|
46 |
tmp = [], |
|
|
47 |
i, |
|
|
48 |
j; |
|
|
49 |
|
|
|
50 |
for (i = 0; i < n; ++i){ |
|
|
51 |
tmp[i] = [points[i][0], points[i][1]]; // save input |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
for (j = 1; j < n; ++j) { |
|
|
55 |
for (i = 0; i < n - j; ++i) { |
|
|
56 |
tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; |
|
|
57 |
tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; |
|
|
58 |
} |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
return [ tmp[0][0], tmp[0][1] ]; |
|
|
62 |
|
|
|
63 |
}; |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
}, '3.10.3', {"requires": ["anim-xy"]}); |