Random & Repetition: Good Clean Fun

So far all the code you have written has been sequential, one line of code for each action. But sometimes we want the computer to repeat an action and for that we will use a for loop

Random Walk (I love this program but it has zero actual uses)

for number in [1..20]     this means count from 1 to 20 and each time do
    fd 10                 make sure this is INDENTED
    rt random(91)
    dot limegreen, 6

How many dots will this program draw? Now change the program to make 50 dots

Each time, the program is selecting a random number between 1 and 91 as the angle of the right turn

Now modify your program so that it picks a random color each time.Make sure to include this code BEFORE you tell the computer to draw the dot.

aColor = random [red,blue,yellow,green]
dot aColor, 6

TIP: Spaces matter here

for line in [1..40]
    pen  random [red, black, blue, yellow]
    fd random 70
    rt 120

In Network Notebook: explain in english the steps that the computer is taking for each line.

Now modify the code so that the lines can be longer and modify the angle so that your drawing is based on a pentagon

Last updated