Shape – Adaptable Procedures

My Blocks allows you to define a sequence of actions which are performed when called. In programming this is called a ‘procedure’.

Adaptable procedures extend ‘My Blocks’ by passing values to the procedures, which are used as variables. In the code here, the ‘Shape 4 60’ block calls the Shape procedure (set of instructions) passing two values to it. These are then used within the block to perform the instructions.

You need to …

  • Know about variables
  • Understand Loops and some Pen extension of Scratch
  • Be taught about defining My Blocks using number variables
  • Have a basic understanding of x-y coordinates in more than one quadrant.

This unit introduces the following code blocks

Answer the following questions


 

Results

%3Ch3%3E%3Cimg%20class%3D%22alignright%22%20style%3D%22font-size%3A%2014px%22%20src%3D%22http%3A%2F%2Fscratchschool.co.uk%2Fwp-content%2Fuploads%2F2020%2F03%2FdefineBlock.png%22%20alt%3D%22%22%20width%3D%22231%22%20height%3D%22122%22%20%2F%3E%3C%2Fh3%3E%0A%3Ch3%3ESelf%20Review%3C%2Fh3%3E%0ACheck%20back%20through%20your%20answers%2C%20especially%20if%20you%20got%20any%20wrong.%0A%3Ch3%3EInvestigate%20Further%3C%2Fh3%3E%0AMake%20sure%20you%20know%20what%20each%20part%20does%0A%3Ch3%3EModify%20the%20Code%3C%2Fh3%3E%0AChange%20the%20shapes%20to%20create%20a%20triangle%2C%20heptagon%20or%20decagon%0A%0AMake%20it%20draw%20four%20pentagons%20of%20different%20sizes%0A%3Ch4%3E%3Ca%20href%3D%22https%3A%2F%2Fscratch.mit.edu%2Fprojects%2F376090399%2F%22%3ETo%20modify%20the%20code%2C%20click%20here%3C%2Fa%3E%3C%2Fh4%3E

%3Ch3%3E%3Cimg%20class%3D%22alignright%22%20src%3D%22http%3A%2F%2Fscratchschool.co.uk%2Fwp-content%2Fuploads%2F2020%2F03%2FdefineBlock.png%22%20width%3D%22206%22%20height%3D%22109%22%20%2F%3E%3C%2Fh3%3E%0A%3Ch3%3ECheck%20your%20answers%3C%2Fh3%3E%0ALook%20closely%20at%20the%20code%20and%20make%20sure%20you%20understand%20how%20it%20works.%0A%0AIf%20you%20still%20aren%5C’t%20sure%2C%20then%20ask%20an%20adult.%0A%3Ch3%3EInvestigate%20Further%3C%2Fh3%3E%0AMake%20sure%20you%20know%20what%20each%20part%20does%0A%3Ch3%3EModify%20the%20Code%3C%2Fh3%3E%0AChange%20the%20shapes%20to%20create%20a%20triangle%2C%20heptagon%20or%20decagon%0A%0AMake%20it%20draw%20four%20pentagons%20of%20different%20sizes%0A%0A%3Ca%20href%3D%22https%3A%2F%2Fscratch.mit.edu%2Fprojects%2F376090399%2F%22%3ETo%20modify%20the%20%3Ccode%3Ecode%2C%3C%2Fcode%3E%20click%20here%3C%2Fa%3E

#1. What shape do you think this will draw? ? The 'Shape 4 60' command on the right is passed to the Shape procedure (algorithm)

‘Shape 4 60’ will tell the Shape procedure (My BLock) to draw a Shape with 4 sides and length of 60.

The angle will be ‘360 ÷ sides’ or 360 ÷ 4 which is 90 degrees ( a right angle)

The sides will all be ‘move length steps’ and, as the length is 60, they will move 60 steps.

Hence it will draw a square.

#2. How much will the sprite turn right each time it is called in this code? ? Look at 'Turn

This command creates the angle of turn in the shape.
It will turn 360 ÷ sides

As sides=6, it will turn 360° ÷ 6 = 60°

Please note this is the exterior angle that it will turn.

#3. How many steps will it move each time? ? Look at the 'move length steps' block

This is the instruction which draws each side and tells it how long it should be.

This instruction tells it to draw a Shape with 8 sides, each of length 30.

So each time it runs the ‘Steps’ command block, it will ‘move 30 steps’

#4. Which block was used with the function to create this shape? ? What shape is it? That is a big clue.

The shape is an Octogon, which has 8 sides.

The first number passed to the My Block procedure defines how many repeats it will do, and therefore how many sides it will draw.

With this command, the number of sides is 8, so it will repeat 8 times drawing sides 30 steps in length.

#5. This code will put different shapes in different places, what will it look like? ? What do you know about coordinates? Think positive!

These commands tell the Sprite where to go before drawing…

  • If the numbers are both positive, it will draw in the top right.
  • If the x value is negative, it will draw on the left.
  • If the y value is negative, it will draw at the bottom

When both x and y are negative, it moves to the bottom left of the screen and draws a shape with 6 sides – a hexagon.

 

Previous
Score and next steps

This page’s content is closely aligned to the Code-IT resources designed by Phil Bagge.
http://code-it.co.uk/goldshape/#BasicProceedures