Skip to content

← Creating

Why Does a Turtle’s Star Close Up?

Topic 29 · Grades 6–8 · Angles and loops

Blocks, from Grade 6 (Programming with Blocks); one block program from Grade 7 (variables); the Python parts from Grade 8 (loops and functions).

What this builds on from class
In this unit 8 sections
  1. Try it
  2. How it works
  3. Program it
  4. What your program shows
  5. Going further still
  6. Challenges
  7. Questions
  8. Where to go next

At Tihar, families draw rangoli at the door: rings of petals, stars and lamps in colored powder, each part repeated round the middle. In Grade 6 you made the turtle draw a star with one loop, repeat 5 times: move 150 steps, turn right 144 degrees, and it came back to where it started. But 144 is a strange number. What happens with a different turn, say 100° or 103°? Does the turtle still come home, and how long does it take?

Try it now. Choose a turn, guess how many lines the turtle will draw before it is back at the start, facing the way it began, then press Draw.

Try it

Turn and turn again

Move the Turn slider (or press − and +), type your guess, then press Draw. Every line is the same length, and every turn is the same.

Start
Your guess:
lines
Lines
5
Times round
2
Turn as a share of 360°
144/360 = 2/5

Home after 5 lines. It turned 720° in all, exactly 2 whole turns, so its lines cross: a star with 5 points.

Before you try it: the turtle turns 103° after every line. What do you think happens?

Pick an answer to see why.

You need: block programs with repeat, from Grade 6 (Programming with Blocks). One block program uses variables, from Grade 7; the Python parts need loops and functions, from Grade 8.

Try it

Use the widget above. For each turn, write down how many lines it took.

  • a.Try 144°, 150°, 135° and 160°. Which make stars, and how many points does each have?
  • b.Try 90°, 120° and 72°, the turns from Grade 6. What do these draw?
  • c.Now try 100°, 102° and 103°. Do the numbers of lines follow any pattern you can see?
  • d.Watch Times round after each drawing. When do the lines cross each other, and when don’t they?

So the turtle always comes home, even at 103°, and never needs more than 360 lines. Is that luck, or is there a rule?

How it works

Home means a whole number of turns

The turtle starts facing right. After 2 lines it has turned twice the angle in all, after 3 lines three times, and so on. It faces right again only when the total turning is exactly 360°, or 720°, or 1080°: a whole number of turns.

For 144°: after 5 lines it has turned 5 × 144° = 720°, exactly 2 whole turns. So it faces right again after 5 lines, not before (1, 2, 3 and 4 lines give 144°, 288°, 432° and 576°, none of them a multiple of 360).

And when it faces the way it started, it is back at the start too (unless the turn is 0° or 360°: see below). Look at the widget’s faint dashed circle: every corner of every star lies on it. Each move-and-turn carries the turtle the same distance round that circle, so once its turns add up to whole turns, it has gone round the circle a whole number of times and is back at the first corner.

The turn as a share of a whole turn

Write the turn as a fraction of 360 and simplify it. For 144°:

144360=25 \frac{144}{360} = \frac{2}{5}

The bottom number, 5, is the number of lines. The top number, 2, is how many times the turtle goes round. Each line moves it on two fifths of a turn, so after 5 lines it has gone two whole turns.

To simplify the fraction, divide the top and the bottom by their HCF, the highest common factor you meet in maths class: the biggest number that divides both exactly. So:

  • lines until home = 360 ÷ HCF(turn, 360)
  • times round = turn ÷ HCF(turn, 360)

So for 103°: 103 and 360 have no common factor except 1, so 103/360 can’t be simplified. The turtle needs 360 lines and goes round 103 times, as does any whole-number turn that shares no factor with 360 except 1 (101°, 107°…).

The turtle turns 135° each time. How many lines does it draw before it is home?

Pick an answer to see why.

A star or a shape?

If the top of the fraction is 1, the turtle goes round once and its lines never cross: 90/360 = 1/4, a square. If the top is 2 or more, it goes round more than once and the lines cross: a star. That is why the pentagon (72/360 = 1/5) and the star (144/360 = 2/5) both have 5 lines: the star is the pentagon’s corners joined “every second one”.

Program it

With blocks: a program that counts the lines

The widget knew when to stop. Your program can know too. This block program asks for the turn, then keeps drawing until the total turning is a whole number of 360s. It uses the remainder block: the remainder of turned ÷ 360 is 0 exactly when turned is 360, 720, 1080…

