Mercurial > MadButterfly
annotate nodejs/testdesktop.js @ 880:ac3e8492ad74 abs_n_rel_center
Formalize path data for MadButterfly.
Inkscape and other editors would omit 'l' or 'L' after 'm' or 'M'.
MadButterfly can not handle it, now. So, we work around it at SVG
parser.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 25 Sep 2010 18:46:37 +0800 |
parents | 881efcd8a18f |
children | 3136db0ac01b |
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; |
801 | 30 an = new animate.scale(app,items[item],1,1.5,0.1); |
752 | 31 an.start(); |
845 | 32 app.refresh(); |
820 | 33 app.addKeyListener(mbapp.KEY_LEFT, function() { |
855 | 34 var old = items[item]; |
35 item = item - 1; | |
36 if (item == -1) { | |
37 item = 0; | |
38 return; | |
39 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
40 |
855 | 41 var target = items[item]; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
42 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
43 old.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
44 target.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
45 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
46 var an = new animate.scale(app, old, 1, 1, 0.1); |
855 | 47 an.start(); |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
48 an = new animate.scale(app, target, 1, 1.5, 0.3); |
855 | 49 an.start(); |
752 | 50 }); |
51 | |
820 | 52 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
855 | 53 var old = items[item]; |
54 item = item + 1; | |
55 if (item == items.length) { | |
56 item = item - 1; | |
57 return; | |
58 } | |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
59 |
855 | 60 var target = items[item]; |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
61 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
62 old.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
63 target.bbox.update(); |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
64 |
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
65 var an = new animate.scale(app, old, 1, 1, 0.1); |
855 | 66 an.start(); |
862
3ce9daa9558b
Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents:
858
diff
changeset
|
67 an = new animate.scale(app, target, 1, 1.5, 0.3); |
855 | 68 an.start(); |
845 | 69 }); |
70 | |
847 | 71 app.addKeyListener(mbapp.KEY_UP, function() { |
855 | 72 var old = lines[line]; |
73 line = line - 1; | |
74 if (line == -1) { | |
75 line = 0; | |
76 return; | |
77 } | |
78 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
|
79 var sy = target.center.y - lightbar.center.y; |
855 | 80 sys.puts(sy); |
81 var an = new animate.linear(app,lightbar,0,sy,0.3); | |
82 an.start(); | |
847 | 83 }); |
84 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
855 | 85 var old = lines[line]; |
86 line = line + 1; | |
87 if (line == lines.length) { | |
88 line = line - 1; | |
89 return; | |
90 } | |
91 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
|
92 var sy = target.center.y - lightbar.center.y; |
855 | 93 sys.puts("line="+line); |
94 sys.puts("sy="+sy); | |
95 sys.puts("target.y="+target.center.y); | |
96 sys.puts("lightbar.y="+lightbar.center.y); | |
97 var an = new animate.linear(app,lightbar,0,sy,0.3); | |
98 an.start(); | |
847 | 99 }); |
845 | 100 |
101 app.addKeyListener(mbapp.KEY_ENTER, function() { | |
855 | 102 var target = items[item]; |
103 var sx = 500 - target.center.x; | |
104 var sy = 220 - target.center.y; | |
105 sys.puts("target "+sx+','+sy); | |
106 var an = new animate.linear(app,target,sx,sy,1); | |
107 an.start(); | |
108 for(i=0;i<items.length;i++) { | |
109 if (i == item) continue; | |
110 var x = Math.random(); | |
111 var y = Math.random(); | |
112 if (x > 0.5) x = 900; | |
113 else x = -500; | |
114 if (y > 0.5) y = 900; | |
115 else y = -500; | |
116 sx = x - items[i].center.x; | |
117 sy = y - items[i].center.y; | |
118 an = new animate.linear(app,items[i], sx,sy,2); | |
845 | 119 an.start(); |
855 | 120 alpha = new animate.alpha(app,items[i],0, 1); |
121 alpha.start(); | |
122 } | |
752 | 123 }); |
124 | |
125 app.loop(); |