2 Making Blocks
1 2 3 Today’s Objectives Know how to break problems down into chunks Know how to define blocks without or with inputs 3 Know how to call the blocks in a program Create programs where you create your own blocks
Draw a square Leave CAT sprite & leave stage WHITE
How to draw a Square 100 Pen down Forward 100 Turn 90 Pen up 90°
Blocks needed to draw a square Motion Pen Pen Add Extensions
How to draw a Square
‘Smarter’ programming Smart programmers break problems down into smaller parts so they can write code in chunks or modules. In Scratch, you create modules by making your own blocks. Scratch Blocks Own Blocks
3 Stages of creating blocks DEFINE You define a block with a meaningful name You add any inputs like special variables to use in the block You call the new block from your program CALL
Define you block Click Make a Block Give it a name Click OK
Defining and Calling Blocks CALL in MAIN program DEFINE call execute return
Defining block - initialise Initialise is coding what you want to happen at the START of your program. call execute return
Challenges 5 6 3 Make a draw triangle block Make a draw pentagon block \ Make a draw triangle block Make a draw pentagon block Make a draw hexagon block Make one up… 120° 360/3=120 72° 360/5=72 5 6 3
Shapes program
[1] Squares Using your draw square block, draw this pattern. Using your draw triangle block, draw this pattern.
1 2 3 Today’s Objectives Know how to break problems down into chunks Know how to define blocks 3 Know how to call the blocks in a program Create programs where you create your own blocks