This code continues the previous blog post on two-dimensional collisions to model Brownian motion. The code is on GitHub page ‘https://github.com/xnx/collision’.
The core classes, PeriodicParticle and PeriodicSimulation are derived from the original Particle and Simulation classes to allow periodic boundary conditions: instead of bouncing off the walls, the particles move through them and reappear at the other side of the domain.
In the example given here, the mass of the large particle is set to be equal to that of the small ones, so that it gains enough momentum quickly to be seen to move in the animation. This can be altered by setting the mass property of the PeriodicParticle class.