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). In the light of that, McIntosh (2020) posits that, practising social distancing by maintaining six feet (two metres) distance when not staying home, and assiduously washing hands, especially after touching surfaces in public places, observing good respiratory hygiene, including wearing face coverings, avoiding touching ones face, eyes, nose, and mouth especially, and keeping often touched surfaces clean and disinfected, are preventive measures that play significant roles in preventing the spread of the virus.


The model initializes with 30 persons of three breeds, with one COVID-19 positive person from one breed named INFECTED, and identified by the colour orange, 25 unprotected persons from another breed named PEOPLE, and identified by the colour grey, and 4 protected persons from the COMPLIANT breed, identified by the colour blue. The persons move about their community in a random manner, and anyone within 1.99 metres range from an infected person, and who also is not protected contracts the infection and turns orange. 1.99 is the susceptibility range as McIntosh (2020) and other scholarly studies recommend two metres social distance for safety, and the susceptibility range has been represented as 1.99 radius in the model. In the model also, only the PEOPLE breed has been represented as vulnerable as they are the unprotected group who do not abide by safety measures, therefore, the COMPLIANT breed is protected and not prone to contracting the infection even when they are in 1.99 radius of an infected person, as the model assumes they follow all safety precautions to the letter and never go wrong, hence, stand a lean or no chance of getting infected. When all unprotected persons are infected, the modelling stops automatically and the ticks stop counting, meaning that there is no vulnerable person left to be infected.

Summarily, the model explains the risk of not taking safety measures, and the importance of abiding by safety precautions as 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 coronavirus. This claim is buttresed by Gosak, Kraemer, Nax, Perc and Pradelski (2021) who assert that if safety pracautions are diligently adhered to, 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 tries to simulate 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 an increment in the number of infected persons to show any influence in spread, and five infected persons can model that as the total population of persons in the model is 100.

The UNPROTECTED slider sets the number of persons who can contract the virus because they do not take precautionary measures hence, 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 minimum is one person, while the maximum is 50 persons with an increment of one. The minimum is set to one because the model tries to show transmission of the coronavirus, and it takes at least, one susceptible person to model transmission. Likewise, the maximum 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, for example, 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, the minimum, zero, and the maximum, 45, with an increment of one. Zero is set as the minimum value because in a real-life scenario in certain communities, there is a likelihood that nobody takes heed for some reasons, be it cultural, religious, political, economic, etc. Also, the slider maximum is set to 45 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 plot (SPREAD GRAPH) to their proportionate values in relation to the sliders’ values.

On the one hand, the GO button starts the simulation and the monitors’ displays. On the other hand, 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 one study the activities going on in the WORLD at their 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 indicated 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 them. This is so because the model tries to depict 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, and 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.
This depicts and corroborates the claims that following recommended precautions to the letter could actually 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 actually models a setting where it is possible for one person to walk the entire perimeter of the community.

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


The model tries to simulate 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 manipulates social distance could be added, as against the 1.99 radius defined in the codes of the model. This 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 – would not move around the entire perimeter of a given place. This also 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 period. 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, while 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, and there should be a monitor that shows the number and percentage of persons recovered.

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, UNPROTECTED, and PROTECTED categories, and 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, and this was achieve simply 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)