Skip to 0 minutes and 2 secondsLast week, you were introduced to Scratch and one of the activities was using the pen features to draw shapes on the stage. In this video, I'm going to show you how you can use repetition to create more interesting drawings. One of the things you drew last session was a triangle. So I'm just going to start by redrawing that shape. I chose to draw the shape when the sprite was clicked. First of all, I need to put the pen down to start drawing. And then to draw a triangle, I just need to move and turn.

Skip to 0 minutes and 38 secondsI'm going to move 50 steps to draw each side and then I'm going to turn 120 degrees.

Skip to 0 minutes and 48 secondsThat draws one side of the shape. So to draw the triangle, I'm just going to write click and duplicate the code.

Skip to 0 minutes and 57 secondsSo I've now got that same code three times. And if I click the pen, you'll see that it draws the triangle. Now that's one way of creating a triangle. But I'm going to show you how to use repetition to draw the shape more efficiently. The repetition, the repeat block in Scratch is in the control section. And I'm just going to drag the repeat block in. And what I want to do is I want to move and turn, but I want to do that three times.

Skip to 1 minute and 34 secondsAnd I don't need this code anymore so I'll just drag it back into the code area.

Skip to 1 minute and 40 secondsYou'll notice that the pen down block is outside of the repeat block because I only want to put the pen down once before drawing the three sides of the triangle. And if I click clear to clear the stage and then click the pen sprite again, you'll see that it draws the same triangle as before. The good thing about this code now is that I can change the shape that I draw. Instead of drawing a triangle, I could draw a square. So I could repeat four times and just turn 90 degrees each time. And if I click the pen, it draws a square. I could draw an eight sided shape and just turn 45 degrees each time.

Skip to 2 minutes and 31 secondsAnd you can see that I only need to change these two numbers to draw lots of different shapes.

Skip to 2 minutes and 38 secondsIf I wanted to draw this eight sided shape without using repetition, the code I'd need would look something like this. I'd need to duplicate two, four, eight times.

Skip to 2 minutes and 56 secondsAnd if I clear the stage and then click the sprite to draw it again, it draws the same shape. But let's just say I wanted a slightly bigger shape. Instead of moving 50 steps each time, I might want each side to be 75 steps. And what I'd have to do is I'd have to find everywhere where it mentions moving 50 steps, and I'd have to change each of these to 75.

Skip to 3 minutes and 37 secondsAnd if I clicked to draw the shape again, that doesn't quite look right. And the reason is I've forgotten to change that 50 to a 75, which is easily done if I'm changing lots of different bits of the code.

Skip to 3 minutes and 57 secondsBut with the repetition block, if I wanted an even bigger shape, what I need to do is change this number once and it will draw each of the eight sides 100 steps long. So let's try that out.

Skip to 4 minutes and 21 secondsI'm not actually sure exactly what I want to draw so the next thing I'm going to do is just to tinker.

Skip to 4 minutes and 29 secondsFor example, I don't know what the stamp block does. So I'm just going to drag it into the code somewhere and I'm just going to see what it does.

Skip to 4 minutes and 40 secondsAnd it stamps a copy of the sprite just before it moves and turns, so at the beginning of every side.

Skip to 4 minutes and 50 secondsI'm going to change the numbers as well. So I'm going to repeat, I'm just going to choose a number, 40. And I'm going to turn 130 degrees each time. I'm going to take that stamp out. And I'm not really sure what I'm doing here. I'm just tinkering with the code, making small changes. And I'm clicking to see what happens.

Skip to 5 minutes and 18 secondsI could make some more changes. So, I could change the pen size. I could have a pen size of three. And I might change the pen colour. I'll put that inside the loop so that it draws each side a slightly different colour. So I'll clear the stage and then draw that again.

Skip to 5 minutes and 59 secondsNotice that I've used a change pen size by three. So each time I draw one of these shapes, the pen is getting slightly larger. Instead, I could use set the pen size to three.

Skip to 6 minutes and 20 secondsAnd that would mean that each shape uses the same size pen.

Skip to 6 minutes and 32 secondsOne final thing you'll notice is that the pen doesn't end up facing in the right direction. And I'd quite like that to happen. So I'm going to add some code to reset the stage and the sprites when I press space. So I'm going to point the pen back over to the right hand side. I'm going to move the pen back into the centre of the stage. And then I'm going to clear the stage. And of course, remember from last week that the order of these instructions is important.

Skip to 7 minutes and 15 secondsSo I can now click the pen to draw a shape and then press the space key to reset. So that's my-- I don't know if you can call that art-- but that's my drawing. And now you're going to have a go at seeing what you can create.

Repetition in Art

In this section, you’ll learn how to use repetition to draw simple shapes as well as more complex patterns.

This video shows you some examples of what can be drawn.

Share this video:

This video is from the free online course:

Teaching Programming in Primary Schools

Raspberry Pi Foundation