NetLogo banner

NetLogo Publications
Contact Us

Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Farsi / Persian


NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".

Try It in NetLogo Web


This model simulates the transmission and prevention of the coronavirus (COVID-19) among humans interfacing in a small community.

The World Health Organization ([WHO], 2020) reports that the coronavirus is transmittable over a significantly short distance through imperceptible respiratory secretions expelled when an infected person coughs, sneezes, talks or sings. Thus, causing possible infection in a susceptible person when the droplets reach their mouth, nose or eyes. This makes close contact with an infected person the primary mode of transmission among people interfacing in a community (WHO, 2021). Based on the foregoing, McIntosh (2020) posits that practising social distancing by maintaining six feet (two metres) distance when not staying home, assiduously washing one's hands — especially after touching surfaces in public places, observing good respiratory hygiene — including wearing face coverings, avoiding touching one's face, eyes, nose, and mouth especially, and keeping frequently touched surfaces clean and disinfected are preventive measures that play significant roles in preventing the spread of the virus.


The model initialises with 30 persons from three breeds. There is one COVID-19 positive person from the breed named INFECTED and identified by the colour orange. There are 25 unprotected persons from the PEOPLE breed identified by the colour grey. The third breed is the COMPLIANT breed. It comprises 4 protected persons identified by the colour blue.

The persons move about their community in random manner. Anyone within 1.99 metres range from an infected person, and is not protected contracts the infection and turns orange. 1.99 is the susceptibility range in the model as two metres social distance is recommended for safety. However, only the PEOPLE breed is represented as vulnerable as it composes the unprotected group who do not abide by safety measures. Therefore, the COMPLIANT breed is protected and is not prone to contracting the infection even when they are within 1.99 radius of an infected person. This is because the model assumes they follow all safety precautions to the letter and never go wrong. Hence, they stand a lean or no chance of getting infected.

When all unprotected persons are infected, the modelling stops automatically and the ticks stop counting. That means there is no vulnerable person left to be infected.

Summarily, the model explains the risk of not taking safety measures, as well as the importance of diligent adherence to safety precautions. Bielecki, Züst, Siegrist, Meyerhofer, Crameri, Stanga..., Deuel (2020) show in their research that social distancing and stringent hygiene effectively reduce transmission and the infectivity of the coronvirus. Their claim is buttresed by Gosak, Kraemer, Nax, Perc and Pradelski (2021) who assert that if safety pracautions are conscientiously observed, the epidemic curve flattens.


Each ‘tick’ portrays one day in the model’s time scale.

The POSITIVE slider sets the number of persons who are pre-infected before the start of the simulation. While the default value is set to one infected person, the number can be changed in an increment of one, up to a maximum of five infected persons. One is the minimum value because the model simulates the transmission of a viral infection among humans, and at least, one person must be infected before there can be a transmission. Likewise, five is set as the maximum because with just one infected person, the entire community can get infected. However, to determine if the virus spreads faster with more infected people, the model, through the POSITIVE slider allows for increment in the number of infected persons to show any influence in the spread, and five infected people can model that as the total population is 100.

The UNPROTECTED slider sets the number of persons who do not take precautionary measures and can contract the virus. Therefore, when in defined proximity (1.99 radius) to an infected person, they get infected and become carriers of the virus and agents of transmission. The default slider value is 25 persons. However, the number can be reduced to one person, minimum, and 50 persons, maximum. The minimum value is set to one because the model simulates transmission of the coronavirus, and it takes at least, one susceptible person to model transmission. Likewise, the maximum value is set to 50 because modelling transmission and prevention in a small community is the goal of the model. Hence, 50 susceptible persons could simulate a small community like a workplace, a street, a place of worship, a library, among others.

