3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('anim-curve', function(Y) {
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.
13
* @submodule anim-curve
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;
22
anim._node.setXY(Y.Anim.getBezier(to, t));
25
get: function(anim, att) {
26
return anim._node.getXY();
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.
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
43
Y.Anim.getBezier = function(points, t) {
44
var n = points.length;
47
for (var i = 0; i < n; ++i){
48
tmp[i] = [points[i][0], points[i][1]]; // save input
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];
58
return [ tmp[0][0], tmp[0][1] ];
63
}, '3.5.1' ,{requires:['anim-xy']});