annotate nodejs/examples/testsvg/testsvg.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/testsvg.js@191d3a5f74c8
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
939
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 937
diff changeset
3 var svg = require("svg");
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 937
diff changeset
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");
939
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 937
diff changeset
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
f53e45d1fcd0 Translate the svg.js as a nodejs module.
wycc
parents:
diff changeset
8
716
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
9 app = new mbapp.app();
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
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 lightbar.center.move_pnt(target.center);
722
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
15
732
6879aa403306 Add set_text to the coordinate of the coord_t of the text.
wycc
parents: 730
diff changeset
16 app.files=fs.readdirSync("/tmp/");
6879aa403306 Add set_text to the coordinate of the coord_t of the text.
wycc
parents: 730
diff changeset
17 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
18 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
19 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
20 }
6879aa403306 Add set_text to the coordinate of the coord_t of the text.
wycc
parents: 730
diff changeset
21
6879aa403306 Add set_text to the coordinate of the coord_t of the text.
wycc
parents: 730
diff changeset
22
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
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
25 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
26 item = item - 1;
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
27 if (item == 0)
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
28 item = 1;
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
29 else {
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
30 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
31 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
32 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
33 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
34 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
35 an.start();
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
36 }
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
37 });
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
38
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
39 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
40 item = item + 1;
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
41 if (item == 10) {
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
42 item = 9;
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
43 } else {
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
44 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
45 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
46 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
47 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
48 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
49 an.start();
191d3a5f74c8 Migrate testsvg.js to new interface of shift action.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
50 }
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
51 });
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
52
716
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
53 app.loop();