727
|
1 var sys=require("sys");
|
|
2
|
|
3 function linear_draw() {
|
|
4 if (this.end == 1) return;
|
|
5 var percent = (Date.now() - this.starttime)/this.duration;
|
|
6 if (percent > 1) percent = 1;
|
728
|
7 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx;
|
|
8 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy;
|
727
|
9 this.app.refresh();
|
|
10 var self = this;
|
|
11 if (percent < 1) {
|
|
12 this.obj.timer=setTimeout(function() { self.draw();}, 20);
|
|
13 return;
|
|
14 }
|
|
15 this.app.refresh();
|
|
16 this.obj.animated_linear = null;
|
|
17 }
|
728
|
18 function linear(app,obj,targetx,targety,duration) {
|
727
|
19 try {
|
|
20 if (obj.animated_linear) {
|
|
21 obj[5] = obj.animated_linear.target;
|
|
22 obj.animated_linear.end = 1;
|
|
23 }
|
|
24 } catch(e) {
|
|
25
|
|
26 }
|
|
27 obj.animated_linear = this;
|
|
28 this.app = app;
|
|
29 this.obj = obj;
|
|
30 this.end = 0;
|
|
31 this.starttime = Date.now();
|
728
|
32 this.startposx = obj[2];
|
|
33 this.startposy = obj[5];
|
|
34 this.targetx = targetx;
|
|
35 this.targety = targety;
|
727
|
36 this.duration = duration*1000;
|
|
37 }
|
|
38
|
|
39
|
|
40 exports.linear = linear;
|
|
41 linear.prototype.start = linear_draw;
|
|
42 linear.prototype.draw = linear_draw;
|