Pen Power: Shapes and Flowers

Pen Power: Shapes and Flowers: Block Coding lesson banner with Beep and Pixel

Track: Block Coding  ·  Lesson 9 of 10  ·  Ages: 8+  ·  Time: 45 minutes

Today Beep becomes an artist! With the pen blocks, Beep carries a pen and draws a line wherever it walks. A few simple blocks can draw triangles, stars, circles and even flowers. And there is a secret maths rule that makes it all work.

Beep says I walk, I turn, and my pen leaves a trail. I only know how to do those two things, but with them I can draw almost anything. Beep boop!

What you need

  • A block-coding app that a grown-up has helped you open, with pen blocks. In many apps the pen blocks live in a menu of extra blocks that you add.
  • Paper and a pencil for planning.
  • About 45 minutes.

Grown-ups This lesson quietly teaches an important geometry fact: when you walk all the way round any simple shape and end up facing the way you started, you have turned a total of 360 degrees. Your child does not need to know the word “exterior angle” yet, but they will use the idea. If your child enjoys it, follow up by asking them to predict the turn for a shape before they build it.

Words to know

  • The pen leaves a line when it is down and stops drawing when it is up.
  • A polygon is a flat shape made of straight sides, like a triangle, square or hexagon.
  • A degree is a tiny unit of turning. A whole turn all the way round is 360 degrees.

Pen blocks

The main pen blocks are pen down (start drawing), pen up (stop drawing), pen colour and pen size. Here is a hexagon, a shape with 6 sides:

A script that sets the pen colour to pink, the pen size to 3, puts the pen down, and then repeats 6 times: move 80 steps and turn right 60 degrees.

Beep draws six sides of 80 steps each. At every corner it turns 60 degrees. Check the maths: 6 turns of 60 degrees is 6 × 60 = 360 degrees, one whole turn.

The magic rule

Look at these shapes and the turn at each corner:

ShapeSidesTurn at each cornerCheck: sides × turn
Triangle31203 × 120 = 360
Square4904 × 90 = 360
Pentagon5725 × 72 = 360
Hexagon6606 × 60 = 360
Octagon8458 × 45 = 360
12-sided shape123012 × 30 = 360

Do you see the pattern? Turn = 360 ÷ number of sides. Beep must turn a whole 360 degrees by the time it gets back to the start, and each corner shares that turning equally.

Pixel says The inside of a corner on an equal-sided triangle is 60 degrees, but Beep turns 120. That is because the turn is the outside of the corner: how far Beep has to swing to face down the next side. The inside angle and the turn always add up to 180. Meow!

Nearly a circle

What if we use a shape with lots and lots of tiny sides? Try 36 sides, each 10 steps long. The turn is 360 ÷ 36 = 10 degrees:

A script with pen down and a repeat 36 loop that moves 10 steps and turns right 10 degrees.

The sides are so short and the corners so gentle that Beep draws what looks like a circle! The more sides you use, the rounder it gets.

A flower

Now for the best trick: a loop inside a loop. The inside loop draws a square. The outside loop draws it 10 times, and turns a little after each square, so the squares fan out and spin round a centre, like the petals of a flower.

A script with pen colour hotpink and pen down, then an outer repeat 10 loop. Inside it, a repeat 4 loop draws a square with move 80 steps and turn right 90 degrees, and then Beep turns right 36 degrees.

Why 36? We want 10 petals to fill one whole turn, and 360 ÷ 10 = 36. So after each petal Beep turns 36 degrees, and after 10 petals it has turned 360 degrees and is back where it began.

Same idea in Python

Here is the flower again as a Python turtle program. The loop inside a loop is a for inside a for:

import turtle

t = turtle.Turtle()
t.pencolor("hotpink")
t.pensize(2)
for petal in range(10):
    for side in range(4):
        t.forward(80)
        t.right(90)
    t.right(36)

turtle.done()
The drawing made by the turtle code above
This is what the code above draws.

When you run it, you see ten squares turned round one middle point, like a spinning flower. Look at the pushed-in lines. The t.right(36) is indented once, so it belongs to the petal loop and happens after each square. The forward and right(90) lines are indented twice, so they belong to the inside loop.

Challenges

Try it Draw an octagon (8 sides). What is the turn? Then guess the turn for a shape with 9 sides, and for one with 20 sides.

Show a hint

Use the rule: turn = 360 ÷ number of sides.

Show the answer

For 8 sides, the turn is 360 ÷ 8 = 45 degrees. For 9 sides, it is 360 ÷ 9 = 40 degrees. For 20 sides, it is 360 ÷ 20 = 18 degrees.

A script with pen down and a repeat 8 loop that moves 60 steps and turns right 45 degrees.

Try it Change the flower so it has 6 petals instead of 10. What turn do you need after each petal? What if you want 12 petals?

Show the answer

For 6 petals, turn 360 ÷ 6 = 60 degrees after each one, and repeat the outside loop 6 times. For 12 petals, turn 360 ÷ 12 = 30 degrees, and repeat 12 times.

Try it Here is a surprise. Draw a star by repeating 5 times: move 100 steps, then turn right 144 degrees. Does it work?

Show the answer

Yes! You get a five-pointed star. Beep turns so far each time that it skips a corner. The total turn is 5 × 144 = 720 degrees, which is exactly two whole turns, so Beep still finishes where it started.

import turtle

t = turtle.Turtle()
t.pencolor("gold")
t.pensize(4)
for point in range(5):
    t.forward(100)
    t.right(144)

turtle.done()
The drawing made by the turtle code above
This is what the code above draws.

Did you know? A children’s programming language called Logo was created in the 1960s. Kids used it to steer a turtle that drew lines, first a little floor robot with a pen and later a turtle on the screen. The Python turtle is named after those turtles.

What you learned

  • Pen blocks leave a trail when the pen is down.
  • To draw a shape with any number of sides, turn 360 ÷ the number of sides at every corner.
  • Shapes with many tiny sides look like circles.
  • A loop inside a loop can draw a flower made of squares.