comparison nodejs/animate.js @ 862:3ce9daa9558b abs_n_rel_center

Scale an object according bbox.orig
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 21 Sep 2010 00:40:36 +0800
parents 9303fb45a958
children 3136db0ac01b
comparison
equal deleted inserted replaced
861:e69f551e4a37 862:3ce9daa9558b
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 = 1 + (this.targetx - 1) * percent; 131 var sx = 1 + (this.totalsx - 1) * percent;
132 var sy = 1 + (this.targety - 1) * percent; 132 var sy = 1 + (this.totalsy - 1) * percent;
133 var sh1 = [1, 0, -this.center_x, 0, 1, -this.center_y]; 133 var sh1 = [1, 0, -this.center_x, 0, 1, -this.center_y];
134 var sh2 = [1, 0, this.center_x, 0, 1, this.center_y]; 134 var sh2 = [1, 0, this.center_x, 0, 1, this.center_y];
135 var scale=[sx, 0, 0, 0, sy, 0]; 135 var scale=[sx, 0, 0, 0, sy, 0];
136 var obj = this.obj; 136 var obj = this.obj;
137 var mtx; 137 var mtx;
154 } 154 }
155 this.app.refresh(); 155 this.app.refresh();
156 obj.animated_scale = null; 156 obj.animated_scale = null;
157 } 157 }
158 158
159 function scale(app,obj,targetx,targety, duration) { 159 function scale(app, obj, fact_x, fact_y, duration) {
160 var bbox;
161
160 try { 162 try {
161 if (obj.animated_scale) { 163 if (obj.animated_scale) {
162 //obj[0] = obj.animated_scale.targetx;
163 //obj[4] = obj.animated_scale.targety;
164 //obj[2] = obj.animated_scale.final_offset_x;
165 //obj[5] = obj.aninated_scale.final_offset_y;
166 obj.animated_scale.end = 1; 164 obj.animated_scale.end = 1;
167 } 165 }
168 } catch(e) { 166 } catch(e) {
169 167
170 } 168 }
169
170 bbox = obj.bbox;
171 bbox.update();
171 obj.animated_scale = this; 172 obj.animated_scale = this;
172 this.app = app; 173 this.app = app;
173 this.obj = obj; 174 this.obj = obj;
174 this.end = 0; 175 this.end = 0;
175 this.starttime = Date.now(); 176 this.starttime = Date.now();
176 this.targetx = targetx; 177 this.totalsx = fact_x * bbox.orig.width / bbox.width;
177 this.targety = targety; 178 this.totalsy = fact_y * bbox.orig.height / bbox.height;
178 this.duration = duration*1000; 179 this.duration = duration*1000;
179 this.center_x = obj.center.rel.x; 180 this.center_x = obj.center.rel.x;
180 this.center_y = obj.center.rel.y; 181 this.center_y = obj.center.rel.y;
181 this.orig_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]; 182 this.orig_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]];
182 } 183 }