Setting Pen Color

In addition to being able to clear the stage and control when the pen is up or down, Scratch also specifies the color that is used in drawing operations using any of the three pen code blocks shown in Figure 12.4.

Figure 12.4. The code blocks let you control the color used when drawing.


The first code block shown in Figure 12.4 lets you set the color to be used when drawing by allowing you to click on the color swatch located in its input field. When the swatch is clicked, Scratch responds by displaying a color palette, as shown in Figure 12.5. You can select the color you want either by clicking on the color shown within the color palette or by moving the pointer, which now looks like a dropper, over any color currently displayed anywhere on the Scratch IDE and clicking in it. Once specified, the color you selected is displayed in the code block’s input area.

Figure 12.5. Select a color by clicking anywhere on the color palette.


The following script demonstrates how to use this code block to specify the color you want to use.

Here, the stage is cleared, and the pen’s color is set to red. Otherwise, the application operates no differently than before.

Scratch also lets you specify the color to be used when drawing by specifying a number. For example, the following list identifies numbers that you can use to specify a range of commonly used colors.

  • 0 = red

  • 20 = orange

  • 35 = yellow

  • 70 = green

  • 130 = blue

  • 150 = purple

  • 175 = pink

By experimenting with other numbers, you identify a host of different colors. For example, using the second code block shown in Figure 12.4, you change the color used when drawing, changing it relative to its currently assigned value.

Here, the pen block has been added to the beginning of the script’s loop. Each time the loop repeats, it changes the pen’s current color assignment by a value of 10. The result is that a rainbow effect is applied as you draw, with the color changing across a full spectrum supported by Scratch as you move the mouse and draw on the stage.

Using the third code block shown in Figure 12.4, you can specify the color to be used when drawing using its associated numeric value. For example, you could modify the application’s script to draw using red with this code block by passing it a value of 0, as demonstrated here.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.210.91