Particles in a box!

My latest code at http://www.math.ntnu.no/~stacey/HowDidIDoThat/iPad/Codea.html is a particle-in-a-box simulator. They bounce around off the walls and each other; their colour changes depending on their speed (not in a physically realistic manner); and if you want then you can allow them to escape out of the box if they get enough energy. The particles are created by touching the screen, and they can be given an initial velocity by “flicking” the screen.

(Earlier versions had some fun bugs whereby particles could get “entangled” - they got locked in an eternal collision. It was quite fun, but physically unrealistic. If anyone wants, I could explain which lines to comment out to restore this behaviour!)

The particles all have the same mass and the collisions are totally elastic. Those could be things to vary. Could also allow gravity to have an effect: get all the particles clumped at one end and then give the iPad a darned good shaking to get them moving again.

Awesome!

Be fun to add temperature and some thermodynamics. Moving walls that impart momentum? Gas law demonstrator?

This is cool, makes me want to play billiards :slight_smile: