A simulation of a 2D gas


The particles undergoes perfect elastic collisions with each other and the walls.
You can “heat up” the lower wall by pressing W, and cool it down with the S-key.
You can move the left wall with the D- and A-keys. You can pause the simulation and restart it clicking the Esc-key.

You can see the temperature above the graph. This is calculated as the total kinetic energy times a
scale factor
This calculation corresponds to the equation E=(3/2)kT

You can see the pressure both numerically and on a pressure gauge. The pressure is calculated
as an moving average of the sum of the impulses on the right wall.
As you can see the pressure is a statistical phenomena.

If you heat up the gas or cool it down you can see that the T/P will remain somewhat constant.
This is showing that this "gas" obeys Charles's law, T/P=constant.
You many have to wait a few seconds for the value to somewhat stabilize.

The diagram to the right shows the distribution of speeds of the atoms.
All the atoms will initially have the same speed, but the direction of motion is randomized.
You can also see the theoretical 2D Maxwell-Bolzmann distribution i.e. a Rayleigh distribution.