Mercurial > MadButterfly
annotate nodejs/animate.js @ 937:191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 12 Nov 2010 16:54:48 +0800 |
parents | d35f9702b8c2 |
children | 4072a302b207 |
rev | line source |
---|---|
794 | 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 | 3 var sys=require("sys"); |
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 | 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 | 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 | 15 x = (this.targetx - this.startposx) * percent + this.startposx; |
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 | 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 | 21 function shift(app,obj,shiftx,shifty) { |
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 | 24 this.obj = obj; |
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 | 30 } |
31 | |
894 | 32 exports.shift = shift; |
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 | 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 | 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 | 76 m[0] = s[0]*d[0]+s[1]*d[3]; |
77 m[1] = s[0]*d[1]+s[1]*d[4]; | |
78 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | |
79 m[3] = s[3]*d[0]+s[4]*d[3]; | |
80 m[4] = s[3]*d[1]+s[4]*d[4]; | |
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 | 86 function scale_draw(percent) { |
929
d35f9702b8c2
Fix the bug when the last scale is issued before the last one is ended.
wycc
parents:
913
diff
changeset
|
87 if (this.end==1) return; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 var sh2 = [1, 0, this.center_x, 0, 1, this.center_y]; |
895 | 92 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
|
93 var obj = this.obj; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
94 var mtx; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
95 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
96 mtx = multiply(scale, sh1); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
97 mtx = multiply(sh2, mtx); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
98 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
|
99 obj[0] = mtx[0]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
100 obj[1] = mtx[1]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
101 obj[2] = mtx[2]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
102 obj[3] = mtx[3]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
103 obj[4] = mtx[4]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
104 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
|
105 |
794 | 106 this.app.refresh(); |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
107 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
108 |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
109 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
|
110 var bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
111 |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
112 try { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
113 if (obj.animated_scale) { |
794 | 114 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
|
115 } |
794 | 116 } catch(e) { |
117 | |
118 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
119 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
120 bbox = obj.bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
121 bbox.update(); |
794 | 122 obj.animated_scale = this; |
123 this.app = app; | |
124 this.obj = obj; | |
125 this.end = 0; | |
126 this.starttime = Date.now(); | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
127 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
|
128 this.totalsy = fact_y * bbox.orig.height / bbox.height; |
794 | 129 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
|
130 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
|
131 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
|
132 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
|
133 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
134 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
135 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
136 exports.scale = scale; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
137 scale.prototype.draw = scale_draw; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
138 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
139 function holder(app, coord) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
140 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
|
141 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
142 this._mtx = mtx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
143 this._coord = coord; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
144 this._app = app; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
145 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
146 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
147 holder.prototype = { |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
148 go: function(pos) { |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
149 var sx, sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
150 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
151 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
|
152 sy = pos.y - this._coord.center.y; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
153 this.shift(sx, sy); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
154 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
155 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
156 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
|
157 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
|
158 }, |
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
159 |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
160 home: function() { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
161 this._coord[2] = this._mtx[2]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
162 this._coord[5] = this._mtx[5]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
163 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
164 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
165 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
166 shift: function(sx, sy) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
167 this._coord[2] = this._mtx[2] + sx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
168 this._coord[5] = this._mtx[5] + sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
169 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
170 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
171 }; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
172 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
173 exports.holder = holder; |
831 | 174 |
175 | |
176 | |
894 | 177 function alpha_draw(percent) { |
831 | 178 |
179 if (this.end == 1) return; | |
180 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; | |
181 this.obj.opacity=sx; | |
182 this.app.refresh(); | |
183 this.obj.animated_alpha = null; | |
184 } | |
185 | |
186 function alpha(app,obj,alpha, duration) { | |
187 try { | |
188 if (obj.animated_alpha) { | |
189 obj.animated_alpha.end = 1; | |
190 } | |
191 } catch(e) { | |
192 | |
193 } | |
194 obj.animated_alpha = this; | |
195 this.app = app; | |
196 this.obj = obj; | |
197 this.end = 0; | |
198 this.starttime = Date.now(); | |
199 this.startalpha = obj.opacity; | |
200 this.targetalpha = alpha; | |
201 this.duration = duration*1000; | |
202 } | |
203 | |
204 alpha.prototype.draw = alpha_draw; | |
205 exports.alpha = alpha; | |
894 | 206 |
207 function linear_update() | |
208 { | |
209 var now = Date.now(); | |
895 | 210 var i; |
211 | |
894 | 212 if (now >= this.end) { |
213 this.timer.stop(); | |
214 now = this.end; | |
913 | 215 if (this.callback_end) { |
216 this.callback_end(); | |
217 this.callback_end=null; | |
218 } | |
894 | 219 } |
220 if (now < this.startmove) return; | |
221 var per = (now-this.startmove)/this.duration/1000; | |
222 if (per > 1) per = 1; | |
223 this.action.draw(per); | |
224 } | |
225 | |
226 function linear_start() | |
227 { | |
228 var self = this; | |
229 if (this.timer) | |
230 this.timer.stop(); | |
231 this.timer = setInterval(function() { self.update();}, frame_interval); | |
232 this.startmove = Date.now()+this.starttime*1000; | |
233 this.end = this.startmove+this.duration*1000; | |
234 } | |
235 function linear_stop() | |
236 { | |
237 if (this.timer) { | |
238 this.timer.stop(); | |
239 this.timer = null; | |
240 } | |
241 } | |
242 | |
243 function linear_finish() | |
244 { | |
245 this.action.draw(1); | |
913 | 246 if (this.callback_end) { |
247 this.callback_end(); | |
248 this.callback_end=null; | |
249 } | |
894 | 250 } |
251 function linear(action,start, duration) | |
252 { | |
253 this.action = action; | |
254 this.duration = duration; | |
255 this.starttime = start; | |
913 | 256 this.callback_end = null; |
894 | 257 this.timer=null; |
258 } | |
913 | 259 |
260 function linear_callback(cb) | |
261 { | |
262 this.callback_end = cb; | |
263 } | |
264 | |
894 | 265 linear.prototype.update = linear_update; |
266 linear.prototype.start = linear_start; | |
267 linear.prototype.stop = linear_stop; | |
268 linear.prototype.finish = linear_finish; | |
913 | 269 linear.prototype.callbackAtEnd = linear_callback; |
894 | 270 exports.linear = linear; |
271 | |
272 | |
907 | 273 function multilinear_update() |
274 { | |
275 } | |
276 | |
277 function multilinear_start() | |
278 { | |
279 } | |
898 | 280 |
907 | 281 function multilinear_stop() |
282 { | |
283 } | |
284 | |
285 function multilinear_finish() | |
286 { | |
287 } | |
898 | 288 function multilinear(action,start,stages) { |
289 sys.puts("Multilinear word is not implemented yet"); | |
290 } | |
291 | |
292 exports.multilinear = multilinear; | |
293 multilinear.prototype.update = multilinear_update; | |
294 multilinear.prototype.start = multilinear_start; | |
295 multilinear.prototype.stop = multilinear_stop; | |
296 multilinear.prototype.finish = multilinear_finish; | |
907 | 297 function exponential_update() |
298 { | |
299 } | |
300 function exponential_start() | |
301 { | |
302 } | |
303 function exponential_stop() | |
304 { | |
305 } | |
306 function exponential_finish() | |
307 { | |
308 } | |
898 | 309 function exponential(action,start,stages) { |
310 sys.puts("exponential word is not implemented yet"); | |
311 } | |
312 | |
313 exports.exponential = exponential; | |
314 exponential.prototype.update = exponential_update; | |
315 exponential.prototype.start = exponential_start; | |
316 exponential.prototype.stop = exponential_stop; | |
317 exponential.prototype.finish = exponential_finish; | |
318 | |
894 | 319 function program(words) |
320 { | |
321 this.words = wrods; | |
322 } | |
323 | |
324 program.prototype.start=function() { | |
325 for(w in this.words) { | |
326 w.start(); | |
327 } | |
328 } | |
329 | |
897 | 330 program.prototype.step=function(s) { |
331 sys.puts("This function is not implemented yet"); | |
332 } | |
333 program.prototype.stop=function() { | |
894 | 334 for(w in this.words) { |
335 w.stop(); | |
336 } | |
337 } | |
338 program.prototype.finish=function() { | |
339 for(w in this.words) { | |
340 w.finish(); | |
341 } | |
342 } | |
343 | |
913 | 344 exports.run = function(actions,start,duration,cb) { |
345 var li; | |
894 | 346 for(a in actions) { |
913 | 347 li = new linear(actions[a],start,duration); |
894 | 348 li.start(); |
349 } | |
913 | 350 li.callbackAtEnd(cb); |
894 | 351 } |
352 exports.runexp=function(actions,start,exp) { | |
897 | 353 sys.puts("This function is not implemented yet"); |
894 | 354 } |
897 | 355 |