Mercurial > MadButterfly
changeset 722:f95d58a8edd1
Add javascript-based animation test program. We should make it as module in the future.
author | wycc |
---|---|
date | Sun, 15 Aug 2010 19:44:09 +0800 |
parents | 01d02382dea7 |
children | 8af3b87b502e 503f3d18248e |
files | nodejs/testsvg.js |
diffstat | 1 files changed, 33 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/testsvg.js Sun Aug 15 19:07:36 2010 +0800 +++ b/nodejs/testsvg.js Sun Aug 15 19:44:09 2010 +0800 @@ -7,17 +7,45 @@ lightbar = app.get("item_lightbar") item=1 lightbar[5] = app.get("item"+item)[5] + +function animated(app,obj) { + var d=obj.animated_loc - obj[5]; + var dd=d; + if (dd<0) dd = -dd; + + if (dd > 5) { + if (d > 0) d = 5; else d = -5; + } + + obj[5] += d; + sys.puts(d); + app.refresh() + if (dd > 1) { + setTimeout(function() { animated(app,obj);}, 20); + return; + } + app.animated_end = 1; +} +function animated_start(app,obj,target) { + if (obj.animated_end==0) + obj[5] = obj.animated_loc; + obj.animated_loc = target[5]; + obj.animated_end = 0; + animated(app,obj); +} +lightbar.animated_loc = 1; app.addKeyboardListener(6, function(evt) { if (evt.keycode == mbapp.KEY_UP) { item = item - 1; - if (item == 0) item = 9; - lightbar[5] = app.get("item"+item)[5] + if (item == 0) item = 1; + else + animated_start(app,lightbar,app.get("item"+item)); } else if (evt.keycode == mbapp.KEY_DOWN) { item = item + 1; if (item == 10) { - item = 1; - } - lightbar[5] = app.get("item"+item)[5] + item = 9; + } else + animated_start(app,lightbar,app.get("item"+item)); } }); app.loop();