Open Access Research Article

COVID-19 Herd Immunity Simulation with Scratch

Dazhuang Wang1 and Leyu Wang2*

1Fairfax County Public Schools, Virginia, USA

2Center for Collision Safety and Analysis, George Mason University, USA

Corresponding Author

Received Date: February 11, 2021;  Published Date: February 26, 2021


The total infected population in the pandemic is found to be related to the number of risky contacts a person may have per day. COVID-19 will infect the entire population if the average person has one risky encounter per day. The virus is unlikely to spread further if the average person has lower than 0.23 times risky encounter per day. In this study, herd immunity for COVID-19 is simulated with scratch. The vaccine was added later as a factor in the study.


Herd immunity is a concept that is frequently mentioned in COVID-19 pandemic. The idea is that the population, which is exposed and immunized to the virus, will serve as a barrier to prevent further spreading of the disease [1,2]. It is important to know the percentages of total infected population before herd immunity is achieved and the pandemic ends. Under certain conditions, the naturally occurred herd immunity can only occur if everyone is infected with the virus. Previous study of herd immunity assumes a static population, where individual does not move from place to place in simulation [3-5]. The result may underestimate the severity of COVID-19 pandemic.


This study analyzed 100 freely moved people in a square area using simulation. The time scale of one second in simulation represents one day in real life. Each person continuously moves to a random position in n-seconds time. A new random position is given once the old one is reached. The time duration n can be adjusted to represent different social activity level (larger n means less social activity). This semi-random moving pattern is set to represent actual behavior of people in a community. The simulation runs with 0 infected person first to determine the daily risky contact per person. In real life, this means how many times a person may have close contact to others that can potentially transmit disease each day. Once the simulation starts, the patient zero turns infectious (red) from healthy (blue). The virus is transmitting if the healthy person (blue) touches the infectious person (red). The infected person enters the latent period (yellow) of 6 days [6–8], where the person carries virus but not infectious to others. After that, the infected person enters the infectious period (red) of 9 days [9]. After the infectious period, the person gets immunized (purple) and can no longer pass disease to others or get sick again. The simulation continues until no more infectious person exists in the sandbox (Figure 1). At the end of the simulation, the daily personal contact number, “R” value for the first patient, percentage of total infected population, and duration of pandemic are recorded. The “R” value refers to number of people each patient can infect before the end of infectious period. We only recorded the R value for patient zero as it changes with increasing immunized population. Each simulation is repeated three times and their average value is recorded in Table 1. The total infected population and the pandemic duration is plotted against the daily risky contact per person (Figure 2).


Result Interpretation and Discussion

The number of daily risky contact per person is direct related to the total infectious population of the pandemic. A lower daily contact number will allow a larger percentage of the population not infected when pandemic ends. COVID-19 will infect everyone if the average person in society has one times of risky contact per day. If the average person has 0.23 times or less risky contact per day, the virus is more likely to die down without further spreading to other people (Figure 2 Left). The key point for Disease prevention and control measures is to reduce the number of risky contacts among peoples. Mandatory mask-wearing and social distancing makes each contact less risky and thus reduce the number of effective risky contact. Remote learning, working from home and travel restriction will directly reduce the numbers contacts.

The high contagious of SARS-Cov-2 is due to three factors suggested by the simulation:

• The virus has long incubation and infectious period.

• Most contagious person still moves around in society due to asymptomatic infection or mild symptoms.

• The condition of risky contact between two people is easily achieved as the disease is airborne transmitted.

Vaccinated Result

The study of a vaccination program is presented for comparison. The program is set to distribute the vaccine to the entire population in 120 days. The distribution of the vaccine starts at the same time of the patient zero get infectious. The vaccine program represented by a syringe freely moves in the sandbox and gives the vaccine to the person in contact (Figure 3). The moving speed is adjusted to reach approximately 120 days of delivery time to the whole population. The result suggests the vaccination program protect part of the population that are not vaccinated only if the daily risky contact per person is below 1. If the value is above 1, the vaccine only protects those who are vaccinated. All unvaccinated person will be infected.

Table 1:The simulation result of COVID-19 simulation. Each value is the average of three simulations with identical parameter.



This work is dedicated to the memorial of Dr. Runtao Yan for his guidance and mentorship. The idea is based on a course project of the first author. Special thanks to MIT scratch program and David Zhang for his teaching and support. Special thanks to Cing-Dao Kan for his valuable suggestions. Source Code of the simulation program is shared at

Conflict of Interest

No conflict of interest.

Signup for Newsletter
Scroll to Top