annotate nodejs/animate.js @ 1071:1a75a4778515 openvg

Commont for changes of mbe
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Dec 2010 14:33:57 +0800
parents 4072a302b207
children c028aa928cc8
rev   line source
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 808
diff changeset
2 // vim: sw=4:ts=8:sts=4
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
3 var sys=require("sys");
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
4
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
5 /*
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
6 * This is configuration for animate module. For slower or speeder
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
7 * machines, ffs can be decreased or increased respective.
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
8 */
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
9 var ffs = 12;
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
10 var frame_interval = 1000 / ffs;
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
11
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
12 function shift_draw(percent) {
854
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
13 var x, y;
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
14
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 862 894
diff changeset
15 x = (this.targetx - this.startposx) * percent + this.startposx;
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 862 894
diff changeset
16 y = (this.targety - this.startposy) * percent + this.startposy;
854
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
17 this.obj.center.move(x, y);
937
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 929
diff changeset
18 this._app.refresh();
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
19 }
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
20
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
21 function shift(app,obj,shiftx,shifty) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
22 obj.animated_shift = this;
937
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 929
diff changeset
23 this._app = app;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
24 this.obj = obj;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
25 this.end = 0;
854
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
26 this.targetx = shiftx + obj.center.x;
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
27 this.targety = shifty + obj.center.y;
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
28 this.startposx = obj.center.x;
eff2f580b536 Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents: 844
diff changeset
29 this.startposy = obj.center.y;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
30 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
31
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
32 exports.shift = shift;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
33 shift.prototype.draw = shift_draw;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
34
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
35 /* ------------------------------------------------------------ */
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
36 function rotate(app, obj, ang, duration) {
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
37 this._app = app;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
38 this._obj = obj;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
39 this._ang = ang;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
40 this._start_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
41 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
42
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
43 function rotate_draw(percent) {
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
44 var percent;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
45 var ang;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
46 var sv, cv;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
47 var obj = this._obj;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
48 var mtx, shift;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
49
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
50
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
51 ang = percent * this._ang;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
52 sv = Math.sin(ang);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
53 cv = Math.cos(ang);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
54 mtx = [cv, -sv, 0, sv, cv, 0];
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
55 shift = [1, 0, -obj.center.x, 0, 1, -obj.center.y];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
56 mtx = multiply(mtx, shift);
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
57 shift = [1, 0, obj.center.x, 0, 1, obj.center.y];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
58 mtx = multiply(shift, mtx);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
59 mtx = multiply(mtx, this._start_mtx);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
60
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
61 obj[0] = mtx[0];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
62 obj[1] = mtx[1];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
63 obj[2] = mtx[2];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
64 obj[3] = mtx[3];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
65 obj[4] = mtx[4];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
66 obj[5] = mtx[5];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
67
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
68 this._app.refresh();
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
69 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
70
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
71 rotate.prototype.draw = rotate_draw;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
72 exports.rotate = rotate;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
73
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
74 function multiply(s,d) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
75 var m=[];
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
76 m[0] = s[0]*d[0]+s[1]*d[3];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
77 m[1] = s[0]*d[1]+s[1]*d[4];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
78 m[2] = s[0]*d[2]+s[1]*d[5]+s[2];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
79 m[3] = s[3]*d[0]+s[4]*d[3];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
80 m[4] = s[3]*d[1]+s[4]*d[4];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
81 m[5] = s[3]*d[2]+s[4]*d[5]+s[5];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
82 return m;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
83 }
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
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
86 function scale_draw(percent) {
1047
4072a302b207 Fine tune the animation effect
wycc
parents: 937
diff changeset
87 if (this.end==1) {
4072a302b207 Fine tune the animation effect
wycc
parents: 937
diff changeset
88 percent = 1;
4072a302b207 Fine tune the animation effect
wycc
parents: 937
diff changeset
89 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
90 var sx = 1 + (this.totalsx - 1) * percent;
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
91 var sy = 1 + (this.totalsy - 1) * percent;
857
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
92 var sh1 = [1, 0, -this.center_x, 0, 1, -this.center_y];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
93 var sh2 = [1, 0, this.center_x, 0, 1, this.center_y];
1047
4072a302b207 Fine tune the animation effect
wycc
parents: 937
diff changeset
94 sys.puts("sc="+sx+" sy="+sy);
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 862 894
diff changeset
95 var scale = [sx, 0, 0, 0, sy, 0];
857
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
96 var obj = this.obj;
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
97 var mtx;
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
98
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
99 mtx = multiply(scale, sh1);
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
100 mtx = multiply(sh2, mtx);
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
101 mtx = multiply(this.orig_mtx, mtx);
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
102 obj[0] = mtx[0];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
103 obj[1] = mtx[1];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
104 obj[2] = mtx[2];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
105 obj[3] = mtx[3];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
106 obj[4] = mtx[4];
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
107 obj[5] = mtx[5];
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
108
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
109 this.app.refresh();
758
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
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
112 function scale(app, obj, fact_x, fact_y, duration) {
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
113 var bbox;
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
114
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
115 try {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
116 if (obj.animated_scale) {
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
117 obj.animated_scale.end = 1;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
118 }
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
119 } catch(e) {
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
120
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
121 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
122
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
123 bbox = obj.bbox;
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
124 bbox.update();
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
125 obj.animated_scale = this;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
126 this.app = app;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
127 this.obj = obj;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
128 this.end = 0;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
129 this.starttime = Date.now();
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
130 this.totalsx = fact_x * bbox.orig.width / bbox.width;
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 860
diff changeset
131 this.totalsy = fact_y * bbox.orig.height / bbox.height;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
132 this.duration = duration*1000;
857
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
133 this.center_x = obj.center.rel.x;
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
134 this.center_y = obj.center.rel.y;
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
135 this.orig_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]];
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
136 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
137
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
138
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
139 exports.scale = scale;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
140 scale.prototype.draw = scale_draw;
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
141
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
142 function holder(app, coord) {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
143 var mtx = [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
144
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
145 this._mtx = mtx;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
146 this._coord = coord;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
147 this._app = app;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
148 }
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
149
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
150 holder.prototype = {
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
151 go: function(pos) {
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
152 var sx, sy;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
153
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
154 sx = pos.x - this._coord.center.x;
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
155 sy = pos.y - this._coord.center.y;
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
156 this.shift(sx, sy);
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
157 },
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
158
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
159 go_center: function(o) {
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
160 this.go(o.center);
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
161 },
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
162
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
163 home: function() {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
164 this._coord[2] = this._mtx[2];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
165 this._coord[5] = this._mtx[5];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
166 this._app.refresh();
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
167 },
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
168
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
169 shift: function(sx, sy) {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
170 this._coord[2] = this._mtx[2] + sx;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
171 this._coord[5] = this._mtx[5] + sy;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
172 this._app.refresh();
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
173 }
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
174 };
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
175
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
176 exports.holder = holder;
831
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
177
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
178
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
179
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
180 function alpha_draw(percent) {
831
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
181
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
182 if (this.end == 1) return;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
183 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
184 this.obj.opacity=sx;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
185 this.app.refresh();
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
186 this.obj.animated_alpha = null;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
187 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
188
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
189 function alpha(app,obj,alpha, duration) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
190 try {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
191 if (obj.animated_alpha) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
192 obj.animated_alpha.end = 1;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
193 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
194 } catch(e) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
195
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
196 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
197 obj.animated_alpha = this;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
198 this.app = app;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
199 this.obj = obj;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
200 this.end = 0;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
201 this.starttime = Date.now();
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
202 this.startalpha = obj.opacity;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
203 this.targetalpha = alpha;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
204 this.duration = duration*1000;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
205 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
206
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
207 alpha.prototype.draw = alpha_draw;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
208 exports.alpha = alpha;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
209
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
210 function linear_update()
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
211 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
212 var now = Date.now();
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 862 894
diff changeset
213 var i;
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 862 894
diff changeset
214
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
215 if (now >= this.end) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
216 this.timer.stop();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
217 now = this.end;
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
218 if (this.callback_end) {
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
219 this.callback_end();
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
220 this.callback_end=null;
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
221 }
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
222 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
223 if (now < this.startmove) return;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
224 var per = (now-this.startmove)/this.duration/1000;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
225 if (per > 1) per = 1;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
226 this.action.draw(per);
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
227 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
228
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
229 function linear_start()
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
230 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
231 var self = this;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
232 if (this.timer)
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
233 this.timer.stop();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
234 this.timer = setInterval(function() { self.update();}, frame_interval);
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
235 this.startmove = Date.now()+this.starttime*1000;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
236 this.end = this.startmove+this.duration*1000;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
237 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
238 function linear_stop()
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
239 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
240 if (this.timer) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
241 this.timer.stop();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
242 this.timer = null;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
243 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
244 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
245
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
246 function linear_finish()
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
247 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
248 this.action.draw(1);
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
249 if (this.callback_end) {
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
250 this.callback_end();
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
251 this.callback_end=null;
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
252 }
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
253 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
254 function linear(action,start, duration)
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
255 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
256 this.action = action;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
257 this.duration = duration;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
258 this.starttime = start;
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
259 this.callback_end = null;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
260 this.timer=null;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
261 }
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
262
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
263 function linear_callback(cb)
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
264 {
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
265 this.callback_end = cb;
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
266 }
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
267
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
268 linear.prototype.update = linear_update;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
269 linear.prototype.start = linear_start;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
270 linear.prototype.stop = linear_stop;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
271 linear.prototype.finish = linear_finish;
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
272 linear.prototype.callbackAtEnd = linear_callback;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
273 exports.linear = linear;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
274
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
275
907
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
276 function multilinear_update()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
277 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
278 }
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
279
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
280 function multilinear_start()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
281 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
282 }
898
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
283
907
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
284 function multilinear_stop()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
285 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
286 }
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
287
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
288 function multilinear_finish()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
289 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
290 }
898
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
291 function multilinear(action,start,stages) {
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
292 sys.puts("Multilinear word is not implemented yet");
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
293 }
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
294
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
295 exports.multilinear = multilinear;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
296 multilinear.prototype.update = multilinear_update;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
297 multilinear.prototype.start = multilinear_start;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
298 multilinear.prototype.stop = multilinear_stop;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
299 multilinear.prototype.finish = multilinear_finish;
907
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
300 function exponential_update()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
301 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
302 }
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
303 function exponential_start()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
304 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
305 }
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
306 function exponential_stop()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
307 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
308 }
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
309 function exponential_finish()
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
310 {
55767e444436 Add Stub functions.
wycc
parents: 900
diff changeset
311 }
898
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
312 function exponential(action,start,stages) {
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
313 sys.puts("exponential word is not implemented yet");
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
314 }
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
315
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
316 exports.exponential = exponential;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
317 exponential.prototype.update = exponential_update;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
318 exponential.prototype.start = exponential_start;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
319 exponential.prototype.stop = exponential_stop;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
320 exponential.prototype.finish = exponential_finish;
6044b977ce4f Add stub functions
wycc
parents: 897
diff changeset
321
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
322 function program(words)
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
323 {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
324 this.words = wrods;
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
325 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
326
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
327 program.prototype.start=function() {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
328 for(w in this.words) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
329 w.start();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
330 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
331 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
332
897
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
333 program.prototype.step=function(s) {
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
334 sys.puts("This function is not implemented yet");
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
335 }
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
336 program.prototype.stop=function() {
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
337 for(w in this.words) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
338 w.stop();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
339 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
340 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
341 program.prototype.finish=function() {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
342 for(w in this.words) {
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
343 w.finish();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
344 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
345 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
346
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
347 exports.run = function(actions,start,duration,cb) {
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
348 var li;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
349 for(a in actions) {
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
350 li = new linear(actions[a],start,duration);
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
351 li.start();
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
352 }
913
85b647f5aeff Add callback after the animation is finished.
wycc
parents: 910
diff changeset
353 li.callbackAtEnd(cb);
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
354 }
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
355 exports.runexp=function(actions,start,exp) {
897
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
356 sys.puts("This function is not implemented yet");
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
357 }
897
b38161a3abae Add stub functions for unimplemented methods.
wycc
parents: 895
diff changeset
358