1) Now we have our people, and one of them is infected, all we need to do is pass on the infection.
The easiest way to do this is to change the colour of a green sprite if it touches a red one. Add the following code inside the
Repeat until
block:
It should go inside the Repeat until
block so it gets checked every time that
repeats. Note that the code checks the colour of the sprite against the thing the sprite is touching. You can set the colours in the boxes by clicking on the box (the mouse will turn to a finger) and then clicking the current
costume to pick up the colour. To get the colour of the other costume, go to the "Costumes" tab, and click the other costume to change the sprite. Then go back and set the colour of the box. Remember to change back the costume of Sprite1 to the healthy costume at the end, or all the clones will start infected.
2) Make sure you understand how the code above works and then run the model. You should see the green sprites turn red when red sprites touch them.
3) If you've managed this, great! That's your core model done! If you find the model too fast or too
slow, adjust the step size and the wait period in the Repeat until
block until you're
comfortable with it. Note that if one or two sprites take a while to get infected, you can be cruel and
pick them up and drop them near a zombie while the model is running.
4) We'll add one last bit of code to stop the model. Go to the "data" set of blocks. Make yourself a new variable called "numberInfected", making sure it is "For all sprites":
Then add the following bits of code to complete the model:
The new bits of code:
1) Set the variable to "1" at the start of each run (remembering one sprite will start infected).
2) Change the Repeat until
block to end when the variable reaches some number.
3) Increases the variable by one each time a sprite changes.
4) Ends the model once the Repeat until
block has ended.
Note that an alternative to the change numerInfected by 1
block would be the following:
This works fine, even though the variable is on both sides of the sum. The right side is worked out first and then the answer copied over the current variable value.
Secondly, note that the variable values are reported on the Stage. You can hide those you're not interested in
(like counter) by right-clicking on them and selecting
That's it! We're done. Try out your model -- note that depending on how many sprites you add, you
may want to change the stopping number in the Repeat until
block.
This is a perfectly good disease-spread model, just as good as many used in the real world for understanding diseases - infact, better than some. Go on now to Experimenting with the model.