Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
938:13b9acbbe9a3 | 939:a74b4d986a91 |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
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("test.svg"); | |
11 lightbar = app.get("item_lightbar"); | |
12 item=1; | |
13 var target = app.get("item" + item); | |
14 lightbar.center.move_pnt(target.center); | |
15 | |
16 app.files=fs.readdirSync("/tmp/"); | |
17 for(i=1;i<10;i++) { | |
18 var o = app.get("item"+i+"text"); | |
19 o.set_text(app.files[i]); | |
20 } | |
21 | |
22 | |
23 | |
24 | |
25 app.addKeyListener(mbapp.KEY_UP, function() { | |
26 item = item - 1; | |
27 if (item == 0) | |
28 item = 1; | |
29 else { | |
30 var target = app.get("item"+item); | |
31 var shx = target.center.x - lightbar.center.x; | |
32 var shy = target.center.y - lightbar.center.y; | |
33 var action = new animate.shift(app, lightbar, shx, shy); | |
34 var an = new animate.linear(action, 0, 0.3); | |
35 an.start(); | |
36 } | |
37 }); | |
38 | |
39 app.addKeyListener(mbapp.KEY_DOWN, function() { | |
40 item = item + 1; | |
41 if (item == 10) { | |
42 item = 9; | |
43 } else { | |
44 var target = app.get("item"+item); | |
45 var shx = target.center.x - lightbar.center.x; | |
46 var shy = target.center.y - lightbar.center.y; | |
47 var action = new animate.shift(app, lightbar, shx, shy); | |
48 var an = new animate.linear(action, 0, 0.3); | |
49 an.start(); | |
50 } | |
51 }); | |
52 | |
53 app.loop(); |