Mercurial > MadButterfly
comparison nodejs/animate.js @ 798:210e4d24a3ba
Change linear to relative location shifting and add rotate
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 31 Aug 2010 14:52:12 +0800 |
parents | 46a4cd4d382b |
children | 55875133fa60 |
comparison
equal
deleted
inserted
replaced
797:891bbaca1d8f | 798:210e4d24a3ba |
---|---|
40 this.step = 1000 / (this.duration * ffs); | 40 this.step = 1000 / (this.duration * ffs); |
41 this.percent = 0; | 41 this.percent = 0; |
42 obj.timer = setInterval(function() { self.draw(); }, frame_interval); | 42 obj.timer = setInterval(function() { self.draw(); }, frame_interval); |
43 } | 43 } |
44 | 44 |
45 function linear(app,obj,targetx,targety,duration) { | 45 function linear(app,obj,shiftx,shifty,duration) { |
46 obj.animated_linear = this; | 46 obj.animated_linear = this; |
47 this.app = app; | 47 this.app = app; |
48 this.obj = obj; | 48 this.obj = obj; |
49 this.end = 0; | 49 this.end = 0; |
50 this.targetx = targetx; | 50 this.targetx = shiftx + obj[2]; |
51 this.targety = targety; | 51 this.targety = shifty + obj[5]; |
52 this.duration = duration*1000; | 52 this.duration = duration*1000; |
53 } | 53 } |
54 | 54 |
55 exports.linear = linear; | 55 exports.linear = linear; |
56 linear.prototype.start = linear_draw_start; | 56 linear.prototype.start = linear_draw_start; |
57 linear.prototype.draw = linear_draw; | 57 linear.prototype.draw = linear_draw; |
58 | |
59 /* ------------------------------------------------------------ */ | |
60 function rotate(app, obj, ang, duration) { | |
61 this._app = app; | |
62 this._obj = obj; | |
63 this._ang = ang; | |
64 this._duration = duration; | |
65 } | |
66 | |
67 function rotate_start() { | |
68 var obj = this._obj; | |
69 var self = this; | |
70 | |
71 this._step = 1 / (ffs * this._duration); | |
72 this._percent = 0; | |
73 this._start_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]; | |
74 obj.timer = setInterval(function() { self.draw(); }, frame_interval); | |
75 } | |
76 | |
77 function rotate_draw() { | |
78 var percent; | |
79 var ang; | |
80 var sv, cv; | |
81 var obj = this._obj; | |
82 var mtx, shift; | |
83 | |
84 this._percent = percent = this._percent + this._step; | |
85 if(percent > 1) { | |
86 percent = 1; | |
87 obj.timer.stop(); | |
88 } | |
89 | |
90 ang = percent * this._ang; | |
91 sv = Math.sin(ang); | |
92 cv = Math.cos(ang); | |
93 mtx = [cv, -sv, 0, sv, cv, 0]; | |
94 | |
95 shift = [1, 0, -obj.center_x, 0, 1, -obj.center_y]; | |
96 mtx = multiply(mtx, shift); | |
97 shift = [1, 0, obj.center_x, 0, 1, obj.center_y]; | |
98 mtx = multiply(shift, mtx); | |
99 mtx = multiply(mtx, this._start_mtx); | |
100 | |
101 obj[0] = mtx[0]; | |
102 obj[1] = mtx[1]; | |
103 obj[2] = mtx[2]; | |
104 obj[3] = mtx[3]; | |
105 obj[4] = mtx[4]; | |
106 obj[5] = mtx[5]; | |
107 | |
108 this._app.refresh(); | |
109 } | |
110 | |
111 rotate.prototype.start = rotate_start; | |
112 rotate.prototype.draw = rotate_draw; | |
113 exports.rotate = rotate; | |
58 | 114 |
59 function multiply(s,d) { | 115 function multiply(s,d) { |
60 var m=[]; | 116 var m=[]; |
61 m[0] = s[0]*d[0]+s[1]*d[3]; | 117 m[0] = s[0]*d[0]+s[1]*d[3]; |
62 m[1] = s[0]*d[1]+s[1]*d[4]; | 118 m[1] = s[0]*d[1]+s[1]*d[4]; |
63 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | 119 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; |
64 m[3] = s[3]*d[0]+s[4]*d[3]; | 120 m[3] = s[3]*d[0]+s[4]*d[3]; |
65 m[4] = s[3]*d[1]+s[4]*d[4]; | 121 m[4] = s[3]*d[1]+s[4]*d[4]; |
66 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; | 122 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; |
67 s[0] = m[0]; | 123 return m; |
68 s[1] = m[1]; | |
69 s[2] = m[2]; | |
70 s[3] = m[3]; | |
71 s[4] = m[4]; | |
72 s[5] = m[5]; | |
73 } | 124 } |
74 | 125 |
75 | 126 |
76 function scale_draw() { | 127 function scale_draw() { |
77 if (this.end == 1) return; | 128 if (this.end == 1) return; |