Back to portfolio
simulation2025

Epidemic Simulation

Real-time SIR disease spread simulation with vaccination zones, lockdowns, and virus variants

HTML5 CanvasJavaScriptCSS
Personal Project
2025
Epidemic Simulation

Overview

A real-time 2D epidemic simulation using an SIR model variant. Agents transition through Susceptible, Infected, Recovered, and Dead states on a dark canvas with glowing infection radii and pulsing rings. Place vaccination zones to immunize survivors, trigger lockdowns to flatten the curve, and introduce virus variants mid-simulation to watch competing strains battle for dominance.

Challenge

Modeling realistic disease dynamics requires balancing transmission parameters — R₀, mortality rate, infection duration, radius — where small tweaks produce wildly different outcomes. The simulation needed real-time interactivity so users can intervene with public health measures and immediately see their impact on the outbreak curve.

Solution

Built as a single-file vanilla JavaScript application with zero dependencies. Agents move with configurable speed on an HTML Canvas, transmitting infection within a visual radius. A full control panel exposes 10+ parameters for tuning outbreak behavior. Vaccination and lockdown zones are placed interactively on the canvas. Virus variants spawn with randomized R₀, mortality, and duration multipliers, each rendered with a distinct color. Real-time R_eff tracking and population charts visualize the epidemic curve.

Results

The simulation produces intuitive demonstrations of epidemiological concepts — herd immunity thresholds, the effect of lockdowns on R_eff, how variants with higher transmissibility outcompete existing strains, and why early intervention dramatically changes outcomes. The dramatic red infection haze visualization makes outbreak severity immediately visceral.

Key Features

01SIR model with Susceptible → Infected → Recovered/Dead state transitions
02Virus variants with randomized R₀, mortality, and duration multipliers
03Placeable vaccination zones that gradually immunize passing agents
04Global lockdown toggle and placeable lockdown zones
05Real-time R_eff tracking and population line charts
06Full control panel with 10+ configurable parameters
07Visual infection radius glow and pulsing ring effects
08Day counter and live S/I/R/D population counts
09Zero dependencies — single HTML file, no build step

Gallery

Epidemic Simulation — early outbreak with susceptible, infected, and recovered agents