Programming and Scripting :: some math help please?



Well at least the one based on my last "patch" doesn't seem to have the "line-grav" anymore...
Code Sample
-- based on last code "patch"
 if distance <= 25 then -- warp it offscreen
   ball[i]:color(b)
-- delete old 2 lines, add
   if math.random(0,1) == 0 then
      bx = math.random(0,1)*max_x
      by = math.random(1,max_y)
   else
      bx = math.random(1,max_x)
      by = math.random(0,1)*max_y
   end
 end
This one make them warp offscreen, but looks 'square-ish' unless you add an additional offset to it (due to choosing a coordinate on the edges of the window box).  Not sure how many random()'s you'd want to use.

My previous post's warp just copied the random code that was used at the start where it chooses a coordinate anywhere in the window.

Quote
This one make them warp offscreen, but looks 'square-ish' unless you add an additional offset to it (due to choosing a coordinate on the edges of the window box).  Not sure how many random()'s you'd want to use.
That's exactty the issue I was trying to solve from my most recent test (I'm up to version "3e" now)

btw, color(b) is a typo. The b variable was a leftover from a previous script. The color should be c

mikshaw, Thanks for posting/sharing. It is really cool!
I have played with things like this on and off dating back to 1992.
One thing i like to do is use sin() to move the object more slowly as it reaches its objective or move it in a non-strait line.  logrithems behave similarly but a different pattern.
i also like to reposition the object to a random location at a random time with the odds of it being repositioned increasing as it gets closer to the objective.  this can be done with a simple
Code Sample
(Distance From Objective) < (Random Number)

And this random number would not need to be generated again until the object reaches it.  This can reduce the number of objects close together where their all headed to.
You can also weight the occurences of where it is repositioned(maybe you want more to end up at the edge of the screen).

Sorry this is pretty general, but i dont recognise enough of the sytnax to give good code.  maybe it might give you some ideas.

sparks


original here.