Mercurial > MadButterfly
annotate nodejs/testdesktop.js @ 930:30cd14b11bc7
USe the graphics from the Max.
author | wycc |
---|---|
date | Sat, 06 Nov 2010 00:53:59 +0800 |
parents | 3136db0ac01b |
children |
rev | line source |
---|---|
855 | 1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
820
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
752 | 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"); | |
845 | 13 //var an = new animate.alpha(app,video,0,1); |
14 //an.start(); | |
752 | 15 audio = app.get("audio"); |
16 picture = app.get("picture"); | |
17 setting = app.get("setting"); | |
845 | 18 |
847 | 19 lightbar = app.get("lightbar"); |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
20 lines = []; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
21 for(i = 0; i < 5; i++) { |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
22 line = app.get("line" + (i + 1)); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
23 lines.push(line); |
847 | 24 } |
25 line=0; | |
26 | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
27 items=[video, audio, picture, setting]; |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
28 |
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
|
29 item = 0; |
894 | 30 |
895 | 31 animate.run([new animate.scale(app,items[item], 1, 1.5)], 0, 0.1); |
845 | 32 app.refresh(); |
894 | 33 |
820 | 34 app.addKeyListener(mbapp.KEY_LEFT, function() { |
855 | 35 var old = items[item]; |
36 item = item - 1; | |
37 if (item == -1) { | |
38 item = 0; | |
39 return; | |
40 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
41 |
855 | 42 var target = items[item]; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
43 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
44 old.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
45 target.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
46 |
895 | 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); | |
752 | 51 }); |
52 | |
820 | 53 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
855 | 54 var old = items[item]; |
55 item = item + 1; | |
56 if (item == items.length) { | |
57 item = item - 1; | |
58 return; | |
59 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
60 |
855 | 61 var target = items[item]; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
62 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
63 old.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
64 target.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
65 |
895 | 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); | |
845 | 70 }); |
71 | |
847 | 72 app.addKeyListener(mbapp.KEY_UP, function() { |
855 | 73 var old = lines[line]; |
74 line = line - 1; | |
75 if (line == -1) { | |
76 line = 0; | |
77 return; | |
78 } | |
79 var target = lines[line]; | |
858
ed49dc0a26f1
Move lightbar to correct position when it being up
Thinker K.F. Li <thinker@codemud.net>
parents:
857
diff
changeset
|
80 var sy = target.center.y - lightbar.center.y; |
855 | 81 sys.puts(sy); |
895 | 82 var an = new animate.shift(app, lightbar, 0, sy); |
83 animate.run([an], 0, 0.3); | |
847 | 84 }); |
85 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
855 | 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]; | |
856
88f4916a0691
Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents:
855
diff
changeset
|
93 var sy = target.center.y - lightbar.center.y; |
855 | 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); | |
895 | 98 var an = new animate.shift(app, lightbar, 0, sy); |
99 animate.run([an], 0, 0.3); | |
847 | 100 }); |
845 | 101 |
102 app.addKeyListener(mbapp.KEY_ENTER, function() { | |
855 | 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); | |
895 | 107 var an = new animate.shift(app,target,sx,sy,1); |
855 | 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; | |
895 | 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); | |
855 | 123 } |
752 | 124 }); |
125 | |
126 app.loop(); |