Mercurial > MadButterfly
comparison nodejs/animate.js @ 758:d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
author | wycc |
---|---|
date | Sat, 28 Aug 2010 17:31:59 +0800 |
parents | a843f147c995 |
children | 77b561bb7929 |
comparison
equal
deleted
inserted
replaced
757:f43224bf3524 | 758:d11b0900f03c |
---|---|
16 this.obj.animated_linear = null; | 16 this.obj.animated_linear = null; |
17 } | 17 } |
18 function linear(app,obj,targetx,targety,duration) { | 18 function linear(app,obj,targetx,targety,duration) { |
19 try { | 19 try { |
20 if (obj.animated_linear) { | 20 if (obj.animated_linear) { |
21 obj[5] = obj.animated_linear.target; | 21 obj[5] = obj.animated_linear.targety; |
22 obj[2] = obj.animated_linear.targetx; | |
22 obj.animated_linear.end = 1; | 23 obj.animated_linear.end = 1; |
23 } | 24 } |
24 } catch(e) { | 25 } catch(e) { |
25 | 26 |
26 } | 27 } |
34 this.targetx = targetx; | 35 this.targetx = targetx; |
35 this.targety = targety; | 36 this.targety = targety; |
36 this.duration = duration*1000; | 37 this.duration = duration*1000; |
37 } | 38 } |
38 | 39 |
39 | |
40 exports.linear = linear; | 40 exports.linear = linear; |
41 linear.prototype.start = linear_draw; | 41 linear.prototype.start = linear_draw; |
42 linear.prototype.draw = linear_draw; | 42 linear.prototype.draw = linear_draw; |
43 | |
44 function multiply(s,d) { | |
45 var m=[]; | |
46 m[0] = s[0]*d[0]+s[1]*d[3]; | |
47 m[1] = s[0]*d[1]+s[1]*d[4]; | |
48 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | |
49 m[3] = s[3]*d[0]+s[4]*d[3]; | |
50 m[4] = s[3]*d[1]+s[4]*d[4]; | |
51 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; | |
52 s[0] = m[0]; | |
53 s[1] = m[1]; | |
54 s[2] = m[2]; | |
55 s[3] = m[3]; | |
56 s[4] = m[4]; | |
57 s[5] = m[5]; | |
58 } | |
59 | |
60 | |
61 function scale_draw() { | |
62 if (this.end == 1) return; | |
63 var percent = (Date.now() - this.starttime)/this.duration; | |
64 if (percent > 1) percent = 1; | |
65 //sys.puts("time="+(Date.now()-this.starttime)+" percent="+percent); | |
66 var sx = (this.targetx-this.startsx)*percent+this.startsx; | |
67 var sy = (this.targety-this.startsy)*percent+this.startsy; | |
68 var t=[sx,0,0,0,sy,0]; | |
69 //sys.puts("center="+this.obj.center.x+","+this.obj.center.y); | |
70 this.obj[0] = sx; | |
71 this.obj[4] = sy; | |
72 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x; | |
73 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y; | |
74 //sys.puts("sx="+sx); | |
75 //sys.puts("sy="+sy); | |
76 //sys.puts("offseet x="+this.obj[2]); | |
77 //sys.puts("offseet y="+this.obj[5]); | |
78 | |
79 this.app.refresh(); | |
80 var self = this; | |
81 if (percent < 1) { | |
82 this.obj.timer=setTimeout(function() { self.draw();}, 20); | |
83 return; | |
84 } | |
85 this.app.refresh(); | |
86 this.obj.animated_scale = null; | |
87 } | |
88 | |
89 function scale(app,obj,targetx,targety, duration) { | |
90 try { | |
91 if (obj.animated_scale) { | |
92 //obj[0] = obj.animated_scale.targetx; | |
93 //obj[4] = obj.animated_scale.targety; | |
94 //obj[2] = obj.animated_scale.final_offset_x; | |
95 //obj[5] = obj.aninated_scale.final_offset_y; | |
96 obj.animated_scale.end = 1; | |
97 } | |
98 } catch(e) { | |
99 | |
100 } | |
101 obj.animated_scale = this; | |
102 this.app = app; | |
103 this.obj = obj; | |
104 this.end = 0; | |
105 this.starttime = Date.now(); | |
106 this.startsx = obj[0]; | |
107 this.startsy = obj[4]; | |
108 this.targetx = targetx; | |
109 this.targety = targety; | |
110 this.duration = duration*1000; | |
111 this.origin_offset_x = obj[2]; | |
112 this.origin_offset_y = obj[5]; | |
113 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x; | |
114 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y; | |
115 } | |
116 | |
117 | |
118 exports.scale = scale; | |
119 scale.prototype.start = scale_draw; | |
120 scale.prototype.draw = scale_draw; |