The loop is a repeat until. It checks its condition before each round, and at the start nothing has been turned yet (0 ÷ 360 leaves remainder 0 too), so the condition also asks for at least one line: lines > 0 and the remainder of turned ÷ 360 = 0.

Try it

The turtle that counts its lines

Press Run and type 144. Then try 150, 100, 170 and 103. (103 takes a few seconds: 360 lines.)

What the program says and asks appears here.

angle – no value
lines – no value
turned – no value

Press Run to start the program, or Step to do one block at a time.

Loading the blocks…

A mandala from a loop inside a loop

One star repeated, turned a little each time, makes a mandala, as Grade 6’s twelve squares made a flower. This program draws a five-pointed star, turns 36°, and does it again, 10 times: 10 × 36° = 360°, so the stars go evenly all the way round the point they share.

Try it

A mandala of stars

Run it. Then change the inside loop to another star (12 lines of 150°, or 9 of 160°), and the outside loop to another number of stars. The outside turn must be 360 ÷ the number of stars.

Press Run to see what the turtle does.

Loading the blocks…

The same rule works twice here: the inside loop closes because 5 × 144° is 2 whole turns, and the outside loop closes because 10 × 36° is 1 whole turn.

In Python (from Grade 8)

In Python, the counting program is a function that adds one line at a time until the total turning divides exactly by 360 (% gives the remainder, as the block does). It only counts, without drawing, so it is fast.

