SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

5.03 Coloured pencils

Now you’re going to add different coloured pencils to your project and allow the user to choose between them.

Click on the Costumes tab of the ‘pencil’ sprite.

Rename the pencil-a costume to pencil-blue

rename-pencil

Right click on the pencil-blue costume and select duplicate.

screenshot

Name the new costume ‘pencil-green’, and colour the pencil green.

screenshot

Draw two new sprites: one blue square and one green square. These are for choosing between the blue and green pencil.

screenshot

Rename the new sprites so that they are called ‘blue’ and ‘green’

To rename a sprite in Scratch, click on the sprite:

screenshot

The information about the sprite will be displayed above:

screenshot

Edit the name of the sprite.

Add some code to the ‘green’ sprite so that when this sprite is clicked, it broadcasts the message “green”.

green square

broadcasts is a way of sending a message which can be heard by all sprites. Think of it like an announcement made over a loudspeaker.

Broadcasting spells: Use the magic wand to click on the buttons and cast spells. What does each spell do to the characters? See inside

You can create a message to be broadcast. The message text can be anything you like, but it is useful to give it a sensible description.

  • Find the broadcast block under Events
  • Select New Message in the drop-down menu.
  • Then type your message
Create a broadcast

Send a broadcast

You can decide when to broadcast your message. For example:

Receive a broadcast

Sprite can react to a broadcast by using a when I receive block. Multiple sprites can respond when they receive the same message.

You can add blocks below a when I receive block to tell the sprite(s) what to do when they receives the message.

The pencil sprite should listen for the “green” message and change its costume and pencil colour in response.

Switch to your pencil sprite. Add some code so that when this sprite receives the green broadcast, it switchs to the green pencil costume and changes the pen colour to green.

pencil

To set the pencil to colour to green, click the coloured square in the set pen color block, and then click on the green square sprite.

Then to a similar thing so that you can switch the pencil colour to blue.

Click on the blue square sprite and add this code:

blue_square

Then click on the pencil sprite and add this code:

pencil

Finally, add this code to tell the pencil sprite which colour to start with, and to make sure that the screen is clear when your program starts.

pencil

If you prefer, you can start with a different colour pencil.

Test your code. Can you switch between the blue and green pencil colours by clicking on the blue or green square sprites?

screenshot
×
×

Cart