|
1 /* |
|
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
3 Code licensed under the BSD License: |
|
4 http://developer.yahoo.net/yui/license.txt |
|
5 version: 3.0.0b1 |
|
6 build: 1163 |
|
7 */ |
|
8 YUI.add('anim-curve', function(Y) { |
|
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, att) { |
|
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 var tmp = []; |
|
47 |
|
48 for (var i = 0; i < n; ++i){ |
|
49 tmp[i] = [points[i][0], points[i][1]]; // save input |
|
50 } |
|
51 |
|
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]; |
|
56 } |
|
57 } |
|
58 |
|
59 return [ tmp[0][0], tmp[0][1] ]; |
|
60 |
|
61 }; |
|
62 |
|
63 |
|
64 |
|
65 }, '3.0.0b1' ,{requires:['anim-base', 'node-screen']}); |