Mercurial > MadButterfly
annotate nodejs/testsvg.js @ 937:191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 12 Nov 2010 16:54:48 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
775
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
775
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
714 | 3 var svg = require("./svg"); |
716 | 4 var mbapp = require("./mbapp"); |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
5 var sys=require("sys"); |
727 | 6 var animate=require("./animate"); |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
7 var fs = require("fs"); |
714 | 8 |
716 | 9 app = new mbapp.app(); |
10 app.loadSVG("test.svg"); | |
723
8af3b87b502e
Correct syntax if a statement
Thinker K.F. Li <thinker@branda.to>
parents:
722
diff
changeset
|
11 lightbar = app.get("item_lightbar"); |
8af3b87b502e
Correct syntax if a statement
Thinker K.F. Li <thinker@branda.to>
parents:
722
diff
changeset
|
12 item=1; |
937
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
13 var target = app.get("item" + item); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
14 sys.puts(lightbar.center.x); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
15 sys.puts(lightbar.center.y); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
16 lightbar.center.move_pnt(target.center); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
17 // lightbar[5] = app.get("item"+item)[5]; |
722
f95d58a8edd1
Add javascript-based animation test program. We should make it as module in the future.
wycc
parents:
721
diff
changeset
|
18 |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
19 app.files=fs.readdirSync("/tmp/"); |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
20 for(i=1;i<10;i++) { |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
21 var o = app.get("item"+i+"text"); |
937
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
22 o.set_text(app.files[i]); |
732
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
23 } |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
24 |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
25 |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
26 |
6879aa403306
Add set_text to the coordinate of the coord_t of the text.
wycc
parents:
730
diff
changeset
|
27 |
730 | 28 app.addKeyListener(mbapp.KEY_UP, function() { |
937
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
29 item = item - 1; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
30 if (item == 0) |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
31 item = 1; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
32 else { |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
33 var target = app.get("item"+item); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
34 var shx = target.center.x - lightbar.center.x; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
35 var shy = target.center.y - lightbar.center.y; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
36 var action = new animate.shift(app, lightbar, shx, shy); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
37 var an = new animate.linear(action, 0, 0.3); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
38 an.start(); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
39 } |
730 | 40 }); |
41 | |
42 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
937
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
43 item = item + 1; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
44 if (item == 10) { |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
45 item = 9; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
46 } else { |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
47 var target = app.get("item"+item); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
48 var shx = target.center.x - lightbar.center.x; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
49 var shy = target.center.y - lightbar.center.y; |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
50 var action = new animate.shift(app, lightbar, shx, shy); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
51 var an = new animate.linear(action, 0, 0.3); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
52 sys.puts(target.center.y); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
53 sys.puts(lightbar.center.y); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
54 an.start(); |
191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
55 } |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
56 }); |
730 | 57 |
716 | 58 app.loop(); |