mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Jan. 23 2008,13:32 |
|
I posted beta1 of the murgaLua widgets collection last night, over at Murga's place, and the 3 stages of gravity tests up to this point have been included.
I still want to improve it over time, maybe turn it into some sort of interactive screensaver thing, and have to work out some kinks.
Code Sample | #!/bin/murgaLua
balls=250 bsize=10
function grav_loop() local my_x,bx=Fl:event_x(),0 local my_y,by=Fl:event_y(),0 local c=math.random(1,255) local b=math.random(1,balls) ball[b]:color(c) for i=1,balls do local xdistance=math.abs(my_x-ball[i]:x()) local ydistance=math.abs(my_y-ball[i]:y()) local distance=math.sqrt(xdistance*xdistance+ydistance*ydistance) local speed=max_slider:value()/distance if distance > 0 then if my_x > ball[i]:x() then bx=ball[i]:x()+speed else bx=ball[i]:x()-speed end if my_y > ball[i]:y() then by=ball[i]:y()+speed else by=ball[i]:y()-speed end ball[i]:position(bx,by) end end w:redraw() grav_timer:doWait(.05) end
w=fltk:Fl_Double_Window(640,480,"gravity test") w:color(0) fltk.fl_define_FL_OVAL_BOX() math.randomseed(os.time()) max_x=w:w()-bsize max_y=w:h()-bsize ball={} for i=1,balls do ball[i]=fltk:Fl_Box(math.random(1,max_x),math.random(1,max_y),bsize,bsize) if fltk._FL_OFLAT_BOX then ball[i]:box(fltk._FL_OFLAT_BOX) else ball[i]:box(fltk.FL_OFLAT_BOX) end end
max_slider=fltk:Fl_Hor_Value_Slider(0,w:h()-20,w:w(),20) max_slider:minimum(50) max_slider:maximum(5000) max_slider:value(500) max_slider:step(10)
grav_timer = murgaLua.createFltkTimer() grav_timer:callback(grav_loop) grav_timer:do_callback()
w:show() Fl:run()
|
Edit: I replaced the plastic with a flat oval box after seeing how poorly it runs in fullscreen
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|