AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Teams and sub-routines

Week 2 · Unit 1: Be a designer · 3 lessons
3

Drawing with the pen

Computing 5: Unit 1, pp. 8–19
GoalUse the pen blocks and a sub-routine to draw a pattern.
New words
pen extension · a set of blocks that lets a sprite draw lines as it movespen down · a block that makes the sprite draw while it movespen up · a block that makes the sprite stop drawingerase all · a block that clears the stage of all pen drawings
Explanation

The Pen extension adds drawing blocks. After ‘pen down’ the sprite draws a line wherever it moves. ‘Pen up’ lets it move without drawing. ‘Erase all’ clears the stage, so it is a good first block. The block ‘set pen color to’ takes a number, and different numbers give different colours. A sub-routine can draw a shape. To draw a square we move 50 steps and turn 90 degrees, four times. Four turns of 90 degrees make 360 degrees, a full turn. The sprite then faces the way it began and is back at its starting corner. The main script can turn a little and call the square again.

definedefinesquaremove50stepsturn ↻90degreesrepeat4mainwhenclickederase allgo to x:0y:0point in direction90pen downsquareturn ↻120degreesrepeat3
Worked examples
x 240−240y 180−180
One call of square draws four sides of 50 steps. The turns add up to 4 × 90 = 360 degrees, so the sprite ends where it started and faces the same way.
x 240−240y 180−180
The main script calls square and then turns 120 degrees, three times. This draws three squares that share one corner. 3 × 120 = 360, so the sprite ends facing the way it began.
whenclickederase allpen downsquarepen upmove80stepspen downsquare
Pen up lets the sprite travel without drawing. This script draws one square, jumps 80 steps along without a line, and draws a second square.
Class activity

Walk the shape (a clear floor or a playground, with a friend). Take 4 steps forward and turn a quarter turn to the right. Do this 4 times. Where do you finish? Which way do you face? Now take 3 steps and turn a third of a full turn (120 degrees), three times. What shape did you walk? Draw both walks on paper. If you have a computer or tablet, add the Pen extension in Scratch and build the pinwheel program.

Practice
1
How many degrees does the sprite turn in total while the pinwheel program runs?
pen downsquareturn ↻120degreesrepeat3
2
Change the main script to repeat (6) with a turn of 60 degrees. How many squares are drawn? Does the sprite end facing the way it began?
whenclickedpen downsquareturn ↻60degreesrepeat6
3
Which number completes the sub-routine so that it draws a triangle with three equal sides?
definedefinetrianglemove70stepsturn ↻?degreesrepeat3
4
A pupil runs the pinwheel program but sees nothing on the stage. Which block might be missing? What happens if ‘pen up’ is forgotten between two shapes?