This simulation brings the classic SIR compartmental model to life as a swarm of moving particles, each labelled Susceptible, Infected or Recovered. When an infected particle drifts within roughly 16 pixels of a susceptible one, transmission may occur with a per-frame probability scaled from the transmissibility β. Infected particles recover after an exponentially distributed time of about 1/γ, mirroring the differential equations dS/dt = −βSI, dI/dt = βSI − γI, dR/dt = γI.
The sliders set the population N, transmissibility β, recovery rate γ, the initial number of infected, and the vaccination coverage that removes susceptibles before the outbreak begins. The R₀ box shows the basic reproduction number and the live curve plots Susceptible, Infected and Recovered counts day by day. This is exactly how epidemiologists reason about flattening the curve, herd immunity and when an outbreak will fade.
What is the SIR model?
SIR is a compartmental model of infectious disease that divides a population into three groups: Susceptible (can catch it), Infected (currently contagious) and Recovered (immune). People flow from S to I to R, and tracking how these compartments change over time predicts the shape and size of an epidemic.
How does this particle version work?
Each particle bounces around a box at constant speed. Whenever a susceptible particle comes within about 16 pixels of an infected one, it can become infected based on the transmissibility β. Infected particles automatically recover after a randomised duration tied to the recovery rate γ, turning green and becoming immune.
What does the R₀ number mean?
R₀, the basic reproduction number, is the average number of new infections caused by one infected individual in a fully susceptible population. If R₀ is above 1 the epidemic grows; below 1 it dies out. The display turns red when R₀ is 2 or more and green when it falls below 1.
Transmissibility β sets how easily infection passes during a close contact, so raising it speeds the outbreak. Recovery rate γ sets how quickly infected particles heal; a higher γ means shorter infectious periods. Their ratio drives R₀, so the two together decide whether the disease spreads or fizzles out.
The Vaccination % slider removes that fraction of susceptibles before the simulation starts, shown in purple, and the Vaccinate now button immunises susceptibles mid-run. Vaccinated particles cannot be infected, which shrinks the susceptible pool and can push the effective reproduction number below 1, producing herd immunity.
Herd immunity is reached when enough of the population is immune that each infection produces fewer than one new case on average. The threshold is 1 − 1/R₀. For a disease with R₀ of 4 you need about 75% immunity; for measles with R₀ near 15 you need roughly 93%.
Early on, many susceptibles fuel rapid growth and the infected count climbs to a peak. As susceptibles run low, infections can no longer outpace recoveries and the curve falls. Lowering β or vaccinating reduces and delays the peak, which is what public health measures aim to achieve.
It captures the qualitative behaviour of the SIR equations well, including thresholds, peaks and herd immunity, but it is a teaching model. Real movement is uniform random rather than realistic mobility, β is rescaled to a per-frame probability, and the small particle counts produce more random fluctuation than continuous real-world populations.
When R₀ drops below 1 each infected person passes the disease to fewer than one other on average, so the chain of transmission cannot sustain itself. The infected count declines steadily and the outbreak dies out, often without ever reaching most of the population, which is the goal of containment.
SEIR adds an Exposed compartment for people who have been infected but are not yet contagious, capturing an incubation period. This simulation uses the simpler SIR structure, where infection is immediate, but SEIR is often preferred for diseases like COVID-19 that have a meaningful latent phase before symptoms or contagiousness.
SIR and its extensions underpin much of modern epidemiology, from forecasting seasonal flu and measles outbreaks to guiding vaccination targets and lockdown decisions during pandemics. Similar compartmental maths is also borrowed to model the spread of computer viruses, rumours and product adoption across networks.
Particles spread infection by physical proximity. Tune the transmission rate β, recovery rate γ, vaccination coverage and watch the reproduction number R₀ and epidemic curve evolve in real time.
SIR compartmental model: Susceptible → Infected → Recovered. The basic reproduction number R₀ = β/γ determines whether an epidemic spreads (R₀ > 1) or dies out (R₀ < 1).
Adjust β (transmission rate) and γ (recovery rate). Vaccinate a portion of the population to see herd immunity emerge. Watch the epidemic curve flatten.
Herd immunity threshold = 1 - 1/R₀. For measles (R₀ ≈ 15), 93% vaccination is needed. For seasonal flu (R₀ ≈ 1.3), about 23% is sufficient.