Lesson 2 · Drawing Shapes
Lesson 2 · Drawing Shapes
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 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)
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.
Upload it, set the robot on the floor, press the button. Did it go 20 cm? Roughly where did it end up, and which way is it facing?
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.
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.
Once your square works, look at your program and answer these two questions:
- How many blocks did it take?
- Is there anything in it that's the same thing, over and over?
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.
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.
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:
| Shape | Sides | Repeat | Turn angle |
|---|---|---|---|
| Triangle | 3 | 3 | ____ |
| Square | 4 | 4 | ____ |
| Pentagon | 5 | 5 | ____ |
| Hexagon | 6 | 6 | ____ |
| Octagon | 8 | 8 | ____ |
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:
- Pentagon — Repeat
5, and the turn angle from your table. Shorten the sides to15cm so it fits. - Hexagon — Repeat
6, and its angle from your table. - 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.
What turn angle do you need to draw a regular hexagon (6 sides)?
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:
CNC machines
Cutting tools trace shapes by repeating precise move-and-turn steps, just at much finer scale.
3D printers
Each layer is a looped path the print head repeats hundreds of times to build up an object.
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?)