Simulating the Spread of Diseases in Scratch

By March 22, 2014classes, tutorial

This walkthrough requires you have a free account with Scratch. Get it here. 

http://scratch.mit.edu/
http://scratch.mit.edu/projects/19361239/

1. New project and sprite

  • Create a new project with the ‘Create’ button

  • Give your project a name (you can change this later)

  • The cat is fun, but there are lots of other sprites. Right click on the cat to delete it.

  • Download a sprite from: http://www.clipartlord.com/
    What do you want your colony to be? A dinosaur, monkey, a golden armadillo?

  • Below the animation panel is an arrow with a folder => click on that to Choose new sprite from file.

2. Make a healthy and a sick look for your sprite by making two “costumes”

  • Click on Costumes at the top of the middle panel and you’ll see your sprite.

  • Right click and duplicate your costume to make another costume just like it.

  • Give it a new costume name – ‘sick’

  • Then click Edit beside the new copy and use the painting tool to make it look sick. Be sure to give the sick costume a different color so it stands out.

3. Make the Sprite move by writing a script for it to follow

  • Click on Scripts at the top of the middle panel to get ready to write your script.

  • At the top of the left panel, click on Events. Drag the when flag clicked block to your script panel in the middle.

  • Now click on Motion at the top of the left panel. Drag move 10 steps to your script and attach it to the other block.

  • Try running your program by clicking the flag. Cool!

  • Make your sprite turn by attaching another block from the Motion options.

4. Keep your sprite moving!

  • Click on Control to go back to the orange control blocks.

  • Make your sprite follow the move and turn actions ten times by dragging a repeat 10 block over to the script. Attach it below the when flag clicked and around the move and turn blocks. Try it!

  • Change the number of repeats from 10 to 100 and try it again. Your program runs for a longer time, but still eventually stops.

  • Disconnect the blocks and throw away the repeat block by dragging it to the left panel. Instead, insert a forever block. Try it! Now you need to click the red stop sign to stop.

5. Slow down your sprite

  • That sprite is too fast! Put a wait 1 secs block inside your forever loop.

  • Okay, now it’s too slow. Change to .1 sec.

6. Make your sprite a little less predictable

  • Instead of always moving the same number of steps, you can make your sprite move a random amount. Replace the 10 in your move block with a green pick random 1 to 10 block from the Operators menu.

  • Use the same idea to make the amount your sprite turns be random.

  • Play with the range of your random numbers until you like how your sprite moves.

7. Make a new sprite who is always sick

  • Go to the bottom right panel and right click on your sprite to duplicate it. Now you have a new sprite with the same costumes and script as your first sprite. Give this sprite a name like “sick sprite” by double clicking on the name in the top of the middle panel.

  • Click on Scripts. Now you’re going to change your sick sprite’s costume so that it looks sick.

  • Go to the Looks menu and drag a purple switch to costume block into your script right before the forever loop. Set the block so that it chooses your costume for sick sprites.

8. Make your original sprite healthy

  • Run your program. Your two sprites run around, but they have no effect on each other.

9. Make your original sprite “get sick” with it touches a sick sprite

  • First, your sprite must notice if it touches a sick sprite. From the Control menu, drag an if block into the bottom your loop.

  • The if block is going to check if something is true. You get to tell it what to check, by filling in the hole in the block. Go to the Sensing menu and drag in a touching color block.

  • Set it to the color of the sick sprite by clicking on the color square, taking the little eye dropper (it will pop up over) to your sick sprite and clicking on its background color.

  • Now fill in what should happen if your sprite is touching a sick sprite: change to the sick costume.

  • Run your program and watch your sprite get sick! Run it again and confirm that your sprite starts out healthy at the beginning. If not, adjust the order of the blocks in its script to make that happen.

10. Add more sprites – don’t do this step until you have finished steps 1-9

  • In the bottom right panel, right-click on your original sprite to make some duplicates. They will inherit the same costumes and script. Be sure to keep that other sprite who is always sick.

  • Now run your program and watch the disease spread through all the sprites. If the sprites start out too close together they’ll get sick immediately, which isn’t much fun to watch.

  • You can drag them apart to better starting positions.

11. More ideas: Experiment with more realistic diseases

  • Keep track of the sickness level of each sprite. Go to the Data menu and click on Make a variable. Name it “sickness” (and make it a variable For this sprite only). Your sprite now has a variable called “sickness” that can be 0 if it has no sickness and higher numbers if it is sick. Add a block at the beginning of your sick sprite’s script that will set its sickness to 50. Make your other sprites start out with a sickness level of 0.

  • Make your sprites get well again after they have been sick for a while. (Hint: reduce their sickness level every time through the loop and check for when that sickness hits 0.) But be sure to keep that one sprite who is always sick so the disease has somewhere to start.

  • Experiment! Make the disease more or lass catchy, try different amounts of time needed to get well

  • Change your script so that a sprite isn’t guaranteed to get sick when they touch a sick sprite. Try using a 30% chance of getting sick.

12. More ideas: Make it look cool

  • Make your sprites “say” something when it gets sick. (Hint: Find a block for this in the Looks menu.)

  • Make an interesting “stage” that will be the background for your sprites: Click on the stage icon in the lower-right panel, and then the Backgrounds tab in the top of the middle panel. You can paint your own background, or import one from a file.

  • Improve how your sprites move.

  • Keep track of the total number of sprites who are sick.

Using Scratch at home: http://scratch.mit.edu
Adapted from: Gr8 Designs for Gr8 Girls

dojo-admin

About dojo-admin