The PROTECTED slider sets the number of persons not prone to contracting the virus because they religiously abide by all safety measures, and are assumed to never go wrong with the practice. The default value is set to four persons with the minimum as zero, and the maximum as 45, with an increment of one. Zero is the minimum value because in a real-life scenario, there is the likelihood that nobody in certain small communities takes safety precautions because of cultural, religious, political, economic, and other reasons. Also, 45 is set as maximum to depict the impact in transmission and prevention when nearly the entire population takes heed and diligently abide by all safety precautions.

The SETUP button triggers the community (NetLogo WORLD) to be populated with the appropriate number of persons set on the sliders. It also resets the values of the output monitors – POPULATION, number infected (NO. INFECTED), percent infected (% INFECTED), DAYS, number uninfected (NO. UNINFECTED), and percent uninfected (% UNINFECTED) – and the plot (SPREAD GRAPH) to their proportionate values in relation to the sliders’ values.

The GO button starts the simulation and the monitors’ displays. The MOVE button has the same function as the GO button but differs in the simulation process automation. While the GO button makes the simulation process run automatically (NetLogo FOREVER) until a `STOP` command is reached and executed, the MOVE button does not automate the process. Rather, it executes the process per click. The MOVE button helps the user to study the activities going on in the WORLD at their own pace.

The POPULATION monitor displays the total number of persons involved in the simulation.

The NO. INFECTED monitor displays the number of infected persons before the simulation starts, as well as shows the progressive count of infected persons as more persons contract the virus.

The % INFECTED monitor displays the percentage of infection / transmission in relation to the population.

The DAYS monitor displays the number of days / assumed or projected number of days it takes, or will take for a given number of susceptible population to be infected. As mentioned earlier, each tick indicates one day in the model’s time scale.

The NO. UNINFECTED monitor shows the number of persons not susceptible to infection as set on the PROTECTED slider.

The % UNINFECTED monitor displays the percentage of persons not infected in relation to the number of persons not infected.

It is pertinent to mention that while the simulation runs, the NO. UNINFECTED and % UNINFECTED monitors show no decrease in the number of protected persons, which if occurred, would mean transmission was successful among that group. It is so because the model depicts the claims of Bielecki et al. (2020) and Gosak et al. (2021) who postulate that stringent adherence to all safety precautions is tantamount to no successful transmission.

The SPREAD GRAPH plots and displays the transmission rate with Percent Infected on the x-axis, and Days on the y-axis.

The WORLD displays the core of the simulation which lies in the activities of the turtles represented by the PERSON shape.


The values set by all three sliders interact to determine the likelihood of transmission among the population.

When more than one person is infected from the start of the simulation, transmission occurs faster. Therefore, the more the number of infected persons at the onset, the faster the spread.

A significant increase or decrease in the number of PROTECTED persons significantly influences the duration of transmission. This supports the claims of Bielecki et al. (2020) and Gosak et al. (2021) who advocate that strict compliance with preventive measures is effective.

The success or failure of the transmission is determined by the population dynamics change controlled by the sliders.

The number of PROTECTED persons never decreases, and their colour never turns orange. That depicts and corroborates the claims that following recommended precautions to the letter could alter the rate of transmission.

Persons could move around the entire length and breadth of the WORLD as they simulate what is possible in a small community, be it a formal or an informal community. The simulation models a setting where it is possible for one person to walk the entire perimeter of the community.

When no vulnerable person with the colour grey is left in the WORLD, the process stops automatically.


The model simulates transmission and prevention of the coronavirus. Hence, try manipulating the slider values to achieve a near real-life coronavirus situation — taking strict abidance and non-adherence to recommended preventive measures into cognisance.

Pay attention to the number of days it takes to infect all vulnerable persons as slider values are manipulated. This could be useful to make projections. For instance, a significant increase or decrease in the number of PROTECTED persons plays a significant role in the number of days it takes the virus to spread and infect all members of the UNPROTECTED group.


A monitor that displays the number of persons who have come within 1.99 radius of an infected person could be added. This would help establish a correlation between those who have come within the defined radius and the NO. INFECTED count.

