💨 2D Particle Diffusion — Random Walk & Fick's Law
2D particle diffusion simulation with real Brownian random walk, optional hard-disk collisions, a live concentration histogram, and a measured diffusion coefficient compared to the Fick's-law Gaussian prediction.
About 2D Particle Diffusion — Random Walk & Fick's Law
This simulation runs a genuine two-dimensional random walk: hundreds of particles each take an independent Gaussian-distributed step every frame, the same microscopic rule that generates Fick's second law, ∂C/∂t = D∇²C, at the macroscopic scale. Starting from a point source, a compact blob, or two separated species, the particles spread out while the simulation tracks their real mean-squared displacement and back-calculates a diffusion coefficient D from ⟨r²⟩ = 4Dt — the 2D form of Einstein's relation. A live histogram of particle positions along the x-axis is plotted against the analytic Gaussian solution of the diffusion equation, so you can see the measured concentration profile and the theoretical prediction track each other in real time. An optional hard-disk collision mode adds excluded-volume interactions between particles, showing how crowding slows the effective spreading rate compared to ideal, non-interacting Brownian motion.
Working in two dimensions instead of three keeps every particle visible at once and makes the concentration profile easy to read directly off the canvas, while still obeying exactly the same diffusion equation that governs pollen grains in water, ink in a glass, or dopants in a wafer — only the geometric prefactor between mean-squared displacement and D changes (4Dt in 2D versus 6Dt in 3D).
Frequently Asked Questions
How is this different from a simple "spreading dots" animation?
Every particle actually performs an independent Gaussian random walk each frame — the step lengths are drawn from a normal distribution, not a fixed radius or a cosmetic outward drift. The mean-squared displacement is measured from real particle positions relative to their starting points, the diffusion coefficient D is fit from that measurement rather than hardcoded, and the histogram overlay is the closed-form Gaussian solution of ∂C/∂t = D∇²C evaluated with that measured D. If you disable collisions and run for a while, the measured D converges to the value implied by the temperature slider, and the histogram curve tracks the bars almost exactly — that agreement is the physics working, not a scripted effect.
What does the "measured D" and "fit error" readout mean?
Measured D comes from the particles' own mean-squared displacement via D = ⟨r²⟩/(4t), independent of the histogram. The fit error compares the live x-position histogram to the best-fit Gaussian of that same measured D and reports the root-mean-square deviation between the two curves, normalised by the peak — a small percentage means the population is behaving exactly as the ideal diffusion equation predicts; a larger one (especially with collisions enabled, at very low particle counts, or once the particles have piled up against the walls) shows where the ideal continuum approximation breaks down.
What does enabling hard-disk collisions change?
With collisions off, particles are ideal points that pass through one another — pure, textbook Brownian motion. With collisions on, particles carry a finite radius and are pushed apart whenever they overlap after a step, an excluded-volume correction used in real Brownian dynamics simulations of crowded systems (like proteins diffusing inside a cell). Crowding measurably slows the growth of the concentration profile's width and increases scatter in the measured D, which is exactly the "crowding subdiffusion" effect studied in molecular biophysics.
Why does 2D use ⟨r²⟩ = 4Dt instead of 6Dt?
The mean-squared displacement of a random walk grows as ⟨r²⟩ = 2dDt, where d is the number of spatial dimensions. In three dimensions d = 3, giving 6Dt (as in the companion 3D diffusion simulation); confined to a plane, d = 2, giving 4Dt. Each independent coordinate (x or y) individually satisfies a 1D diffusion equation with variance growing as 2Dt, and summing the two perpendicular contributions gives the 4Dt total.
How is the theoretical Gaussian curve actually computed?
For a source with initial spread σ₀ centred at x₀, the diffusion equation's solution along one axis is a Gaussian whose variance grows linearly with time: σ(t)² = σ₀² + 2Dt. The curve drawn on the histogram is C(x,t) = N·exp(−(x−x₀)²/(2σ(t)²)) / (σ(t)√(2π)), scaled to the same bin width as the histogram bars, using the D measured live from the particles' mean-squared displacement rather than the value implied by the temperature slider — so the fit is an honest, independent check, not a tautology.
What real systems does this idealised 2D random walk approximate?
Surface diffusion of adsorbed atoms on a crystal face, lipid and protein diffusion within the two-dimensional plane of a cell membrane, and the spreading of a droplet of dye on the surface of water are all well approximated by 2D Brownian motion. The hard-disk collision mode specifically models the "crowded membrane" regime, where proteins embedded in a lipid bilayer collide with their neighbours often enough to measurably slow their apparent diffusion coefficient below the dilute-limit value predicted by the Stokes–Einstein relation.
Release particles from a point source, a blob, or two separated species on a flat plane and watch a genuine 2D random walk spread them out — with a live histogram measured against the exact Fick's-law Gaussian prediction, and a diffusion coefficient extracted from the particles' own motion in real time.
🔬 What It Demonstrates
Each particle takes independent Gaussian steps in x and y — true 2D Brownian motion. The concentration field obeys ∂C/∂t = D∇²C, whose solution is a Gaussian broadening as σ(t)² = σ₀² + 2Dt. Mean-squared displacement grows as ⟨r²⟩ = 4Dt, giving a live, independently-measured D.
🎮 How to Use
Use Temperature to control the diffusion rate. Pick an initial condition — point source, blob, or two species with a partition — and toggle hard-disk collisions to add real excluded-volume crowding between particles.
💡 Did You Know?
2D and 3D Brownian motion share the same diffusion equation but different mean-squared-displacement prefactors (4Dt vs 6Dt) — exactly why membrane-protein tracking and cytoplasm tracking experiments use different conversion formulas for the same physics.
2D particle diffusion simulation with a real Brownian random walk, optional hard-disk collisions, and a live concentration histogram matched against the Fick's-law Gaussian solution using a diffusion coefficient measured from the particles' own mean-squared displacement.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install