Pentagon Chain¶
By the end of this lab you'll be able to:
- Compute the exterior angle of any regular polygon with
360 / sides - Position shapes in a horizontal row by advancing the turtle between them
- Use
begin_fill()andend_fill()with two alternating colors
Ten pentagons march in a row, alternating purple and gold — a bracelet of five-sided tiles stretching across the canvas.
Welcome to the Pentagon Chain!
In this lab you'll learn the one formula that draws any regular polygon,
then chain 10 of them in a row. Let's code it together!
How the Chain Works¶
A regular polygon with n sides needs an exterior angle of 360 / n degrees at each corner.
For a pentagon (5 sides): 360 / 5 = 72°.
After drawing each pentagon, the turtle is back at the starting corner.
Moving forward by size steps places the turtle at the next pentagon's starting corner.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
What Do You Think Will Happen?
The exterior angle of a pentagon is 72°. After drawing all 5 sides, how many total degrees
has Monty turned? (Hint: 5 × 72° = ?)
Make your guess — then click Run to find out!
Try It Now¶
5 × 72° = 360° — a complete rotation. That's why the turtle always ends up facing the same direction after any regular polygon. Were you right?
How It Works¶
The inner loop for _ in range(sides) draws one pentagon. After each side, right(angle) rotates by the exterior angle. After all 5 sides, the turtle is back at the start facing the original direction.
monty.forward(size) after end_fill() advances the turtle by exactly one side length, placing it at the first corner of the next pentagon — so the chain connects corner-to-corner.
Explanation Table¶
| Line | What it does |
|---|---|
angle = 360 / sides |
Exterior angle formula — works for any regular polygon |
monty.goto(-270, 0) |
Start near the left edge |
for _ in range(sides) |
Draw one side + one turn, repeated sides times |
monty.end_fill() |
Fill the completed pentagon |
monty.forward(size) |
Advance to the next pentagon's starting corner |
Learning Check¶
Your Turn — Make a Hexagon Chain
Change the code below to draw a chain of hexagons (6 sides) instead of pentagons.
You'll need to update sides and you may want to reduce size slightly to fit 8 hexagons.
Change sides = 5 to sides = 6. The angle updates automatically to 360 / 6 = 60°.
Experiments¶
-
Try squares. Change
sides = 4andsize = 50. Eight squares will chain across the canvas. You'll know it worked when you see a row of colored squares. -
Use three colors. Change
colorsto['purple', 'gold', 'crimson']andi % 2toi % 3. You'll know it worked when three colors cycle across the chain. -
Make a vertical chain. After
monty.goto(-270, 0), addmonty.setheading(90). The chain will march upward. You'll know it worked when the pentagons stack vertically. -
Change the number of pentagons. Replace
range(10)withrange(6). Adjust the starting x position so the shorter chain is still centered. You'll know it worked when 6 pentagons appear centered on the canvas.
Great Work!
You mastered the exterior angle formula 360 / sides — the key to drawing
any regular polygon in Python. Change one number, change the whole shape!
Up next: Overlapping Squares to explore draw order and transparency effects.