Mercurial > MadButterfly
annotate nodejs/animate.js @ 880:ac3e8492ad74 abs_n_rel_center
Formalize path data for MadButterfly.
Inkscape and other editors would omit 'l' or 'L' after 'm' or 'M'.
MadButterfly can not handle it, now. So, we work around it at SVG
parser.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 25 Sep 2010 18:46:37 +0800 |
parents | 3ce9daa9558b |
children | 3136db0ac01b |
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 |
727 | 12 function linear_draw() { |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
13 var percent; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
14 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
|
15 |
806
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
16 percent = (Date.now() - this._start_tm) / this.duration; |
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
17 if(percent >= 1) { |
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
18 percent = 1; |
844 | 19 if (this.obj.timer) { |
20 this.obj.timer.stop(); | |
21 delete this.obj.timer; | |
22 } | |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
23 } |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
24 x = (this.targetx-this.startposx)*percent+this.startposx; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
25 y = (this.targety-this.startposy)*percent+this.startposy; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
26 this.obj.center.move(x, y); |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
27 this.app.refresh(); |
727 | 28 } |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
29 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
30 function linear_draw_start() { |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
31 var obj = this.obj; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
32 var self = this; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
33 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
34 if(obj.timer) |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
35 obj.timer.stop(); |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
36 |
804
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
37 this._start_tm = Date.now(); |
806
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
38 obj.timer = setInterval(function() { self.draw(); }, frame_interval); |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
39 } |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
40 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
41 function linear(app,obj,shiftx,shifty,duration) { |
794 | 42 obj.animated_linear = this; |
43 this.app = app; | |
44 this.obj = obj; | |
45 this.end = 0; | |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
46 this.targetx = shiftx + obj.center.x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
47 this.targety = shifty + obj.center.y; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
48 this.startposx = obj.center.x; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
844
diff
changeset
|
49 this.startposy = obj.center.y; |
794 | 50 this.duration = duration*1000; |
727 | 51 } |
52 | |
53 exports.linear = linear; | |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
54 linear.prototype.start = linear_draw_start; |
727 | 55 linear.prototype.draw = linear_draw; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
56 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
57 /* ------------------------------------------------------------ */ |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
58 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
|
59 this._app = app; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
60 this._obj = obj; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
61 this._ang = ang; |
806
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
62 this._duration = duration * 1000; |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
63 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
64 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
65 function rotate_start() { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
66 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
|
67 var self = this; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
68 |
856
88f4916a0691
Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
69 if(obj.timer) |
88f4916a0691
Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
70 obj.timer.stop(); |
88f4916a0691
Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents:
854
diff
changeset
|
71 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
72 this._start_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]; |
806
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
73 this._start_tm = Date.now(); |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
74 obj.timer = setInterval(function() { self.draw(); }, frame_interval); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
75 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
76 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
77 function rotate_draw() { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
78 var percent; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
79 var ang; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
80 var sv, cv; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
81 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
|
82 var mtx, shift; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
83 |
806
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
84 percent = (Date.now() - this._start_tm) / this._duration; |
bf54c0408d35
Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents:
805
diff
changeset
|
85 if(percent >= 1) { |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
86 percent = 1; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
87 obj.timer.stop(); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
88 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
89 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 mtx = [cv, -sv, 0, sv, cv, 0]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
94 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
108 this._app.refresh(); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
109 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
110 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
111 rotate.prototype.start = rotate_start; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
112 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
|
113 exports.rotate = rotate; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
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 function multiply(s,d) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
116 var m=[]; |
794 | 117 m[0] = s[0]*d[0]+s[1]*d[3]; |
118 m[1] = s[0]*d[1]+s[1]*d[4]; | |
119 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | |
120 m[3] = s[3]*d[0]+s[4]*d[3]; | |
121 m[4] = s[3]*d[1]+s[4]*d[4]; | |
122 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
|
123 return m; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
124 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
125 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
126 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
127 function scale_draw() { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
128 if (this.end == 1) return; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
129 var percent = (Date.now() - this.starttime)/this.duration; |
794 | 130 if (percent > 1) percent = 1; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 var sh2 = [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
|
135 var scale=[sx, 0, 0, 0, sy, 0]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
136 var obj = this.obj; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
137 var mtx; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
138 |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
139 mtx = multiply(scale, sh1); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
140 mtx = multiply(sh2, mtx); |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
141 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
|
142 obj[0] = mtx[0]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
143 obj[1] = mtx[1]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
144 obj[2] = mtx[2]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
145 obj[3] = mtx[3]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
146 obj[4] = mtx[4]; |
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
147 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
|
148 |
794 | 149 this.app.refresh(); |
150 var self = this; | |
151 if (percent < 1) { | |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
152 obj.timer=setTimeout(function() { self.draw();}, frame_interval); |
794 | 153 return; |
154 } | |
155 this.app.refresh(); | |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
156 obj.animated_scale = null; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
157 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
158 |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
159 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
|
160 var bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
161 |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
162 try { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
163 if (obj.animated_scale) { |
794 | 164 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
|
165 } |
794 | 166 } catch(e) { |
167 | |
168 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
169 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
170 bbox = obj.bbox; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
171 bbox.update(); |
794 | 172 obj.animated_scale = this; |
173 this.app = app; | |
174 this.obj = obj; | |
175 this.end = 0; | |
176 this.starttime = Date.now(); | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
860
diff
changeset
|
177 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
|
178 this.totalsy = fact_y * bbox.orig.height / bbox.height; |
794 | 179 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
|
180 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
|
181 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
|
182 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
|
183 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
184 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
185 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
186 exports.scale = scale; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
187 scale.prototype.start = scale_draw; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
188 scale.prototype.draw = scale_draw; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
189 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
190 function holder(app, coord) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
191 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
|
192 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
193 this._mtx = mtx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
194 this._coord = coord; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
195 this._app = app; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
196 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
197 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
198 holder.prototype = { |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
199 go: function(pos) { |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
200 var sx, sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
201 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
202 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
|
203 sy = pos.y - this._coord.center.y; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
204 this.shift(sx, sy); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
205 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
206 |
808
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
207 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
|
208 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
|
209 }, |
9b6c26cf9102
Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents:
806
diff
changeset
|
210 |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
211 home: function() { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
212 this._coord[2] = this._mtx[2]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
213 this._coord[5] = this._mtx[5]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
214 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
215 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
216 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
217 shift: function(sx, sy) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
218 this._coord[2] = this._mtx[2] + sx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
219 this._coord[5] = this._mtx[5] + sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
220 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
221 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
222 }; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
223 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
224 exports.holder = holder; |
831 | 225 |
226 | |
227 | |
228 function alpha_draw() { | |
229 | |
230 if (this.end == 1) return; | |
231 var percent = (Date.now() - this.starttime)/this.duration; | |
232 if (percent > 1) percent = 1; | |
233 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; | |
234 this.obj.opacity=sx; | |
235 | |
236 this.app.refresh(); | |
237 var self = this; | |
238 if (percent < 1) { | |
844 | 239 this.obj.timer=setTimeout(function() { self.draw();}, frame_interval); |
831 | 240 return; |
241 } | |
242 this.app.refresh(); | |
243 this.obj.animated_alpha = null; | |
244 } | |
245 | |
246 function alpha(app,obj,alpha, duration) { | |
247 try { | |
248 if (obj.animated_alpha) { | |
249 obj.animated_alpha.end = 1; | |
250 } | |
251 } catch(e) { | |
252 | |
253 } | |
254 obj.animated_alpha = this; | |
255 this.app = app; | |
256 this.obj = obj; | |
257 this.end = 0; | |
258 this.starttime = Date.now(); | |
259 this.startalpha = obj.opacity; | |
260 this.targetalpha = alpha; | |
261 this.duration = duration*1000; | |
262 } | |
263 | |
264 alpha.prototype.start = alpha_draw; | |
265 alpha.prototype.draw = alpha_draw; | |
266 exports.alpha = alpha; |