Skip to main content

Lesson 1-2 · Drawing Shapes

Module 1 · Learning to Drive

Lesson 1-2 · Drawing Shapes

50–60 minBlockly FoundationBuild it up yourselfSlides (PowerPoint)
👩‍🏫

Teacher mode is on — the gray boxes are yours only. This lesson is built as a discovery sequence: students figure out the square, and the shortcut, before either is explained. The gray boxes tell you what to hold back and when to reveal. Flip the switch (bottom-right) to preview the student view.

In Lesson 1-1 you drove the robot forward and back. Today you'll get it to draw a square — and you'll work out how, one block at a time. No recipe up front. Somewhere along the way you're going to invent a shortcut that programmers use constantly.

Learning Objectives

By the end of this lesson you will be able to:

  • Build a program up one step at a time, running it after each change
  • Make the robot trace a square, and explain why the program needs what it needs
  • Find a shorter way to write a program that does the same thing many times
  • Work out the turn angle for any regular shape (360° ÷ number of sides)
An animation, seen from above, of an XRP robot on a plain floor carrying a marker in the hole between its wheels. It waits for the button, then drives straight 20 cm, stops, and turns 90 degrees in place, drawing a blue line as it goes. It does that four times, drawing a square, and ends back on its start mark facing the way it began. Beside it, the goal in words, a box naming each side and corner as it happens, and four check boxes that fill in as the sides are drawn.
Here's where you're headed. You'll get there one block at a time.

Activity · Build up to a square​

Three steps, each one a small change to the program you already have. Run the robot after every step — watching what it actually does is the point.

Step 1 · Drive straight​

Open XRP Code and start a new project. Your first job is small: find a block that makes the robot drive straight for 20 centimeters. Look through the block palette, drag it out, and set it up. Put a Wait for button press block above it so the robot waits for you.

Set the robot on the floor, click RUN, then press the button on the robot. Did it go 20 cm? Roughly where did it end up, and which way is it facing?

An animation, seen from above, of the step 1 program: Wait for button press, then Straight 20 cm. The robot waits, then drives forward 20 cm, drawing a short blue line from its start mark, and stops facing the same way it started. Beside it, the two blocks, with the one running highlighted.
Step 1: wait for the button, drive 20 cm, stop.

Step 2 · Add a turn​

Now change your program so that after driving straight, the robot turns 90 degrees. Find the block that turns, add it under the Straight block, set the angle, and run it again.

Before you press the button, predict: where will the robot end up, and which way will it be facing? Then check.

Knowledge Check

Your program is Straight 20, then Turn 90. After it runs, how has the robot changed from where it started?

Step 3 · Make a square​

Here's the real challenge: change your program so the robot drives a complete square and ends up back where it started, facing the same way.

You already know everything you need. Use the blocks you have. Try something, run it, watch what happens, adjust, run it again. It's fine if your first try is a triangle or an open box — that's information.

You've succeeded when the robot drives four roughly-equal sides, turns four corners, and finishes near its starting spot.

An animation, seen from above, of two attempts at step 3. In the first, the robot drives a side and turns a corner three times, drawing an open box that stops one side short of its start mark. In the second, it does it four times, drawing a closed square, and ends on its start mark facing the way it began. Beside it, a box names each side and corner as it happens and says whether the shape closed.
A first try that comes up one side short, then the fix. A wrong shape tells you what to change.

Once your square works, look at your program and answer these two questions:

  1. How many blocks did it take?
  2. Is there anything in it that's the same thing, over and over?
Knowledge Check

In the eight-block square, what is being repeated, and how many times?

Activity · A shorter way to say "four times"​

You just wrote the same two blocks four times. Imagine drawing a shape with 12 sides — 24 blocks. There has to be a better way, and there is: the palette has a block that repeats whatever you put inside it. Go find it.

Drag it out, set it to run 4 times, and move one Straight and one Turn inside it. Delete the other six blocks. Run it. Does the robot still draw a square?

Once yours works, you've used a loop: you write the instructions once, and the Repeat block runs them as many times as you tell it to. That's one of the most important ideas in all of programming, and you got to it by noticing your own program repeating itself.

Knowledge Check

A student's Repeat-4 program makes the robot drive one side and then stop. What's the most likely problem?

Activity · Now try a triangle​

Change your Repeat from 4 to 3. What angle should the turn be? Make your best guess, run it, and look at the result.

Didn't close? Before you read on, try this: walk the triangle yourself. Pace out a side, pivot at the corner the way the robot does, and keep going until you're back where you began, facing the way you started. How far did you turn in total, adding up all three corners? That total is the whole answer.

Now set your turn to the angle you worked out and run it again.

Knowledge Check

A classmate's triangle isn't closing up — the robot ends facing the wrong way. They used Turn 60°. What should it be?

Now do the reasoning on paper before you run anything else. Sketch a square and walk your pencil around it, writing the turn at each corner: four 90s that add up to 360. Then fill in the table for the rest:

ShapeSidesRepeatTurn angle
Triangle33____
Square44____
Pentagon55____
Hexagon66____
Octagon88____

Activity · Make other shapes​

Now you can draw any regular shape by changing just two numbers — the repeat count and the turn angle. Use your table, predict the shape, then run it:

  1. Pentagon — Repeat 5, and the turn angle from your table. Shorten the sides to 15 cm so it fits.
  2. Hexagon — Repeat 6, and its angle from your table.
  3. Your choice — pick a number of sides, work out 360 ÷ sides, predict the shape, run it. What happens as the number of sides gets big?

Check each one against your prediction before moving on: if the shape doesn't close, the angle and the repeat count disagree.

Knowledge Check

What turn angle do you need to draw a regular hexagon (6 sides)?

Knowledge Check

You change a working square program from Repeat 4 to Repeat 6, and set the turn to 60°. What does the robot draw?

Real-world connections​

Repeating a move-and-turn is exactly how machines make precise, repeatable paths:

Manufacturing

CNC machines

Cutting tools trace shapes by repeating precise move-and-turn steps, just at much finer scale.

Making

3D printers

Each layer is a looped path the print head repeats hundreds of times to build up an object.

Art

Pen plotters

Drawing robots turn loops of coordinates into logos, maps, and signatures on paper.

Wrap-up​

  • Why did the eight-block square work, and why is the Repeat version better? (Same result; one copy of the instructions instead of four, and easy to change.)
  • What's the rule for the turn angle? (360 ÷ number of sides.)
  • If a shape doesn't close, what's the first thing to check? (The turn angle — did the turns add up to 360?)

Resources​