Program Colour Functions

Code the colour buttons so that you can tap your finger to change the paint colour!

Step 1

Switch to the Blocks editor. First you will set up the colour buttons. Later you will add blocks to decide what happens when someone taps on the screen.

Open the drawer for RedButton and drag out the when RedButton.Click event handler block.

Step 2

  • Open the Canvas1 drawer
  • Find the green set Canvas1.PaintColor block
  • Snap it into the “do” section of the when RedButton.Click block
  • Open the Colors drawer
  • Drag out the block for the colour red 
  • Snap it to the set Canvas1.PaintColor block

Step 3

Repeat Step 2 for the other colours. (Remember: you can copy and paste code using the Ctrl+C/V shortcut on your keyboard.)

The blocks for the buttons should look like this: 

Step 4

Try it out! When you press the colour buttons on the phone, it will change the colour of the paint!

Step 5

Do you want to change the start colour from the default black? Go back to the Designer editor, go to the Components pane and click Canvas1. Go to the Properties pane and change the PaintColor to a colour of your choice.