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
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
2 var svg = require("./svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
3 var mbapp = require("./mbapp");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
4 var sys=require("sys");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
5 var animate=require("./animate");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
6 var fs = require("fs");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
7
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
8 app = new mbapp.app();
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
9 app.loadSVG("desktop.svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
10
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
11 video = app.get("video");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
12 //var an = new animate.alpha(app,video,0,1);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
13 //an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
14 audio = app.get("audio");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
15 picture = app.get("picture");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
16 setting = app.get("setting");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
17
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
18 lightbar = app.get("lightbar");
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
19 lines=[app.get("line1"),app.get("line2"),app.get("line3"), app.get("line4"),app.get("line5")];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
20 line=0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
21
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
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
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
24
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
25 animate.run([new animate.scale(app,items[item],1,1.5)],0,0.1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
26 app.refresh();
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
27
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
28 app.addKeyListener(mbapp.KEY_LEFT, function() {
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
29 var old = items[item];
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
30 item = item - 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
31 if (item == -1) {
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
32 item = 0;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
33 return;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
34 }
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
35 var target = items[item];
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
36 animate.run([new animate.scale(app,old,1,1)],0,0.1);
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
37 animate.run([new animate.scale(app,target,1,1.5)],0,0.3);
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
38 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
39
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
40 app.addKeyListener(mbapp.KEY_RIGHT, function() {
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
41 var old = items[item];
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
42 item = item + 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
43 if (item == items.length) {
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
44 item = item - 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
45 return;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
46 }
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
47 var target = items[item];
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
48 animate.run([new animate.scale(app,old,1,1)],0,0.1);
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
49 animate.run([new animate.scale(app,target,1,1.5)],0,0.3);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
50 });
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
51
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
52 app.addKeyListener(mbapp.KEY_UP, function() {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
53 var old = lines[line];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
54 line = line - 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
55 if (line == -1) {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
56 line = 0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
57 return;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
58 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
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
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
61 sys.puts(sy);
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
62 animate.run([new animate.shift(app,lightbar,0,sy)],0,0.3);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
63 });
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
64 app.addKeyListener(mbapp.KEY_DOWN, function() {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
65 var old = lines[line];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
66 line = line + 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
67 if (line == lines.length) {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
68 line = line - 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
69 return;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
70 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
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
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
73 sys.puts("line="+line);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
74 sys.puts("sy="+sy);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
75 sys.puts("target.y="+target.y);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
76 sys.puts("lightbar.y="+lightbar.y);
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
77 animate.run([new animate.shift(app,lightbar,0,sy)],0,0.3);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
78 });
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
79
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
80 app.addKeyListener(mbapp.KEY_ENTER, function() {
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
81 var target = items[item];
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
82 var sx = 500-target.x;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
83 var sy = 220-target.y;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
84 sys.puts("target "+sx+','+sy);
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
85 animate.run([new animate.shift(app,target,sx,sy)],0,1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
86 for(i=0;i<items.length;i++) {
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
87 if (i == item) continue;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
88 var x = Math.random();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
89 var y = Math.random();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
90 if (x > 0.5) x = 900;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
91 else x = -500;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
92 if (y > 0.5) y = 900;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
93 else y = -500;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
94 sx = x-items[i].x;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
95 sy = y-items[i].y;
892
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
96 animate.run([new animate.shift(app,items[i], sx,sy)],0,2);
23dffb564ace Implemnet new animation framework as the WIKI.
wycc
parents: 849
diff changeset
97 animate.run([new animate.alpha(app,items[i],0)],0, 1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
98 }
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
99 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
100
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
101 app.loop();