Canada Flag in Python Turtle
Intermediate · Flags · 60 lines · draws in about 11 seconds
This program draws the flag of Canada and fills the 11-pointed maple leaf from a list of points for its right half, mirrored to make the left.

How the code works
Half a leaf as a list of points
Each pair is an (x, y) point on the right edge of the maple leaf, from the foot of the stem up to the top point. The points follow the official leaf, scaled to a flag 280 high.
RIGHT_HALF = [ (5, -118), (2, -61), (59, -71), (52, -50), (108, -4), (93, 3), (105, 40), (70, 33), (63, 50), (29, 14), (44, 88), (21, 75), (0, 117), ]
Red, white, red
The flag is twice as long as it is high. Each red band is a quarter of the length and the white square in the middle is half of it.
rectangle(left, top, LENGTH / 4, HEIGHT, RED) rectangle(left + LENGTH / 4, top, LENGTH / 2, HEIGHT, "white") rectangle(left + LENGTH * 3 / 4, top, LENGTH / 4, HEIGHT, RED)
Mirroring the second half
The first loop goes up the right side through every point. The second loop comes back down through the same points in reverse order with -x, which is the left side, and the fill colours the whole leaf.
for x, y in RIGHT_HALF: t.goto(x, y) for x, y in reversed(RIGHT_HALF): t.goto(-x, y)
Make it yours
Change the code above and press Run. Some ideas:
- Add
t.pencolor("black")aftert.color(RED)in the leaf section to see the outline the turtle follows. - Change
t.speed(6)tot.speed(1)and count the 11 points of the leaf as the turtle reaches them. - Change
t.goto(-x, y)tot.goto(x, y)to see why the second half has to be mirrored.
What it uses
- lists of tuples
- reversed()
- goto with coordinates
- begin_fill and end_fill
Every turtle command the site supports is listed on Python turtle online.