Project Folders
Teacher Resources
Student Resources
How Do I?
Site Map
Our Team

obstacle course 1 2 3 4 5 6 7
Obstacle Course 7
8 KB

Goal:   Program a button to create new scenes every time you click it.


Vocabulary:   random, se (sentence)

Project Map



Your colors and your turtle should have instructions as in Obstacle Course 6.  

In the make_a_scene procedure, we will revise the code for the setpos commands that position the rocks, so that they will be placed randomly on the page.

  1. We need to use the word random along with a number for the X coordinate and the Y coordinate.   Random is a special word which is used after a command and before an input number.   It means, "Choose any number that is 0 or higher and less than the input number."

  2. The setpos command needs a list of two numbers, we will use the se command to prepare that list on the fly in the procedure.   Se which stands for sentence, receives some values and reports the list of them.

  3. Setpos se (random 215) (random 50) would mean: "Choose an X coordinate that is 0 or higher, but less than 215, and choose a Y coordinate that is 0 or higher, but less than 50."   However, this command will only place rocks in the upper right area of the page.   If we want to place the rocks all over the page, we need to use negative numbers, too.

  4. Setpos se (-240 + random 215) (5 + random 50) means:
    "Start with an X coordinate of -240 and add a random number that is 0 or higher but less than 215.   Start with a Y coordinate of -5 and add a random number that is 0 or higher but less than 50."

  5. You may choose different numbers depending on your project size and the outer limits of where you might like the rocks to be placed.

  6. When we use the random command, we never know what number the computer will choose.   Sometimes the rocks might be spaced very close together or very far apart.   If you don't like your new scene, just click the make_a_scene button again and again until you do.   It is fun to be surprised.

What If?
Try writing different starting numbers before random.
Try writing different maximum numbers after random.

Can you give each rock a different range of numbers after setpos so that you can be sure the rocks will never touch each other?
Can you place more rocks randomly in the scene?

On Your Own - Project Ideas
Add a different type of obstacle.   Use different ranges of numbers after setpos so that the new obstacles are not mixed in with the rocks.

© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.