Mercurial > MadButterfly
annotate nodejs/testdesktop.js @ 892:23dffb564ace
Implemnet new animation framework as the WIKI.
author | wycc |
---|---|
date | Mon, 27 Sep 2010 22:37:37 +0800 |
parents | d1c98eb474e1 |
children | cad38ddb1253 |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
820
diff
changeset
|
1 // vim: sw=4:ts=8:sts=4 |
752 | 2 var svg = require("./svg"); |
3 var mbapp = require("./mbapp"); | |
4 var sys=require("sys"); | |
5 var animate=require("./animate"); | |
6 var fs = require("fs"); | |
7 | |
8 app = new mbapp.app(); | |
9 app.loadSVG("desktop.svg"); | |
10 | |
11 video = app.get("video"); | |
845 | 12 //var an = new animate.alpha(app,video,0,1); |
13 //an.start(); | |
752 | 14 audio = app.get("audio"); |
15 picture = app.get("picture"); | |
16 setting = app.get("setting"); | |
845 | 17 |
847 | 18 lightbar = app.get("lightbar"); |
19 lines=[app.get("line1"),app.get("line2"),app.get("line3"), app.get("line4"),app.get("line5")]; | |
20 line=0; | |
21 | |
752 | 22 items=[video,audio,picture,setting]; |
776
77b561bb7929
Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents:
758
diff
changeset
|
23 item = 0; |
892 | 24 |
25 animate.run([new animate.scale(app,items[item],1,1.5)],0,0.1); | |
845 | 26 app.refresh(); |
892 | 27 |
820 | 28 app.addKeyListener(mbapp.KEY_LEFT, function() { |
752 | 29 var old = items[item]; |
30 item = item - 1; | |
31 if (item == -1) { | |
32 item = 0; | |
33 return; | |
34 } | |
845 | 35 var target = items[item]; |
892 | 36 animate.run([new animate.scale(app,old,1,1)],0,0.1); |
37 animate.run([new animate.scale(app,target,1,1.5)],0,0.3); | |
752 | 38 }); |
39 | |
820 | 40 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
752 | 41 var old = items[item]; |
42 item = item + 1; | |
43 if (item == items.length) { | |
44 item = item - 1; | |
45 return; | |
46 } | |
845 | 47 var target = items[item]; |
892 | 48 animate.run([new animate.scale(app,old,1,1)],0,0.1); |
49 animate.run([new animate.scale(app,target,1,1.5)],0,0.3); | |
845 | 50 }); |
51 | |
847 | 52 app.addKeyListener(mbapp.KEY_UP, function() { |
53 var old = lines[line]; | |
54 line = line - 1; | |
55 if (line == -1) { | |
56 line = 0; | |
57 return; | |
58 } | |
59 var target = lines[line]; | |
849
d1c98eb474e1
Change the code to fit the change of the center of the transformation point.
wycc
parents:
847
diff
changeset
|
60 var sy = target.y-lightbar.y; |
847 | 61 sys.puts(sy); |
892 | 62 animate.run([new animate.shift(app,lightbar,0,sy)],0,0.3); |
847 | 63 }); |
64 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
65 var old = lines[line]; | |
66 line = line + 1; | |
67 if (line == lines.length) { | |
68 line = line - 1; | |
69 return; | |
70 } | |
71 var target = lines[line]; | |
849
d1c98eb474e1
Change the code to fit the change of the center of the transformation point.
wycc
parents:
847
diff
changeset
|
72 var sy = target.y-lightbar.y; |
847 | 73 sys.puts("line="+line); |
74 sys.puts("sy="+sy); | |
75 sys.puts("target.y="+target.y); | |
76 sys.puts("lightbar.y="+lightbar.y); | |
892 | 77 animate.run([new animate.shift(app,lightbar,0,sy)],0,0.3); |
847 | 78 }); |
845 | 79 |
80 app.addKeyListener(mbapp.KEY_ENTER, function() { | |
81 var target = items[item]; | |
82 var sx = 500-target.x; | |
83 var sy = 220-target.y; | |
84 sys.puts("target "+sx+','+sy); | |
892 | 85 animate.run([new animate.shift(app,target,sx,sy)],0,1); |
845 | 86 for(i=0;i<items.length;i++) { |
87 if (i == item) continue; | |
88 var x = Math.random(); | |
89 var y = Math.random(); | |
90 if (x > 0.5) x = 900; | |
91 else x = -500; | |
92 if (y > 0.5) y = 900; | |
93 else y = -500; | |
94 sx = x-items[i].x; | |
95 sy = y-items[i].y; | |
892 | 96 animate.run([new animate.shift(app,items[i], sx,sy)],0,2); |
97 animate.run([new animate.alpha(app,items[i],0)],0, 1); | |
845 | 98 } |
752 | 99 }); |
100 | |
101 app.loop(); |