Mercurial > MadButterfly
comparison nodejs/animate.js @ 857:ea1e88c40548 abs_n_rel_center
Make scale work on center of an object
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 20 Sep 2010 22:43:44 +0800 |
parents | 88f4916a0691 |
children | ed49dc0a26f1 |
comparison
equal
deleted
inserted
replaced
856:88f4916a0691 | 857:ea1e88c40548 |
---|---|
126 | 126 |
127 function scale_draw() { | 127 function scale_draw() { |
128 if (this.end == 1) return; | 128 if (this.end == 1) return; |
129 var percent = (Date.now() - this.starttime)/this.duration; | 129 var percent = (Date.now() - this.starttime)/this.duration; |
130 if (percent > 1) percent = 1; | 130 if (percent > 1) percent = 1; |
131 var sx = (this.targetx-this.startsx)*percent+this.startsx; | 131 var sx = 1 + (this.targetx - 1) * percent; |
132 var sy = (this.targety-this.startsy)*percent+this.startsy; | 132 var sy = 1 + (this.targety - 1) * percent; |
133 var t=[sx,0,0,0,sy,0]; | 133 var sh1 = [1, 0, -this.center_x, 0, 1, -this.center_y]; |
134 this.obj[0] = sx; | 134 var sh2 = [1, 0, this.center_x, 0, 1, this.center_y]; |
135 this.obj[4] = sy; | 135 var scale=[sx, 0, 0, 0, sy, 0]; |
136 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x; | 136 var obj = this.obj; |
137 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y; | 137 var mtx; |
138 | |
139 mtx = multiply(scale, sh1); | |
140 mtx = multiply(sh2, mtx); | |
141 mtx = multiply(this.orig_mtx, mtx); | |
142 sys.puts([obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]); | |
143 obj[0] = mtx[0]; | |
144 obj[1] = mtx[1]; | |
145 obj[2] = mtx[2]; | |
146 obj[3] = mtx[3]; | |
147 obj[4] = mtx[4]; | |
148 obj[5] = mtx[5]; | |
138 | 149 |
139 this.app.refresh(); | 150 this.app.refresh(); |
140 var self = this; | 151 var self = this; |
141 if (percent < 1) { | 152 if (percent < 1) { |
142 this.obj.timer=setTimeout(function() { self.draw();}, frame_interval); | 153 obj.timer=setTimeout(function() { self.draw();}, frame_interval); |
143 return; | 154 return; |
144 } | 155 } |
145 this.app.refresh(); | 156 this.app.refresh(); |
146 this.obj.animated_scale = null; | 157 obj.animated_scale = null; |
147 } | 158 } |
148 | 159 |
149 function scale(app,obj,targetx,targety, duration) { | 160 function scale(app,obj,targetx,targety, duration) { |
150 try { | 161 try { |
151 if (obj.animated_scale) { | 162 if (obj.animated_scale) { |
166 this.startsx = obj[0]; | 177 this.startsx = obj[0]; |
167 this.startsy = obj[4]; | 178 this.startsy = obj[4]; |
168 this.targetx = targetx; | 179 this.targetx = targetx; |
169 this.targety = targety; | 180 this.targety = targety; |
170 this.duration = duration*1000; | 181 this.duration = duration*1000; |
171 this.origin_offset_x = obj[2]; | 182 this.center_x = obj.center.rel.x; |
172 this.origin_offset_y = obj[5]; | 183 this.center_y = obj.center.rel.y; |
173 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x; | 184 this.orig_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]; |
174 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y; | |
175 } | 185 } |
176 | 186 |
177 | 187 |
178 exports.scale = scale; | 188 exports.scale = scale; |
179 scale.prototype.start = scale_draw; | 189 scale.prototype.start = scale_draw; |