Mirror Butterfly¶
By the end of this lab you'll be able to:
- Create bilateral symmetry by negating the x-coordinates of a list of waypoints
- Draw the right wing of a butterfly using
goto()waypoints, then mirror it automatically - Understand how
(x, y) → (-x, y)produces a perfect mirror reflection
A colorful butterfly built from two coordinate lists — the right wing drawn from waypoints, the left wing created automatically by negating all x-coordinates. One list, two wings.
Welcome to the Mirror Butterfly!
Every butterfly has bilateral (mirror) symmetry — the left wing is exactly
the mirror of the right. In code, mirroring is just one character: a minus sign!
Let's code it together!
How It Works¶
The right wing is defined as a list of (x, y) waypoints. To get the left wing, we create a new list where every x is negated: (-x, y). We draw both wings using goto() and begin_fill()/end_fill().
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
What Do You Think Will Happen?
The left wing is created with (-x, y). Will it look like a perfect mirror of the right,
or will it look upside down?
Make your guess — then click Run to find out!
Try It Now¶
A perfect mirror — negating x flips the shape left-to-right without changing top-to-bottom. Were you right?
How It Works¶
[(-x, y) for x, y in right_wing] is a list comprehension that transforms every coordinate pair. The - before x flips horizontally. The y stays the same so there's no vertical flip.
The black body is drawn as a vertical line from tail to head using setheading(90) (straight up) and forward(200).
Explanation Table¶
| Line | What it does |
|---|---|
right_wing = [(x,y), ...] |
Waypoints defining the right wing shape |
[(-x, y) for x, y in right_wing] |
Mirror: negate all x-coordinates |
monty.goto(x, y) |
Move turtle to each waypoint, drawing as it goes |
begin_fill() / end_fill() |
Fill the wing shape |
Learning Check¶
Your Turn — Flip Vertically Instead
Change (-x, y) to (x, -y) to flip vertically instead of horizontally.
Predict what the result will look like — then run it to check!
(x, -y) flips top-to-bottom — the bottom wing is the vertical reflection of the right wing, in a different color to distinguish them.
Experiments¶
-
Add wing markings. After drawing the filled wings, add a smaller
right_innerlist with fewer points and draw it withpencolor('black')and no fill. You'll know it worked when the wings have outlines. -
Change the body. Replace the straight line body with a series of dots in decreasing size. You'll know it worked when the body looks segmented.
-
Use 4 wings. Also draw
left_wingandbottom_wingto make a four-winged dragonfly. You'll know it worked when four wings radiate from the center. -
Add antennas. After the body, draw two thin lines from the top of the body curving outward. You'll know it worked when the butterfly has antennas.
Beautiful Symmetry!
You used (-x, y) to create perfect bilateral symmetry — the same math used
in computer animation to mirror a character's left and right sides!
Up next: Truchet Tiles — random tiles that form unexpected global patterns.