Description
Simulation of the random walk of one or more particles in two dimensions. At each step, a particle moves in one of four directions—up, down, left, or right—chosen at random, with a 25% probability for each direction.
Controls
In the default mode, a single particle walks continuously across the canvas from the center, leaving a trail. The "Generate final positions" button (in the "Parameters" panel) calculates the final position of N particles after a fixed number of steps at once and displays only the endpoints; clicking "Start" from this mode resumes the single particle. The "Graph" panel shows a histogram of the generated particles' horizontal positions.
Physical model
At each step, the particle moves a fixed distance $\ell$ (the "Step size" parameter) in a direction randomly selected from the four possibilities, with no memory of previous steps. After $N_{passos}$ steps, the mean-square displacement of an ensemble of particles grows linearly with the number of steps,
$$
\langle r^2 \rangle = N_{passos}\,\ell^2,
$$
which is characteristic of a diffusive process. The histogram in the "Graph" panel shows the distribution of the final horizontal position of the $N$ generated particles, which approaches a Gaussian distribution centered at the origin as $N_{passos}$ increases (central limit theorem).
Developers
Marco P. M. de Souza
References
S. Salinas, Introdução à Física Estatística (EDUSP, 2013).