comparison nodejs/examples/desktop/testdesktop.js @ 939:a74b4d986a91

Move examples for nodejs into nodejs/examples/ sub-directories. See INSTALL.txt. Use nodejs/examples/run.sh to run examples. For example, cd nodejs/examples; ./run.sh examples/testsvg/testsvg.js
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 12 Nov 2010 17:39:04 +0800
parents nodejs/testdesktop.js@3136db0ac01b
children
comparison
equal deleted inserted replaced
938:13b9acbbe9a3 939:a74b4d986a91
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4
3 var svg = require("svg");
4 var mbapp = require("mbapp");
5 var sys=require("sys");
6 var animate=require("animate");
7 var fs = require("fs");
8
9 app = new mbapp.app();
10 app.loadSVG("desktop.svg");
11
12 video = app.get("video");
13 //var an = new animate.alpha(app,video,0,1);
14 //an.start();
15 audio = app.get("audio");
16 picture = app.get("picture");
17 setting = app.get("setting");
18
19 lightbar = app.get("lightbar");
20 lines = [];
21 for(i = 0; i < 5; i++) {
22 line = app.get("line" + (i + 1));
23 lines.push(line);
24 }
25 line=0;
26
27 items=[video, audio, picture, setting];
28
29 item = 0;
30
31 animate.run([new animate.scale(app,items[item], 1, 1.5)], 0, 0.1);
32 app.refresh();
33
34 app.addKeyListener(mbapp.KEY_LEFT, function() {
35 var old = items[item];
36 item = item - 1;
37 if (item == -1) {
38 item = 0;
39 return;
40 }
41
42 var target = items[item];
43
44 old.bbox.update();
45 target.bbox.update();
46
47 var an = new animate.scale(app, old, 1, 1);
48 animate.run([an], 0, 0.1);
49 an = new animate.scale(app, target, 1, 1.5);
50 animate.run([an], 0, 0.3);
51 });
52
53 app.addKeyListener(mbapp.KEY_RIGHT, function() {
54 var old = items[item];
55 item = item + 1;
56 if (item == items.length) {
57 item = item - 1;
58 return;
59 }
60
61 var target = items[item];
62
63 old.bbox.update();
64 target.bbox.update();
65
66 var an = new animate.scale(app, old, 1, 1);
67 animate.run([an], 0, 0.1);
68 an = new animate.scale(app, target, 1, 1.5);
69 animate.run([an], 0, 0.3);
70 });
71
72 app.addKeyListener(mbapp.KEY_UP, function() {
73 var old = lines[line];
74 line = line - 1;
75 if (line == -1) {
76 line = 0;
77 return;
78 }
79 var target = lines[line];
80 var sy = target.center.y - lightbar.center.y;
81 sys.puts(sy);
82 var an = new animate.shift(app, lightbar, 0, sy);
83 animate.run([an], 0, 0.3);
84 });
85 app.addKeyListener(mbapp.KEY_DOWN, function() {
86 var old = lines[line];
87 line = line + 1;
88 if (line == lines.length) {
89 line = line - 1;
90 return;
91 }
92 var target = lines[line];
93 var sy = target.center.y - lightbar.center.y;
94 sys.puts("line="+line);
95 sys.puts("sy="+sy);
96 sys.puts("target.y="+target.center.y);
97 sys.puts("lightbar.y="+lightbar.center.y);
98 var an = new animate.shift(app, lightbar, 0, sy);
99 animate.run([an], 0, 0.3);
100 });
101
102 app.addKeyListener(mbapp.KEY_ENTER, function() {
103 var target = items[item];
104 var sx = 500 - target.center.x;
105 var sy = 220 - target.center.y;
106 sys.puts("target "+sx+','+sy);
107 var an = new animate.shift(app,target,sx,sy,1);
108 an.start();
109 for(i=0;i<items.length;i++) {
110 if (i == item) continue;
111 var x = Math.random();
112 var y = Math.random();
113 if (x > 0.5) x = 900;
114 else x = -500;
115 if (y > 0.5) y = 900;
116 else y = -500;
117 sx = x - items[i].center.x;
118 sy = y - items[i].center.y;
119 an = new animate.shift(app,items[i], sx, sy);
120 animate.run([an], 0, 2);
121 alpha = new animate.alpha(app,items[i], 0);
122 animate.run([an], 0, 1);
123 }
124 });
125
126 app.loop();