Pandemic Modeling: Can you flatten the curve?

Since 2019, COVID-19 (caused by coronavirus SARS-CoV-2), has affected millions of people worldwide. Public Health officials have responded by enforcing stay-at-home orders and various social distancing techniques to slow the spread of the virus. Which social distancing measures are the most effective? Ingraham High School’s Girl’s Who Code Club (IHS GWC) decided to model how the coronavirus spreads within a population in PyGame. Build on their code and learn the best methods to flatten the curve.

What does it mean to flatten the curve?

Flattening the curve means slowing the rate of infection so that the number of people requiring medical care does not exceed the capacity of the healthcare system in order to prevent deaths. Watch this youtube video to learn more about reducing the spread of the coronavirus.

Pandemic Model

How do you begin to create a pandemic model?

Think of the pandemic as a system of interacting parts and pieces. IHS GWC students brainstormed the features of a basic pandemic model:


  • Individuals: healthy, sick, dead, and recovered

  • Infection rate

    • How much are individuals interacting?

    • How many individuals are asymptomatic?

  • Recovery Rate


From this, they created a model using PyGame, a python based platform for building video games.


How does the simulation work?

You start out with a group healthy individuals and one sick person in the population. With no preventative measures in places, the virus spreads within the population given the defined infection rate. The sick population then starts to recover given the defined recovery rate.

disease-model-fast-video.mp4

While the simulation is running it produces a curve of infected people over time.



You can adjust the simulation by changing the features within PyGame. Here is an example of the individuals interacting less. The likelihood of collision was decreased through slower movement, and smaller radii.

disease-model-slow-video.mp4

Here you can see it takes about 3 times as long for everyone in the population to recover, but there are fart fewer people infected at a time.

Now it is time for you to run the simulation on your own. You can access the code for the simulation here.

To run this code, you will need to download python and install the PyGame module (more detailed instructions for installing modules in python can be found here).

Once you have the code running, check your understanding of the code by adjusting existing features.

Improving the Model

Now that we have seen how certain features can flatten the curve, it is time to improve the model and implement different social distancing techniques to determine the best method to flatten the curve. Here are some suggested features to try:


  • Model different social distancing techniques (individuals have a social distancing bubble)

  • Create a shopping mall senario with one way lanes

  • Quarantining (individuals kept apart by barriers)

  • Model immunocompromised particles (higher infection and death rate)

  • Vary the amount of time particles can be sick

  • Add Additional graphs/analysis

  • Incorporate statistical bootstrapping methods into creating a curve for your scenario.

Students, please take this 1-minute survey, now that you've completed this activity. We are interested in learning about your experience so we can improve these resources. All responses to this survey are anonymous, all questions are optional, and your feedback is much appreciated.

Curriculum Contributors and Supporters

Kirsten Graham: Ingraham High School Senior, GWC President
Vivian White: Ingraham High School Senior
Ella Wiegman: Ingraham High School Junior
Rachel Calder: Education Coordinator, ISB

Funding to support the development of this lesson was provided by the National Science Foundation Award DBI-1565166 & 0640950. The content of these pages was created by students for students with the help of teachers and scientists. The views expressed herein are those of the authors and do not necessarily reflect the views of NSF or ISB.