Mercurial > MadButterfly
annotate nodejs/animate.js @ 1494:ac390af12152
Add comment and rename methods
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 03 May 2011 01:21:20 +0800 |
parents | c028aa928cc8 |
children |
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; |
895 | 14 x = (this.targetx - this.startposx) * percent + this.startposx; |
15 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
|
16 this.obj.center.move(x, y); |
727 | 17 } |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
18 |
894 | 19 function shift(app,obj,shiftx,shifty) { |
20 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
|
21 this._app = app; |
794 | 22 this.obj = obj; |
23 this.end = 0; | |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
24 this.targetx = shiftx + obj.center.x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
25 this.targety = shifty + obj.center.y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
26 this.startposx = obj.center.x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
27 this.startposy = obj.center.y; |
727 | 28 } |
29 | |
894 | 30 exports.shift = shift; |
31 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
|
32 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
33 /* ------------------------------------------------------------ */ |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
34 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
|
35 this._app = app; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
36 this._obj = obj; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
37 this._ang = ang; |
894 | 38 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
|
39 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
40 |
894 | 41 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
|
42 var percent; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
43 var ang; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
44 var sv, cv; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
45 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
|
46 var mtx, shift; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
47 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
48 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
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(shift, mtx); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
57 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
|
58 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
66 this._app.refresh(); |
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 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
69 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
|
70 exports.rotate = rotate; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
71 |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
72 function multiply(s,d) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
73 var m=[]; |
794 | 74 m[0] = s[0]*d[0]+s[1]*d[3]; |
75 m[1] = s[0]*d[1]+s[1]*d[4]; | |
76 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | |
77 m[3] = s[3]*d[0]+s[4]*d[3]; | |
78 m[4] = s[3]*d[1]+s[4]*d[4]; | |
79 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
|
80 return m; |
758
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 |
894 | 84 function scale_draw(percent) { |
1047 | 85 if (this.end==1) { |
86 percent = 1; | |
87 } | |
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]; |
1047 | 92 sys.puts("sc="+sx+" sy="+sy); |
895 | 93 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
|
94 var obj = this.obj; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
95 var mtx; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
96 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
97 mtx = multiply(scale, sh1); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
98 mtx = multiply(sh2, mtx); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
99 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
|
100 obj[0] = mtx[0]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
101 obj[1] = mtx[1]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
102 obj[2] = mtx[2]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
103 obj[3] = mtx[3]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
104 obj[4] = mtx[4]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
105 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
|
106 |
794 | 107 this.app.refresh(); |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
108 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
109 |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
110 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
|
111 var bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
112 |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
113 try { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
114 if (obj.animated_scale) { |
794 | 115 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
|
116 } |
794 | 117 } catch(e) { |
118 | |
119 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
120 |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
121 |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
122 bbox = obj.bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
123 bbox.update(); |
794 | 124 obj.animated_scale = this; |
125 this.app = app; | |
126 this.obj = obj; | |
127 this.end = 0; | |
128 this.starttime = Date.now(); | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
129 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
|
130 this.totalsy = fact_y * bbox.orig.height / bbox.height; |
794 | 131 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
|
132 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
|
133 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
|
134 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
|
135 } |
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 exports.scale = scale; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
139 scale.prototype.draw = scale_draw; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
140 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
141 function holder(app, coord) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
142 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
|
143 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
144 this._mtx = mtx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
145 this._coord = coord; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
146 this._app = app; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
147 } |
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 holder.prototype = { |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
150 go: function(pos) { |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
151 var sx, sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
152 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
153 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
|
154 sy = pos.y - this._coord.center.y; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
155 this.shift(sx, sy); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
156 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
157 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
158 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
|
159 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
|
160 }, |
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
161 |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
162 home: function() { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
163 this._coord[2] = this._mtx[2]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
164 this._coord[5] = this._mtx[5]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
165 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
166 }, |
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 shift: function(sx, sy) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
169 this._coord[2] = this._mtx[2] + sx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
170 this._coord[5] = this._mtx[5] + sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
171 this._app.refresh(); |
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 }; |
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 exports.holder = holder; |
831 | 176 |
177 | |
178 | |
894 | 179 function alpha_draw(percent) { |
831 | 180 |
181 if (this.end == 1) return; | |
182 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; | |
183 this.obj.opacity=sx; | |
184 this.app.refresh(); | |
185 this.obj.animated_alpha = null; | |
186 } | |
187 | |
188 function alpha(app,obj,alpha, duration) { | |
189 try { | |
190 if (obj.animated_alpha) { | |
191 obj.animated_alpha.end = 1; | |
192 } | |
193 } catch(e) { | |
194 | |
195 } | |
196 obj.animated_alpha = this; | |
197 this.app = app; | |
198 this.obj = obj; | |
199 this.end = 0; | |
200 this.starttime = Date.now(); | |
201 this.startalpha = obj.opacity; | |
202 this.targetalpha = alpha; | |
203 this.duration = duration*1000; | |
204 } | |
205 | |
206 alpha.prototype.draw = alpha_draw; | |
207 exports.alpha = alpha; | |
894 | 208 |
209 function linear_update() | |
210 { | |
211 var now = Date.now(); | |
895 | 212 var i; |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
213 |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
214 //now = this.lasttime + 300; |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
215 //this.lasttime += 300; |
895 | 216 |
894 | 217 if (now >= this.end) { |
218 this.timer.stop(); | |
219 now = this.end; | |
913 | 220 if (this.callback_end) { |
221 this.callback_end(); | |
222 this.callback_end=null; | |
223 } | |
894 | 224 } |
225 if (now < this.startmove) return; | |
226 var per = (now-this.startmove)/this.duration/1000; | |
227 if (per > 1) per = 1; | |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
228 try { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
229 for(a in this.action) { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
230 this.action[a].draw(per); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
231 } |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
232 } catch(e) { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
233 sys.puts(e); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
234 } |
894 | 235 } |
236 | |
237 function linear_start() | |
238 { | |
239 var self = this; | |
240 if (this.timer) | |
241 this.timer.stop(); | |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
242 this.timer = setInterval(function() { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
243 var n = Date.now(); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
244 try { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
245 self.update(); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
246 self._app.refresh(); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
247 } catch(e) { |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
248 sys.puts("libnear: "+e); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
249 } |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
250 |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
251 //while( Date.now() - n < 1000); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
252 }, frame_interval); |
894 | 253 this.startmove = Date.now()+this.starttime*1000; |
254 this.end = this.startmove+this.duration*1000; | |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
255 this.lasttime = this.startmove; |
894 | 256 } |
257 function linear_stop() | |
258 { | |
259 if (this.timer) { | |
260 this.timer.stop(); | |
261 this.timer = null; | |
262 } | |
263 } | |
264 | |
265 function linear_finish() | |
266 { | |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
267 for(a in this.action) |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
268 this.action[a].draw(1); |
913 | 269 if (this.callback_end) { |
270 this.callback_end(); | |
271 this.callback_end=null; | |
272 } | |
894 | 273 } |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
274 function linear(app,action,start, duration) |
894 | 275 { |
276 this.action = action; | |
277 this.duration = duration; | |
278 this.starttime = start; | |
913 | 279 this.callback_end = null; |
894 | 280 this.timer=null; |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
281 this._app =app; |
894 | 282 } |
913 | 283 |
284 function linear_callback(cb) | |
285 { | |
286 this.callback_end = cb; | |
287 } | |
288 | |
894 | 289 linear.prototype.update = linear_update; |
290 linear.prototype.start = linear_start; | |
291 linear.prototype.stop = linear_stop; | |
292 linear.prototype.finish = linear_finish; | |
913 | 293 linear.prototype.callbackAtEnd = linear_callback; |
894 | 294 exports.linear = linear; |
295 | |
296 | |
907 | 297 function multilinear_update() |
298 { | |
299 } | |
300 | |
301 function multilinear_start() | |
302 { | |
303 } | |
898 | 304 |
907 | 305 function multilinear_stop() |
306 { | |
307 } | |
308 | |
309 function multilinear_finish() | |
310 { | |
311 } | |
898 | 312 function multilinear(action,start,stages) { |
313 sys.puts("Multilinear word is not implemented yet"); | |
314 } | |
315 | |
316 exports.multilinear = multilinear; | |
317 multilinear.prototype.update = multilinear_update; | |
318 multilinear.prototype.start = multilinear_start; | |
319 multilinear.prototype.stop = multilinear_stop; | |
320 multilinear.prototype.finish = multilinear_finish; | |
907 | 321 function exponential_update() |
322 { | |
323 } | |
324 function exponential_start() | |
325 { | |
326 } | |
327 function exponential_stop() | |
328 { | |
329 } | |
330 function exponential_finish() | |
331 { | |
332 } | |
898 | 333 function exponential(action,start,stages) { |
334 sys.puts("exponential word is not implemented yet"); | |
335 } | |
336 | |
337 exports.exponential = exponential; | |
338 exponential.prototype.update = exponential_update; | |
339 exponential.prototype.start = exponential_start; | |
340 exponential.prototype.stop = exponential_stop; | |
341 exponential.prototype.finish = exponential_finish; | |
342 | |
894 | 343 function program(words) |
344 { | |
345 this.words = wrods; | |
346 } | |
347 | |
348 program.prototype.start=function() { | |
349 for(w in this.words) { | |
350 w.start(); | |
351 } | |
352 } | |
353 | |
897 | 354 program.prototype.step=function(s) { |
355 sys.puts("This function is not implemented yet"); | |
356 } | |
357 program.prototype.stop=function() { | |
894 | 358 for(w in this.words) { |
359 w.stop(); | |
360 } | |
361 } | |
362 program.prototype.finish=function() { | |
363 for(w in this.words) { | |
364 w.finish(); | |
365 } | |
366 } | |
367 | |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
368 exports.run = function(app,actions,start,duration,cb) { |
913 | 369 var li; |
1439
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
370 li = new linear(app,actions,start,duration); |
c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
wycc
parents:
1047
diff
changeset
|
371 li.start(); |
913 | 372 li.callbackAtEnd(cb); |
894 | 373 } |
374 exports.runexp=function(actions,start,exp) { | |
897 | 375 sys.puts("This function is not implemented yet"); |
894 | 376 } |
897 | 377 |