comparison nodejs/animate.js @ 794:a27606be2cab

Change modeline
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 31 Aug 2010 09:27:16 +0800
parents 7ec13634c97d
children 46a4cd4d382b
comparison
equal deleted inserted replaced
793:cad706a8f5b1 794:a27606be2cab
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4:ai
1 var sys=require("sys"); 3 var sys=require("sys");
2 4
3 function linear_draw() { 5 function linear_draw() {
4 if (this.end == 1) return; 6 if (this.end == 1) return;
5 var percent = (Date.now() - this.starttime)/this.duration; 7 var percent = (Date.now() - this.starttime)/this.duration;
16 this.obj.animated_linear = null; 18 this.obj.animated_linear = null;
17 } 19 }
18 function linear(app,obj,targetx,targety,duration) { 20 function linear(app,obj,targetx,targety,duration) {
19 try { 21 try {
20 if (obj.animated_linear) { 22 if (obj.animated_linear) {
21 obj[5] = obj.animated_linear.targety; 23 obj[5] = obj.animated_linear.targety;
22 obj[2] = obj.animated_linear.targetx; 24 obj[2] = obj.animated_linear.targetx;
23 obj.animated_linear.end = 1; 25 obj.animated_linear.end = 1;
24 } 26 }
25 } catch(e) { 27 } catch(e) {
26 28
27 } 29 }
28 obj.animated_linear = this; 30 obj.animated_linear = this;
29 this.app = app; 31 this.app = app;
30 this.obj = obj; 32 this.obj = obj;
31 this.end = 0; 33 this.end = 0;
32 this.starttime = Date.now(); 34 this.starttime = Date.now();
33 this.startposx = obj[2]; 35 this.startposx = obj[2];
34 this.startposy = obj[5]; 36 this.startposy = obj[5];
35 this.targetx = targetx; 37 this.targetx = targetx;
36 this.targety = targety; 38 this.targety = targety;
37 this.duration = duration*1000; 39 this.duration = duration*1000;
38 } 40 }
39 41
40 exports.linear = linear; 42 exports.linear = linear;
41 linear.prototype.start = linear_draw; 43 linear.prototype.start = linear_draw;
42 linear.prototype.draw = linear_draw; 44 linear.prototype.draw = linear_draw;
43 45
44 function multiply(s,d) { 46 function multiply(s,d) {
45 var m=[]; 47 var m=[];
46 m[0] = s[0]*d[0]+s[1]*d[3]; 48 m[0] = s[0]*d[0]+s[1]*d[3];
47 m[1] = s[0]*d[1]+s[1]*d[4]; 49 m[1] = s[0]*d[1]+s[1]*d[4];
48 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; 50 m[2] = s[0]*d[2]+s[1]*d[5]+s[2];
49 m[3] = s[3]*d[0]+s[4]*d[3]; 51 m[3] = s[3]*d[0]+s[4]*d[3];
50 m[4] = s[3]*d[1]+s[4]*d[4]; 52 m[4] = s[3]*d[1]+s[4]*d[4];
51 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; 53 m[5] = s[3]*d[2]+s[4]*d[5]+s[5];
52 s[0] = m[0]; 54 s[0] = m[0];
53 s[1] = m[1]; 55 s[1] = m[1];
54 s[2] = m[2]; 56 s[2] = m[2];
55 s[3] = m[3]; 57 s[3] = m[3];
56 s[4] = m[4]; 58 s[4] = m[4];
57 s[5] = m[5]; 59 s[5] = m[5];
58 } 60 }
59 61
60 62
61 function scale_draw() { 63 function scale_draw() {
62 if (this.end == 1) return; 64 if (this.end == 1) return;
63 var percent = (Date.now() - this.starttime)/this.duration; 65 var percent = (Date.now() - this.starttime)/this.duration;
64 if (percent > 1) percent = 1; 66 if (percent > 1) percent = 1;
65 var sx = (this.targetx-this.startsx)*percent+this.startsx; 67 var sx = (this.targetx-this.startsx)*percent+this.startsx;
66 var sy = (this.targety-this.startsy)*percent+this.startsy; 68 var sy = (this.targety-this.startsy)*percent+this.startsy;
67 var t=[sx,0,0,0,sy,0]; 69 var t=[sx,0,0,0,sy,0];
68 this.obj[0] = sx; 70 this.obj[0] = sx;
69 this.obj[4] = sy; 71 this.obj[4] = sy;
70 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x; 72 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x;
71 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y; 73 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y;
72 74
73 this.app.refresh(); 75 this.app.refresh();
74 var self = this; 76 var self = this;
75 if (percent < 1) { 77 if (percent < 1) {
76 this.obj.timer=setTimeout(function() { self.draw();}, 20); 78 this.obj.timer=setTimeout(function() { self.draw();}, 20);
77 return; 79 return;
78 } 80 }
79 this.app.refresh(); 81 this.app.refresh();
80 this.obj.animated_scale = null; 82 this.obj.animated_scale = null;
81 } 83 }
82 84
83 function scale(app,obj,targetx,targety, duration) { 85 function scale(app,obj,targetx,targety, duration) {
84 try { 86 try {
85 if (obj.animated_scale) { 87 if (obj.animated_scale) {
86 //obj[0] = obj.animated_scale.targetx; 88 //obj[0] = obj.animated_scale.targetx;
87 //obj[4] = obj.animated_scale.targety; 89 //obj[4] = obj.animated_scale.targety;
88 //obj[2] = obj.animated_scale.final_offset_x; 90 //obj[2] = obj.animated_scale.final_offset_x;
89 //obj[5] = obj.aninated_scale.final_offset_y; 91 //obj[5] = obj.aninated_scale.final_offset_y;
90 obj.animated_scale.end = 1; 92 obj.animated_scale.end = 1;
91 } 93 }
92 } catch(e) { 94 } catch(e) {
93 95
94 } 96 }
95 obj.animated_scale = this; 97 obj.animated_scale = this;
96 this.app = app; 98 this.app = app;
97 this.obj = obj; 99 this.obj = obj;
98 this.end = 0; 100 this.end = 0;
99 this.starttime = Date.now(); 101 this.starttime = Date.now();
100 this.startsx = obj[0]; 102 this.startsx = obj[0];
101 this.startsy = obj[4]; 103 this.startsy = obj[4];
102 this.targetx = targetx; 104 this.targetx = targetx;
103 this.targety = targety; 105 this.targety = targety;
104 this.duration = duration*1000; 106 this.duration = duration*1000;
105 this.origin_offset_x = obj[2]; 107 this.origin_offset_x = obj[2];
106 this.origin_offset_y = obj[5]; 108 this.origin_offset_y = obj[5];
107 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x; 109 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x;
108 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y; 110 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y;
109 } 111 }
110 112
111 113
112 exports.scale = scale; 114 exports.scale = scale;
113 scale.prototype.start = scale_draw; 115 scale.prototype.start = scale_draw;