Epidemic-simulation – Visual Epidemic Model in C++

Epidemic simulation

About

epidemic-simulation is a solo project developed in C++ with SFML over the span of a week. Inspired by a video by Primer (Link here), the simulation visualizes the spread of a disease within a population through individual interactions, daily movement, and generational immunity.

This project marked my first real exploration of C++ programming and class-based architecture. While I made several structural mistakes (e.g. heavy logic inside .hpp files), it was a crucial stepping stone in understanding object-oriented programming through visual experimentation.

🧪 The simulation demonstrates infection dynamics, daily routines, and herd immunity progression – all in real time.


Project Info

  • Role: Solo Developer
  • Duration: 1 week
  • Language: C++
  • Graphics: SFML

🎮 Introduction

Each individual is represented as a colored circle:

  • 🟥 Red – Infected
  • ⚫ Black – Dead
  • 🟩 Green – Immune
  • 🩶 Gray – Healthy (not yet infected)

Every character is assigned a home (blue square) they return to each night. During the day, they visit different locations (e.g. work, supermarket), where infection can spread. The infection chance increases significantly in crowded locations, especially at home.

🏠 When an individual dies, a new one spawns immediately – potentially immune from birth. Immunity is inheritable, allowing natural resistance to spread through generations.


🧠 Simulation Features

Infection Mechanics
  • Contagion spreads during contact in shared locations
  • Each infected individual carries a % chance of infecting others
Lifecycle
  • After X days of life, the entity dies and gives birth to a newborn (a child).
  • Each new entity has a chance to be immune
  • Immune individuals cannot be re-infected
Real-Time Graph
  • A graph at the bottom of the screen dynamically shows:
    • % Infected
    • % Dead
    • % Immune
Simulation Controls
  • UI buttons to control:
    • Population count
    • Infection/mortality rates
    • And more
  • Control time speed
  • Start a new simulation

🎨 Design & Challenges

This project was my introduction to C++. I explored:

  • Basic use of classes and SFML graphics
  • Improvised UI creation with clickable buttons
  • Real-time updates and data visualization
  • Object interaction modeling (people, buildings, infection zones)

⚠️ Structurally, the project wasn’t great. I was developing the class code directly in the header. I quickly changed this in my subsequent projects for greater readability.


📤 Download & Source Code

👉 Available on GitHub:
https://github.com/ArthuryanLoheac/epidemic-simulation


📚 What I Learned

  • Basic principles of C++ class
  • Integrating graphics and interactivity using SFML
  • How to visualize simulations with meaningful metrics
  • Real-time data updates with minimal performance cost
  • The importance of separating logic from UI and visuals
  • How small parameter changes can produce drastically different systemic outcomes

💡 This project gave me my first hands-on taste of simulation design and laid the groundwork for all my future C++ projects.