A slider that controls social distance could be added, as against the 1.99 radius defined in the codes of the model. The function would be designed to show the speed at which transmission occurs or fails when the slider values are adjusted closer to the set social distancing value, or further away from it. This would replicate a near real-life situation.

The model could be extended to include a limitation to the extent persons could move around the community, as everyone for some reasons – medical, cultural, legal, age, or other personal reasons – would not move around the entire perimeter of a given place. That would make the scenario near real-life.

There could be a monitor that shows persons who have been infected with the virus but do not show any symptoms yet, as the virus may be in its incubation stage. This feature could be enhanced also by giving persons in this category a different colour (maybe yellow) before they turn orange (fully) upon full maturity of their infection. To further enhance the feature, it would be apt to add a monitor that counts the number of days left before an infected person without symptoms begins to show symptoms and turn orange from "yellow". The count of this new monitor would be observed alongside another monitor that counts the number of confirmed cases, to see if at the end of an incubation period for one person, there is a correlated increment in the number of confirmed cases.

When cases are confirmed, persons should be able to isolate or get quarantined, as well as get treated, and the turtles that represent such persons should disappear (NetLogo DIE) from the WORLD temporarily. To further enhance this feature, there should be appropriate monitors displaying the number of persons receiving treatment, isolating, and/or quarantining. Additionally, persons fully recovered should be able to reappear in the WORLD and continue their activities. A monitor that shows the number and percentage of persons recovered should be created as well.

When persons who have religiously followed safety precautions go wrong with the practice, they should be vulnerable at the time and their colour should change accordingly. It should be possible for such persons to contract the virus at the time of vulnerability and spread same.

Different strains of the virus and their levels of contagiousness could be added. The contagion level of such strains would make significant contributions to the simulation.


An interesting thing about the model is using a few lines of code to bring all the engaging features to life. The NetLogo Dictionary played a key role in the actualisation of the model. For instance, the model includes three groups of persons — the POSITIVE, the UNPROTECTED, and the PROTECTED groups. Using the `create-<breeds>` command and a few `if`-statements, all three categories of persons function in line with the simulation.

Another interesting feature is the `let` command used in conjunction with the `count other turtles with` command to ask a turtle to execute a command while excluding itself as a turtle.

A particularly interesting feature is the implementation of social distance in the model. That was achieved with the `in-radius` command as shown in the blocks of codes below:

let unsocially-distanced count other turtles with [ covid? ] in-radius 1.99
if unsocially-distanced > 0 [
set covid? true
if covid? [
set color orange


Similar to this model in the NetLogo Library are the:
- HIV Model in the Biology category.
- Spread of Disease Model in chapter 6 of the IABM textbook.
- Virus Model in the Biology category.
- Virus on a Network Model in the Networks category.


Bielecki, M., Züst, R., Siegrist , D., Meyerhofer, D., Crameri, G. A., Stanga, Z., . . . Deuel, J. W. (2021). Social Distancing Alters the Clinical Course of COVID-19 in Young Adults: A Comparative Cohort Study. Clinical Infectious Diseases, 72(4), 598–603. doi:

Gosak, M., Kraemer, M. U., Nax, H. H., Perc , M., & Pradelski , B. S. (2021). Endogenous social distancing and its underappreciated impact on the epidemic curve. Scientific Reports, 11(3093), 1-10. doi:

McIntosh, K. (2020). Coronavirus disease 2019 (COVID-19): Epidemiology, virology, and prevention. PA, Pennsylvania: Wolters Kluwers.

Rand, W., & Wilensky, U. (2008). NetLogo Spread of Disease model. Evanston, Illinois, U.S.A. [Computer software]

Wilensky, U. (1999). NetLogo Virus Model. Evanston, Illinois, U.S.A. [Computer software]

World Health Organization. (2020). Transmission of SARS-CoV-2: implications for infection prevention precautions: Scientific Brief. Geneva: World Health Organization.

World Health Organization. (2021). Preventing and mitigating COVID-19 at work: Policy brief. Geneva: WHO-ILO.

(back to the NetLogo User Community Models)