This simulation needs WebAssembly, and it could not start in this browser.
The image is a frame from a real run. Check that JavaScript is on, or try another browser.
A box of hard discs that only ever collide is the oldest model of a gas. James Clerk Maxwell used it in 1860 to derive the distribution of molecular speeds, and Ludwig Boltzmann in 1872 to show that collisions drive any gas toward that distribution. No forces act at a distance and nothing random happens: every collision conserves momentum and energy exactly. Even so the gas forgets where it started, and when its walls are kept at different temperatures, heat flows through it from hot to cold.
What you see
Discs in an 800 by 800 pixel box, colored from white (slow) to red (fast) relative to the fastest disc; the Speed histogram switch adds an inset with their speed distribution. The panel shows the temperature of the gas, per disc in units of the walls’ neutral temperature, and the total momentum .
Every run starts with all discs at the same speed, 150 px/s, in random directions. Collisions spread the speeds out: after 5 seconds the distribution is already broad, and within about 20 seconds it reaches the two-dimensional Maxwell distribution.
Model
Each step moves every disc in a straight line for s, then resolves the contacts. Two discs that touch while approaching exchange the components of their velocities along the line joining their centers, which for equal masses conserves momentum and kinetic energy exactly; the tangential components are kept. A plain wall reflects a disc. A wall at temperature is a thermal wall: it sends the disc back with a new normal speed drawn from the distribution of molecules leaving a wall at , and so heats or cools the gas.
In equilibrium the speeds follow the 2D Maxwell distribution
with . One temperature unit is the gas’s starting temperature, .
Presets
Default: 100 discs of radius 8 between plain walls. Energy and, between wall hits, momentum stay exactly constant; the speeds relax to the Maxwell distribution in about 20 seconds.
Dilute gas: 50 discs of radius 12. Long straight flights between rare collisions: after a minute the speed distribution has still not fully relaxed.
Dense gas: 300 small discs with periodic edges instead of walls, so the total momentum stays exactly constant. Collisions are frequent and the gas relaxes within about 5 seconds.
Hot walls: all walls at temperature 2. The gas heats up from the edges inward and settles at about 2 within 20 seconds.
Cold walls: all walls at 0.1. The gas cools to about 0.2 within 20 seconds and to 0.14 after a minute.
Thermal gradient: the bottom wall at 3, the top wall at 0.3, the side walls plain. Heat flows through the gas from bottom to top and a steady gradient forms: after a minute the lower third runs at about 2.2 and the upper third at about 0.8. At equal pressure a colder gas is denser, and the upper third holds about one and a half times as many discs as the lower one.
Parameters
Discs: 5 to 500; applies on Reset.
Radius (px): 3 to 20, sets the collision rate; applies immediately.
Periodic edges: discs leaving one edge enter at the opposite one, so there are no walls.
Wall temperature: 0 to 3, for all four walls; 1 is a plain reflecting wall.
Top wall and bottom wall: 0 to 5, overriding the wall temperature for that wall; 1 means it follows the wall temperature.
The force sliders push every disc with a uniform acceleration, like gravity.