How to Make an Epidemic SimulationThis is a simulation of how a disease spreads through a population. Using Kedama, it’s easy to change the density of the population and watch how the number of turtles in the world affects the spread of the disease. To create this project, we’ll be using test statements and variables. The first script we need to write will be one that sets up the world for the simulation. To begin with, we want a large population of healthy turtles, with only one turtle who is carrying the disease. First, drag out a Kedama world and add a new breed of turtle. |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Since we want to work with a larger population than one turtle, pull out the “turtle1’s turtleCount” to create a new script. We called our script “setup” since this will describe how we want the Kedama world to look before we actually run our simulation. Go ahead and create a large number of turtles for your population; we used 1,000. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Now, in order to distinguish the turtles that are infected with the disease from those who are healthy, we can use different colors. We made our healthy turtles blue, and our infected turtles will be red. Of course, you can choose whatever colors you want. In the beginning, since our turtles are healthy, we will set turtle1’s color to blue. To do this, use turtle1’s viewer to open the “kedama turtle” category, pull out the command “turtle1’s color,” and add it to your script. Then, change the color of the turtles to your healthy turtle color. | |||||||||||||||||||||
| In order to change all the turtles to the new color, go ahead and run your script. The turtles will change to their new, healthy color. Did you notice that the red box did not also change color? To find out why, click here. |
|||||||||||||||||||||
| We also want to create a variable for our turtles to know if they are healthy or infected. Click on the “V” at the top of turtle1’s menu to create a new variable, “infected”. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
| This will be a Boolean variable, meaning that it can be either true or false. To change the type of variable you have (the default is a “Number” type), click on the menu icon next to the name of the variable and select “change value type”. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Then, select “Boolean” from the list of choices. In the beginning, we will set this to false. This shows that all of the turtles are healthy. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
Now, drag out this command and add it to your “setup” script. This ensures that the turtles are healthy at the start of your simulation. In order to keep track of how many turtles in the Kedama world are infected, we will also create a variable “infectedCount.” We need to use the Kedama menu for this instead of the turtle menu because we want to count the number of infected turtles within the Kedama world. So, open the Kedama viewer and create the new variable. |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
When we use a detailed watcher, we can observe how many turtles are infected and how quickly they are spreading the disease. Click on the menu icon next to the name of the variable – “Kedama’s infectedCount” – and select “detailed watcher.” |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Go ahead and pull out the watcher. Then, for our “setup” script, let’s set “infectedCount” to zero since no turtles are infected yet. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
So far, we’ve created a large population of healthy, happy turtles. Now, we need to introduce one infected turtle into the population. In order to do this, we can write a test statement so that if there are no infected turtles in the world, one turtle will become infected. Tear off a test statement and add this to your script. Now, one condition that will always be true only at the beginning of the simulation is that infectedCount will equal zero; after all, we just wrote that command! So, a good test might be that if infectedCount equals zero, then one turtle should be infected. How should we infect just one turtle? This will require a new script for turtle1 that performs three actions. It should 1) change the turtle’s infected value from “false” to “true”; 2) change the turtle’s color from a healthy color to an infected color (we changed our turtles from a healthy blue to a sickly red); and 3) increase Kedama’s “infectedCount” variable by one. Can you write this script on your own? (For help, click here.) Once you’ve written this script, you can go ahead and add it to the test statement so that when it is true, the script will run. As you can see, we named our new script “infect.” |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Okay, now we’ve programmed the simulation for how we want it to appear at the beginning. To make sure yours is working, go ahead and run the setup script. You should see a large population of healthy turtles with one infected turtle among them. To make it even easier on the user, you can create a button by clicking on “turtle1” at top of your “setup” script and selecting “button to fire this script.” That should hand you a setup button that you can place near the Kedama world. | |||||||||||||||||||||
![]() |
|||||||||||||||||||||
The last script we need to write is for the spread of the disease. To do this, we need to make the turtles move so that each time an infected turtle is near a healthy turtle, the healthy turtle should become infected. Then, that newly infected turtle can also spread the disease, and so on – just like how a cold might spread through a crowded room. First, we need to get our turtles moving. That part is easy enough; go ahead and create a new script that sets turtle1 moving forward. We had each of our turtles move just one step forward at a time and called our script “spreadDisease.” Now, we need to work with the patches in Kedama. We want to track the infected turtles by following them from one patch to the next. Then, if a healthy turtle is in close proximity to an infected turtle – that is, if they are in the same patch – we want the healthy turtle to become infected. Think of this as a crowded room with a sick person. If you are standing close to that person, there’s a pretty good chance you’ll catch his or her cold. To track our infected turtles, we will first clear the patch values on the grid. Then, we’ll change the values of the patches with the infected turtles to 1 so we know where they are. To clear the patch values so that all patches start with the same empty value, open the patch viewer. You should see the “kedama” category menu already open. To clear the values of the patches, drag out the command “patch clear.” |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
Drop this tile into your script to erase all previous patch values. The next step we need to do is to find the infected turtles and change their patch values to 1. First, we can find the infected turtles by using a test statement. Tear off a test statement and select “turtle1’s infected” from the variables menu of your turtle viewer as your test statement. |
|||||||||||||||||||||
![]() |
|||||||||||||||||||||
| Now, if turtle1 is infected, we need to set the patch value to 1. Do this by selecting “turtle1’s patchValueIn” from the “kedama turtle” menu and dropping it into the test statement. | |||||||||||||||||||||
Change turtle1’s patchValueIn to 1 to mark the patches in the Kedama world where the infected turtles are. Finally, we need to check whether there are any healthy turtles in those same patches with infected turtles. If so, our healthy turtles should become infected. Can you write this script on your own? For a hint, click here. |
|||||||||||||||||||||
| That’s it! Click your “Setup” button to prepare your simulation, and then run your “spreadDisease” script to watch the epidemic take place. You can also play with tick rates, color, and x- and y-coordinates for some interesting effects. Challenge 1: Add a graph that charts the spread of the disease throughout the turtle population over time. For help, see the graphing tutorial on the Squeakland website. Challenge 2: Even when you stand very close to someone who is sick, there is still a chance you will not be infected. In our program right now, any healthy turtle in the same patch as an infected turtle will automatically become infected. Can you modify the epidemic scripts so that instead, each healthy turtle has a high probability of becoming sick if it is near an infected turtle? |
|||||||||||||||||||||
|
|||||||||||||||||||||