Mercurial > MadButterfly
annotate nodejs/testdesktop.js @ 858:ed49dc0a26f1 abs_n_rel_center
Move lightbar to correct position when it being up
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 20 Sep 2010 22:43:44 +0800 |
parents | ea1e88c40548 |
children | 3ce9daa9558b |
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"); |
20 lines=[app.get("line1"),app.get("line2"),app.get("line3"), app.get("line4"),app.get("line5")]; | |
21 for(i=0;i<lines.length;i++) { | |
855 | 22 sys.puts("["+i+"]="+lines[i].center.x); |
847 | 23 } |
24 line=0; | |
25 | |
752 | 26 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
|
27 item = 0; |
801 | 28 an = new animate.scale(app,items[item],1,1.5,0.1); |
752 | 29 an.start(); |
845 | 30 app.refresh(); |
820 | 31 app.addKeyListener(mbapp.KEY_LEFT, function() { |
855 | 32 var old = items[item]; |
33 item = item - 1; | |
34 if (item == -1) { | |
35 item = 0; | |
36 return; | |
37 } | |
38 var target = items[item]; | |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
39 var an = new animate.scale(app,old,1,1/1.5,0.1); |
855 | 40 an.start(); |
41 an = new animate.scale(app,target,1,1.5,0.3); | |
42 an.start(); | |
752 | 43 }); |
44 | |
820 | 45 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
855 | 46 var old = items[item]; |
47 item = item + 1; | |
48 if (item == items.length) { | |
49 item = item - 1; | |
50 return; | |
51 } | |
52 var target = items[item]; | |
857
ea1e88c40548
Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents:
856
diff
changeset
|
53 var an = new animate.scale(app,old,1,1/1.5,0.1); |
855 | 54 an.start(); |
55 an = new animate.scale(app,target,1,1.5,0.3); | |
56 an.start(); | |
845 | 57 }); |
58 | |
847 | 59 app.addKeyListener(mbapp.KEY_UP, function() { |
855 | 60 var old = lines[line]; |
61 line = line - 1; | |
62 if (line == -1) { | |
63 line = 0; | |
64 return; | |
65 } | |
66 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
|
67 var sy = target.center.y - lightbar.center.y; |
855 | 68 sys.puts(sy); |
69 var an = new animate.linear(app,lightbar,0,sy,0.3); | |
70 an.start(); | |
847 | 71 }); |
72 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
855 | 73 var old = lines[line]; |
74 line = line + 1; | |
75 if (line == lines.length) { | |
76 line = line - 1; | |
77 return; | |
78 } | |
79 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
|
80 var sy = target.center.y - lightbar.center.y; |
855 | 81 sys.puts("line="+line); |
82 sys.puts("sy="+sy); | |
83 sys.puts("target.y="+target.center.y); | |
84 sys.puts("lightbar.y="+lightbar.center.y); | |
85 var an = new animate.linear(app,lightbar,0,sy,0.3); | |
86 an.start(); | |
847 | 87 }); |
845 | 88 |
89 app.addKeyListener(mbapp.KEY_ENTER, function() { | |
855 | 90 var target = items[item]; |
91 var sx = 500 - target.center.x; | |
92 var sy = 220 - target.center.y; | |
93 sys.puts("target "+sx+','+sy); | |
94 var an = new animate.linear(app,target,sx,sy,1); | |
95 an.start(); | |
96 for(i=0;i<items.length;i++) { | |
97 if (i == item) continue; | |
98 var x = Math.random(); | |
99 var y = Math.random(); | |
100 if (x > 0.5) x = 900; | |
101 else x = -500; | |
102 if (y > 0.5) y = 900; | |
103 else y = -500; | |
104 sx = x - items[i].center.x; | |
105 sy = y - items[i].center.y; | |
106 an = new animate.linear(app,items[i], sx,sy,2); | |
845 | 107 an.start(); |
855 | 108 alpha = new animate.alpha(app,items[i],0, 1); |
109 alpha.start(); | |
110 } | |
752 | 111 }); |
112 | |
113 app.loop(); |