annotate 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
rev   line source
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
1 var sys=require("sys");
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
2
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
3 function linear_draw() {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
4 if (this.end == 1) return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
5 var percent = (Date.now() - this.starttime)/this.duration;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
6 if (percent > 1) percent = 1;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
7 this.obj[5] = (this.target-this.startpos)*percent+this.startpos;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
8 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
9 var self = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
10 if (percent < 1) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
11 this.obj.timer=setTimeout(function() { self.draw();}, 20);
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
12 return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
13 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
14 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
15 this.obj.animated_linear = null;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
16 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
17 function linear(app,obj,target,duration) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
18 try {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
19 if (obj.animated_linear) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
20 obj[5] = obj.animated_linear.target;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
21 obj.animated_linear.end = 1;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
22 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
23 } catch(e) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
24
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
25 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
26 obj.animated_linear = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
27 this.app = app;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
28 this.obj = obj;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
29 this.end = 0;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
30 this.starttime = Date.now();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
31 this.startpos = obj[5];
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
32 this.target = target;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
33 this.duration = duration*1000;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
34 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
35
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
36
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
37 exports.linear = linear;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
38 linear.prototype.start = linear_draw;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
39 linear.prototype.draw = linear_draw;