[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] looking for a particle/billiard ball engine



On 1/4/06, Miles Van Pelt <milesvp@xxxxxxxxxxx> wrote:
>
> I'm looking to experiment with some simple emergent behavior ideas. Does
> anyone have a favorite particle simulator, or otherwise know where I can
> find the source to a simple engine that uses newtonian physics for particle
> interaction?

I've been work on something like this for the past few days... it may
be too simple for your purpose, but I've successfully used it to push
and spin images around. The collision detection stuff is also a bit
brutish and rather inadequate atm, but you may find something useful.
It uses Numeric.

http://metaplay.dyndns.org:8081/svn/sigl/trunk/SiGL/physics.py

I wrote this because I wanted a 2D specific physics simulator.

Basic usage is:

    world = physics.World(number_of_potential items_to_simulate)

then:

   body = world.Body(sprite)

where sprite is an object which must have a position and rotation attribute.

you can then call things like:

    body.apply_torque(v)

or:

    body.apply_force((x,y))

after that, for each frame, call:

    world.tick(number_of_seconds_to_simulate)

which will update all the bodies with updated position and rotation.

This is not an accurate simulation in any way, it is based on my owned
flawed understanding of Newtonian physics, but it is useful for
spinning and pushing things around the screen. :-)


-Sw.