News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First < Previous 1 [2] Last »
someone with mad math skills, help please
Author Message
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #11
RE: someone with mad math skills, help please

Yep at 1440 x 900 it gets empty, then suddenly fills in all at once.

The second time it did this, most of the particles appeared in
two or three groups of blocks from the lower left side, instead
of a random all over the screen effect that the script starts with.

01-25-2008 05:56 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #12
RE: someone with mad math skills, help please

The grouping is intentional (although it often gets too dense) in order to display nebulae.
One of the other "features" of this is that there is a set number of dots. If you avoid coming into contact with them, they will eventually converge into one point. Touch that point and the dots are sprayed back on or outside the screen.

Still not satisfied with it, but I'm setting it aside for now to get back to some other projects.
I did make a change to hopefully spread the dots according to your screen size, and made that initial block of white dots blend in.

PHP Code:
balls=1500 -- number of dots
bsize
=2    -- dot size
max_grav
=-- maximum gravity
hole
=20    -- distance from cursor within which dots warp

function grav_loop()
local my_x,my_y=Fl:event_x(),Fl:event_y() -- cursor location
local xspeed
,yspeed,bx,by -- initialize some local vars
local c
=math.random(1,255) -- random color (except black)
  for 
i=1,balls do
    -- 
find distance of dots from the cursor
    local xdistance
=math.abs(my_x-ball[i]:x()) -- horz distance from cursor
    local ydistance
=math.abs(my_y-ball[i]:y()) -- vert distance
    local distance
=math.sqrt(xdistance^2+ydistance^2) -- as the crow flies
    
if distance <= hole then
      ball
[i]:color(c) -- set the color of the dot about to be warped
      
-- These equations have no defined mathematical logic behind them.
      -- 
I was just playing with numbers until something cool happened.
      -- 
xspeed and yspeed are actually distance measurements (how far to move the dot in one loop)
      -- 
random offset prevents the dots from eventually converging on a single x-y intersection
      xspeed
=xdistance*w:w()/distance/1.5+math.random(-100,100)
      
yspeed=ydistance*w:h()/distance/1.5+math.random(-100,100)
    else
      -- 
thanks to Juergen for help with this
      xspeed
=max_grav/distance*xdistance
      yspeed
=max_grav/distance*ydistance
    end
    
-- move the dot according to its relative position to cursor
    
if my_x ball[i]:x() then bx=ball[i]:x()+xspeed else bx=ball[i]:x()-xspeed end
    
if my_y ball[i]:y() then by=ball[i]:y()+yspeed else by=ball[i]:y()-yspeed end
    ball
[i]:position(bx,by)
  
end
w
:redraw()
grav_timer:doWait(.05)
end

-- make the window the size of your screen
w
=fltk:Fl_Double_Window(Fl:w(),Fl:h(),"gravity test")
w:color(0)

math.randomseed(os.time()) -- set a seed for upcoming math.random()
-- 
set up dots in random locations
ball
={}
for 
i=1,balls do
ball[i]=fltk:Fl_Box(math.random(-300,w:w()+600),math.random(-300,w:h()+600),bsize,bsize)
ball[i]:box(fltk.FL_FLAT_BOX)
ball[i]:color(math.random(1,255))
end

grav_timer 
murgaLua.createFltkTimer()
grav_timer:callback(grav_loop)
grav_timer:do_callback()

w:fullscreen()
w:show()
w:cursor(66) -- cross
Fl
:run() 

This post was last modified: 02-02-2008 01:27 AM by mikshaw.

01-26-2008 02:38 AM
Find all posts by this user Quote this message in a reply
Pages (2): « First < Previous 1 [2] Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: