Mercurial > MadButterfly
comparison nodejs/animate.js @ 727:468cd504800c
Rewrite the animation as a module.
author | wycc |
---|---|
date | Tue, 17 Aug 2010 05:15:50 +0800 |
parents | |
children | a843f147c995 |
comparison
equal
deleted
inserted
replaced
726:d479f319d7b7 | 727:468cd504800c |
---|---|
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; | |
7 this.obj[5] = (this.target-this.startpos)*percent+this.startpos; | |
8 this.app.refresh(); | |
9 var self = this; | |
10 if (percent < 1) { | |
11 this.obj.timer=setTimeout(function() { self.draw();}, 20); | |
12 return; | |
13 } | |
14 this.app.refresh(); | |
15 this.obj.animated_linear = null; | |
16 } | |
17 function linear(app,obj,target,duration) { | |
18 try { | |
19 if (obj.animated_linear) { | |
20 obj[5] = obj.animated_linear.target; | |
21 obj.animated_linear.end = 1; | |
22 } | |
23 } catch(e) { | |
24 | |
25 } | |
26 obj.animated_linear = this; | |
27 this.app = app; | |
28 this.obj = obj; | |
29 this.end = 0; | |
30 this.starttime = Date.now(); | |
31 this.startpos = obj[5]; | |
32 this.target = target; | |
33 this.duration = duration*1000; | |
34 } | |
35 | |
36 | |
37 exports.linear = linear; | |
38 linear.prototype.start = linear_draw; | |
39 linear.prototype.draw = linear_draw; |