Mercurial > MadButterfly
annotate nodejs/animate.js @ 776:77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
However, the image does not work here since it does not use the transformation of the group.
author | wycc |
---|---|
date | Mon, 30 Aug 2010 08:56:44 +0800 |
parents | d11b0900f03c |
children | 7ec13634c97d |
rev | line source |
---|---|
727 | 1 var sys=require("sys"); |
2 | |
3 function linear_draw() { | |
4 if (this.end == 1) return; | |
5 var percent = (Date.now() - this.starttime)/this.duration; | |
6 if (percent > 1) percent = 1; | |
728 | 7 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx; |
8 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy; | |
727 | 9 this.app.refresh(); |
10 var self = this; | |
11 if (percent < 1) { | |
12 this.obj.timer=setTimeout(function() { self.draw();}, 20); | |
13 return; | |
14 } | |
15 this.app.refresh(); | |
16 this.obj.animated_linear = null; | |
17 } | |
728 | 18 function linear(app,obj,targetx,targety,duration) { |
727 | 19 try { |
20 if (obj.animated_linear) { | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
21 obj[5] = obj.animated_linear.targety; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
22 obj[2] = obj.animated_linear.targetx; |
727 | 23 obj.animated_linear.end = 1; |
24 } | |
25 } catch(e) { | |
26 | |
27 } | |
28 obj.animated_linear = this; | |
29 this.app = app; | |
30 this.obj = obj; | |
31 this.end = 0; | |
32 this.starttime = Date.now(); | |
728 | 33 this.startposx = obj[2]; |
34 this.startposy = obj[5]; | |
35 this.targetx = targetx; | |
36 this.targety = targety; | |
727 | 37 this.duration = duration*1000; |
38 } | |
39 | |
40 exports.linear = linear; | |
41 linear.prototype.start = linear_draw; | |
42 linear.prototype.draw = linear_draw; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
43 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
44 function multiply(s,d) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
45 var m=[]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
46 m[0] = s[0]*d[0]+s[1]*d[3]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
47 m[1] = s[0]*d[1]+s[1]*d[4]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
48 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
49 m[3] = s[3]*d[0]+s[4]*d[3]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
50 m[4] = s[3]*d[1]+s[4]*d[4]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
51 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
52 s[0] = m[0]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
53 s[1] = m[1]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
54 s[2] = m[2]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
55 s[3] = m[3]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
56 s[4] = m[4]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
57 s[5] = m[5]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
58 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
59 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
60 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
61 function scale_draw() { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
62 if (this.end == 1) return; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
63 var percent = (Date.now() - this.starttime)/this.duration; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
64 if (percent > 1) percent = 1; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
65 var sx = (this.targetx-this.startsx)*percent+this.startsx; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
66 var sy = (this.targety-this.startsy)*percent+this.startsy; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
67 var t=[sx,0,0,0,sy,0]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
68 this.obj[0] = sx; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
69 this.obj[4] = sy; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
70 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
71 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
72 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
73 this.app.refresh(); |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
74 var self = this; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
75 if (percent < 1) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
76 this.obj.timer=setTimeout(function() { self.draw();}, 20); |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
77 return; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
78 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
79 this.app.refresh(); |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
80 this.obj.animated_scale = null; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
81 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
82 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
83 function scale(app,obj,targetx,targety, duration) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
84 try { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
85 if (obj.animated_scale) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
86 //obj[0] = obj.animated_scale.targetx; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
87 //obj[4] = obj.animated_scale.targety; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
88 //obj[2] = obj.animated_scale.final_offset_x; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
89 //obj[5] = obj.aninated_scale.final_offset_y; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
90 obj.animated_scale.end = 1; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
91 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
92 } catch(e) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
93 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
94 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
95 obj.animated_scale = this; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
96 this.app = app; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
97 this.obj = obj; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
98 this.end = 0; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
99 this.starttime = Date.now(); |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
100 this.startsx = obj[0]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
101 this.startsy = obj[4]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
102 this.targetx = targetx; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
103 this.targety = targety; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
104 this.duration = duration*1000; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
105 this.origin_offset_x = obj[2]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
106 this.origin_offset_y = obj[5]; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
107 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
108 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
109 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
110 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
111 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
112 exports.scale = scale; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
113 scale.prototype.start = scale_draw; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
114 scale.prototype.draw = scale_draw; |