Disease Spread Hints

Here are some hints for a possible way to write the code:
  1. Initialize the variables that will keep track of time and the number of infected. Ask the user for the population size, the percentage of the population initially infected, and the speed at which the people will be moving.
  2. Keep track of time until the entire population is infected.
    reset timer; repeat until((infectedCounter)=(total)){set (timeElapsed) to (timer)}
  3. As you don't know ahead of time how many people sprites will be created, create a single sprite and then use the create a clone of myself block in Snap! to generate a population of size input by the user.
    repeat(total){create a clone of (myself)}
  4. Initialize clones and give them behavior by using the when I start as a clone block.
    when I start as a clone
  5. Give the clones a sick or a healthy costume during their initialization. As the clones are being created, assign them sick costumes until reaching the user-specified percentage of the population initially infected.
    switch to costume(healthy);if((infectedCounter)<((total)X((percentageInitiallyInfected)/100)){switch to costume(sick);change(infectedCounter) by (1)}
  6. Give a random direction and location to clones initially, but once the timing starts, clones should move in a straight line with the user-specified speed until they hit an edge and bounce.
  7. If a healthy sprite collides with a sick one, it should get sick. To do this, write code to detect collision with a sick person:

    Please note that in order to have the costume name option be available, you need to select a sprite option in the second slot of the of block, prior to dragging in the orange colored variable item.
    collideWithSick?{for each (item) of (my (neighbors)){if(touching(item)? and (costume name of (item)=sick)){report(true)}};report(false)}
    Build this block instead of using the touching(red)? block of the Sensing menu because Snap! can be very slow in sensing touching by color but is very fast sensing touching by sprite.
  8. Test your code to make sure that everything works as intended.