Pattern Pen

Asking for Input

Ok, this is getting pretty cool, but it’s a bit boring to have to edit your code every time you want to draw a different pattern. Wouldn’t it be good to get the program to ask you for values to use? You can do that!

First, go to the Variables section and create variables called degrees and increase.

Now add the new variables to your code like this:

repeatuntiltouchingedge?movestepsstepsturndegreesdegreeschangestepsbyincrease

Now you need to ask for values for these two variables and store them. You do this using a Sensing block called Ask and wait, which you can type a question into.

Pull the Ask and wait block into your sprite panel and change the question to How many steps should I grow by?

Then add it to your program, just after you set steps to 0, like this:

whenclickedsetstepsto0askHow many steps should I grow by?andwaitpenup

Now you’ve got your program asking a question, you need it to remember the answer! It turns out that Scratch has a special variable called answer, where it stores the most recent answer it has received. You can find this variable among the Sensing blocks.

Using a set to block from Variables, take the value of answer and store it in the increase variable like so:

askHow many steps should I grow by?andwaitsetincreasetoanswer

Now, do the same thing with degrees, asking How many degrees should I turn? and storing the value of answer in degrees:

setincreasetoansweraskHow many degrees should I turn?andwaitsetdegreestoanswer

Check your program now looks like the one below, and run it a few times with different numbers. Write down the answers that make the coolest pictures. You’ll need them in a later step!

whenclickedsetstepsto0askHow many steps should I grow by?andwaitsetincreasetoansweraskHow many degrees should I turn?andwaitsetdegreestoanswerpenuphideeraseallgotox:0y:0setpencolortopendownrepeatuntiltouchingedge?movestepsstepsturndegreesdegreeschangestepsbyincrease