def lines_home(turn):    lines = 0    turned = 0    while lines == 0 or turned % 360 != 0:        lines = lines + 1        turned = turned + turn    return lines for turn in [144, 150, 100, 103, 170]:    lines = lines_home(turn)    print('Turn', turn, ': home after', lines, 'lines, round', turn * lines // 360, 'times')

Output

Turn 144 : home after 5 lines, round 2 timesTurn 150 : home after 12 lines, round 5 timesTurn 100 : home after 18 lines, round 5 timesTurn 103 : home after 360 lines, round 103 timesTurn 170 : home after 36 lines, round 17 times

Every turn at once

Now ask about every whole-number turn from 1° to 180° and list the different numbers of lines. (Turns over 180° draw the same stars the other way round: turning right 216° is turning left 144°.)

def lines_home(turn):    lines = 0    turned = 0    while lines == 0 or turned % 360 != 0:        lines = lines + 1        turned = turned + turn    return lines counts = []all_360 = 0for turn in range(1, 181):    n = lines_home(turn)    if n not in counts:        counts.append(n)    if n == 360:        all_360 = all_360 + 1counts.sort()print(len(counts), 'different numbers of lines:')print(counts)print(all_360, 'turns need all 360 lines') never = []for n in range(3, 25):    if n not in counts:        never.append(n)print('Never drawn:', never)

Output

23 different numbers of lines:[2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360]48 turns need all 360 linesNever drawn: [7, 11, 13, 14, 16, 17, 19, 21, 22, 23]

Look at the last line: with whole-number turns, never 7 lines, nor 11, 13, 14 or 16.

Checking the rule

Is “360 ÷ the HCF” really right for every turn, or only for the ones we tried? A program can check all 180. This one finds the HCF by trying every number up to 360.

def lines_home(turn):    lines = 0    turned = 0    while lines == 0 or turned % 360 != 0:        lines = lines + 1        turned = turned + turn    return lines def hcf(a, b):    best = 1    for d in range(1, b + 1):        if a % d == 0 and b % d == 0:            best = d    return best agree = 0for turn in range(1, 181):    if lines_home(turn) == 360 // hcf(turn, 360):        agree = agree + 1print(agree, 'of 180 turns follow the rule') for turn in [144, 150, 100]:    h = hcf(turn, 360)    print(turn, '/ 360 =', turn // h, '/', 360 // h)

Output

180 of 180 turns follow the rule144 / 360 = 2 / 5150 / 360 = 5 / 12100 / 360 = 5 / 18

A seven-pointed star after all

The block editor only takes whole degrees, but Python’s turtle can turn by any amount, even a fraction of a degree. A seven-pointed star that goes round twice needs 720° ÷ 7 = 102.857…° a turn, and one that goes round three times 1080° ÷ 7 = 154.285…°. Python works them out as 360 * 2 / 7 and 360 * 3 / 7.

import turtlet = turtle.Turtle()for times in [2, 3]:    for i in range(7):        t.forward(120)        t.right(360 * times / 7)    t.penup()    t.forward(220)    t.pendown()

Press Run: two seven-pointed stars, one thin and one spiky, side by side. (turtle here is the page’s own turtle; on a computer, Python’s turtle draws the same in a window.)

What your program shows

Your Python program found 23 different numbers of lines. Now list the numbers from 2 to 360 that divide 360 exactly:

divides = []for d in range(2, 361):    if 360 % d == 0:        divides.append(d)print(divides)

Output

[2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360]

The two lists are the same. A turtle that turns a whole number of degrees always comes home, after at most 360 lines, and the number of lines is always a number that divides 360. Whether the turtle comes home, and after how many lines, depends only on one thing: the turn as a fraction of 360, simplified, and your program checked that rule for all 180 turns.

So a seven-pointed star is impossible in whole degrees, because 7 doesn’t divide 360; so is a 7-sided shape, which is why Grade 6’s table of turns skipped from 6 sides to 8.

What about a turn that is not a fraction of 360 at all? Any turn you can type, like 137.5°, is a fraction (137.5/360 = 55/144), so the turtle does come home, after 144 lines. But some numbers can’t be written as any fraction: the golden angle, 137.5077…°, whose digits never end or repeat, is one. A turtle that turned by exactly the golden angle would never face right again, however long it went on: it would draw for ever. Plants come close to it when they place their seeds and leaves, as Why Do Sunflowers Count in Fibonacci Numbers? shows.

Going further still

Repeat more than one move. The rule works for any repeated group of blocks: add up all the turns in one round, and the drawing closes when that total, times the rounds, is a whole number of 360s. Try repeat: move 100, turn right 90, move 50, turn right 60. One round turns 150°; how many rounds until it closes? (A round that turns 0° in all, or 360°, never closes unless it already ends where it began: it walks off across the screen.)

The sun on Nepal’s flag. The flag’s sun has 12 rays. Its outline is a zigzag of 24 lines: at each ray’s tip the turtle turns one way, at the dip between rays it turns back a little. For the outline to close, the two turns of one ray must add up to 360° ÷ 12 = 30°. Try tip 120° right, dip 90° left, with all lines the same length. Then see how the flag is really drawn in Draw Nepal’s Flag.

Challenges

★ The eight-pointed star (blocks)

Make the turtle draw the faint eight-pointed star. The program starts with 8 lines and turns of 90°, which only draws a square twice over.

Try it

★ The eight-pointed star

Make the turtle draw the faint gray shape, then press Run.

Loading the blocks…

Hint
Answer

★★ Four nine-pointed stars (blocks)

Make the turtle draw the faint mandala: four nine-pointed stars round one point. The program starts with one five-pointed star.

Try it

★★ Four nine-pointed stars

Make the turtle draw the faint gray shape, then press Run.

Loading the blocks…

Hint
Another hint
Answer

★★★ Every star with so many points (Python, from Grade 8)

Write star_turns(points): a list, from smallest to largest, of every whole-number turn from 1° to 179° that makes the turtle draw a star (its lines crossing) with exactly that many points. For 5 it gives [144]; for 7 it gives [].

def star_turns(points):    # every whole-number turn from 1 to 179 that draws a star with this many points    return [] print(star_turns(9))

Try it

★★★ Every star with so many points

  1. 9 points star_turns(9) Should give [80, 160] Yours —
  2. 5 points star_turns(5) Should give [144] Yours —
Tests passed
— / 11
Challenge
★★★ solved

Write your star_turns in the program above (Edit), then check it.

A test your function gets wrong, anything it prints, and any error appear here.

Hint
Another hint
Answer

Questions

The turtle turns 40° after every line. What does it draw?

Pick an answer to see why.

a.

How many lines does the turtle draw with a turn of 165°, and how many times does it go round? Show your working.

Answer
b.

Explain why a turtle that turns a whole number of degrees can never draw a seven-pointed star.

Answer
c.

A friend says: “With a turn of 1°, the turtle draws a circle.” Is your friend right? Explain.

Answer
d.

In the block program, why does the repeat until need “lines > 0” as well as “the remainder of turned ÷ 360 = 0”?

Answer

Where to go next

Found a mistake? Please tell us.