SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

5.06 Change the pen width

Next you will add code to allow the person using your program to draw things with different pen widths.

First, add a new variable called width.

  • Click on Variables in the Code tab, then click on Make a Variable.Variable blocks
  • Type in the name of your variable. You can choose whether you would like your variable to be available to all sprites, or to only this sprite. Press OK.Create variable
  • Once you have created the variable, it will be displayed on the Stage, or you can untick the variable in the Scripts tab to hide it.Variable on the stage

Add this line inside the forever loop of the pencil sprite’s code:

The pen width now repeatedly gets set to the value of the width variable.

Right-click on the width variable displayed on the Stage, and then click on slider.

screenshot

You can now drag the slider that is visible below the variable to change the variable’s value.

screenshot

Test your project and see if you can change the pen width.

screenshot
×
×

Cart