annotate nodejs/animate.js @ 772:11f062c2c0b8

Script to detect memory leaking
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 29 Aug 2010 19:13:59 +0800
parents d11b0900f03c
children 77b561bb7929
rev   line source
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
1 var sys=require("sys");
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
2
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
3 function linear_draw() {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
4 if (this.end == 1) return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
5 var percent = (Date.now() - this.starttime)/this.duration;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
6 if (percent > 1) percent = 1;
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
7 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx;
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
8 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
9 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
10 var self = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
11 if (percent < 1) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
12 this.obj.timer=setTimeout(function() { self.draw();}, 20);
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
13 return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
14 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
15 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
16 this.obj.animated_linear = null;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
17 }
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
18 function linear(app,obj,targetx,targety,duration) {
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
19 try {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
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
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
23 obj.animated_linear.end = 1;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
24 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
25 } catch(e) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
26
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
27 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
28 obj.animated_linear = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
29 this.app = app;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
30 this.obj = obj;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
31 this.end = 0;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
32 this.starttime = Date.now();
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
33 this.startposx = obj[2];
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
34 this.startposy = obj[5];
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
35 this.targetx = targetx;
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
36 this.targety = targety;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
37 this.duration = duration*1000;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
38 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
39
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
40 exports.linear = linear;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
41 linear.prototype.start = linear_draw;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
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 //sys.puts("time="+(Date.now()-this.starttime)+" percent="+percent);
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
66 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
67 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
68 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
69 //sys.puts("center="+this.obj.center.x+","+this.obj.center.y);
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
70 this.obj[0] = sx;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
71 this.obj[4] = sy;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
72 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
73 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
74 //sys.puts("sx="+sx);
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
75 //sys.puts("sy="+sy);
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
76 //sys.puts("offseet x="+this.obj[2]);
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
77 //sys.puts("offseet y="+this.obj[5]);
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 var self = this;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
81 if (percent < 1) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
82 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
83 return;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
84 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
85 this.app.refresh();
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
86 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
87 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
88
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
89 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
90 try {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
91 if (obj.animated_scale) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
92 //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
93 //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
94 //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
95 //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
96 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
97 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
98 } catch(e) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
99
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
100 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
101 obj.animated_scale = this;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
102 this.app = app;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
103 this.obj = obj;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
104 this.end = 0;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
105 this.starttime = Date.now();
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
106 this.startsx = obj[0];
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
107 this.startsy = obj[4];
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
108 this.targetx = targetx;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
109 this.targety = targety;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
110 this.duration = duration*1000;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
111 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
112 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
113 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
114 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
115 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
116
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
117
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
118 exports.scale = scale;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
119 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
120 scale.prototype.draw = scale_draw;