Seeding the Infection
Now let's infect some of the Turtles to start. Go to the Setup and Run tab and get a Run Once block and drag it onto the Setup area. Click on where it says Run Once and edit the name to say Infect.
Go to the Logic tab and grab an If block and attach it to the Run Once block. Note that this block has two parts - a test section and a then section.
We want to infect individuals at the start with a 10% chance. We'll do that by instructing the turtle agents to each draw a random number between 1 and 100, and if that number is less than 10 they will be infected. Now go to the Math tab and get a <= block and attach it to the rounded (boolean) port on the If block where it says Test. Grab a Random block from the Math tab, attach it to the left part of the <= block and change the number to 100. Then grab a pink number 1 block from the Math tab, attach it to the right part of the <= block, and change the number to 10.
Finally get a Set Color block from the Traits category and attach it to the Then part of the If block. You can leave the color as red. Remember, the red color means that the turtle agent is infected.
Look at the Runtime space and you should now see a button named Infect in addition to your setup block. Click setup once and then Infect once. You should see several red spheres and a lot of green ones.
| Next: Part 3 of 8 - Motion | Back To Top |