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

Drawing shapes with loops

Week 10 · Unit 4: Be a storyteller · 3 lessons
2

Loops draw shapes

Computing 4: Unit 4, pp. 48–61
GoalUse a repeat block with a move and a turn to draw triangles and hexagons.
New words
regular shape · a shape with all sides the same length and all corners the sameturn angle · how far the sprite turns at each cornerfull turn · a turn all the way round, which is 360 degrees
Explanation

To draw a regular shape, a sprite does the same two things again and again: it moves one side and then it turns. This is a job for a repeat block. The number in the repeat block is the number of sides. The turn angle depends on the number of sides. All the turns at the corners add up to one full turn, 360 degrees, so the turn angle is 360 divided by the number of sides. A triangle has 3 sides and turns 120 degrees. A hexagon has 6 sides and turns 60 degrees. When the loop is finished, the sprite is back at its start place and faces the way it started.

SidesShapeTurn angle
3triangle360 ÷ 3 = 120
4square360 ÷ 4 = 90
5pentagon360 ÷ 5 = 72
6hexagon360 ÷ 6 = 60
8octagon360 ÷ 8 = 45
Worked examples
whenclickederase allgo to x:-40y:35point in direction90pen downmove80stepsturn ↻120degreesrepeat3
This script draws a triangle with sides of 80 steps. The repeat number is 3 and each turn is 120 degrees. The sprite sets its direction to 90 first, so it always begins facing right.
x 240−240y 180−180start
A hexagon with sides of 60 steps: repeat (6), move (60) steps and turn ↻ (60) degrees. The pen line has six equal sides, and the end of the sixth side meets the start.
x 240−240y 180−180start
This is the triangle the script above draws. The sprite moves right first, then turns 120 degrees at each corner. Three turns of 120 degrees make 3 × 120 = 360 degrees, one full turn, so the sprite ends at its start, facing right again.
Class activity

Quarter-turn walk (with family): put a piece of tape on the floor and stand on it, facing a wall. Walk the algorithm “repeat 4 times: take 3 steps, turn right a quarter turn”. Where do you finish, and which way do you face? Now do only 3 trips instead of 4. Are you back at the tape? Why not? If you have a computer or tablet, build the triangle script and then change repeat (3) to repeat (4). Does the shape close?

Practice
1
What turn angle draws a regular shape with 10 sides?
2
Write the loop that draws an octagon with sides of 30 steps.
3
Which script draws a closed hexagon?
Awhenclickedpen downmove30stepsturn ↻60degreesrepeat6Bwhenclickedpen downmove30stepsturn ↻90degreesrepeat6
4
A sprite started at the dot facing right and drew this shape with a loop. Each side is 60 steps. Write the loop.
x 240−240y 180−180start