| Obstacle Course 7 |
|
|
|
| |
if you cannot see the project |
|
Goal: Program a button to create new scenes every time you click it.
Vocabulary: random, se (sentence)

Notes 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 four setpos commands that position the rocks, so that they will be placed randomly on the page.
- 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."
- When we use words and numbers with the setpos command, we can't put them in brackets. (We just use brackets when we are placing two numbers after setpos.) Instead, we put them inside parentheses, and we use the word se, which stands for sentence. It means, "Include everything inside the parentheses."
- Setpos (se random 250 random 150) would mean: "Choose an X coordinate that is 0 or higher, but less than 250, and choose a Y coordinate that is 0 or higher, but less than 150." 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.
- Setpos (se -170 + random 350 -120 + random 180) means:
"Start with an X coordinate of -170 and add a random number that is 0 or higher but less than 350. Start with a Y coordinate of -120 and add a random number that is 0 or higher but less than 180."
- You may choose different numbers depending on your project size and the outer limits of where you might like the rocks to be placed.
- 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.
Challenge
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?
|