This Java applet simulates a 2 dimensional gas of hard spheres. It illustrates several important concepts in statistical mechanics/kinetic theory, such as: mean free path and average time between collisions, the approach to thermal equilibrium and the Maxwell-Boltzmann speed distribution, and the question of macroscopic irreversibility vs. microscopic reversibility.
To use the applet, enter a number in the text field, click "Set", then click "Run." The "molecules" are spheres of radius one pixel (the default value; you can change the radius to two pixels by clicking in the "Make particles bigger" box) and do not interact except when they come in contact; then they scatter elastically. The small box on the right shows the distribution of speeds as the collisions take place. The blue line is the theoretical result for an ideal gas in thermal equilibrium--a two dimensional Maxwell-Boltzmann distribution.
Left to itself, the simulation will run for a long time; you will probably want to click "Stop" at some point. After the animation stops, you can check the microscopic reversibility of this system by clicking on "Reverse." This flips around all the velocities of the particles and runs the system for a time equal to the time it had run previously. In principle, that should "undo" every collision and restore the initial distribution of positions and velocities. You can see how roundoff error prevents this from happening after a sufficiently large number of collisions per molecule have taken place.
You'll find that the reversibility depends on the number of collisions per particle. (Keep in mind that when the number of collisions equals the number of particles, each particle has collided twice, on average.) The very fast propagation of roundoff error with each collision (extreme sensitivity to initial conditions) is an indication of chaos in this system.
How fast the speed distribution approaches the steady state seems to depend also on the number of collisions per particle. Check out also how the the relative size of the fluctuations about the steady state distribution is greater for fewer particles.
If you're interested in quantitative estimates, you will find a lot more information on the physics of this system on this other page!
If you have a really fast computer, you may want to slow down the animation. You may also experience some trouble with the "Number of collisions" and "Time elapsed" fields getting overwritten and not being erased properly. Clicking on "Pause" should clean them up.
Later on in the future I would like to do another applet showing how two different gases of hard spheres attain thermal equilibrium through their mutual interaction.
The algorithm for the hard-sphere dynamics was taken from the book An Introduction to Computer Simulation Methods, by Harvey Gould and Jan Tobochnik (Addison-Wesley, 2nd edition, 1996). Follow that link for further online resources!
This is my second-ever Java applet. The first one was a demonstration of vector addition; you can find it here. If you are interested in the source code, e-mail me (Julio Gea-Banacloche, email@example.com). Warning: I'm a physicist, not a professional programmer, so you'll find that my programming style is anything but exemplary!
Lastly, if you own a Macintosh you can download a prototype version of this applet here!