Christmas decorations, snowflakes and reflection symmetry

Christmas decorations, snowflakes and reflection symmetry#

An observant reader of Christmas decoration, snowflakes and rotational symmetry (which we recommend you read before this tutorial) might have noticed snowflakes often have more than just rotational symmetry. Snowflakes also have reflection symmetry, meaning that if we look at the mirror image of one of the “arms”, it’s the same as the original image.

../_images/pexels-eberhard-grossgasteiger-12366087.jpg

Reflective symmetry#

Landscape reflected in water (image by Eberhard Grossgasteiger).

Use reflection symmetry to reduce the number of code lines#

When drawing an image with reflection symmetry, we can use a loop to cut down on how many lines of code we need (like what we did with rotation symmetry). Below is the code we used to create a snowflake in Christmas decoration, snowflakes and rotational symmetry. Looking closely, we can see that lines 11-14 and 21-24 are very similar, but the angles point in opposite directions.

 1import turtlethread
 2
 3needle = turtlethread.Turtle()
 4with needle.running_stitch(30):
 5
 6    for arm in range(6):
 7        # Move forward a little bit
 8        needle.forward(90)
 9
10        # Draw the first "branch" pointing a little downwards
11        needle.right(30)
12        needle.forward(60)
13        needle.backward(60)
14        needle.left(30)
15    
16        # Move forward and then back again
17        needle.forward(90)
18        needle.backward(90)
19    
20        # Draw the second "branch" pointing a little upwards
21        needle.left(30)
22        needle.forward(60)
23        needle.backward(60)
24        needle.right(30)
25
26        # Move backwards to the starting point
27        needle.backward(90)
28
29        # Rotate 60 degrees to the right to draw six branches
30        needle.right(60)
31
32needle.visualise()
The result from the above code. A snowflake with six arms.

To take advantage of the reflection symmetry, we first need to notice that rotating 30 degrees to the left is the same as rotating -30 degrees to the right. This means we can replace left with right if we add a negative sign to the angle.

 1import turtlethread
 2
 3needle = turtlethread.Turtle()
 4with needle.running_stitch(30):
 5
 6    for arm in range(6):
 7        # Move forward a little bit
 8        needle.forward(90)
 9
10        # Draw the first "branch" pointing a little downwards
11        needle.right(30)
12        needle.forward(60)
13        needle.backward(60)
14        needle.right(-30)
15    
16        # Move forward and then back again
17        needle.forward(90)
18        needle.backward(90)
19    
20        # Draw the second "branch" pointing a little upwards
21        needle.right(-30)
22        needle.forward(60)
23        needle.backward(60)
24        needle.right(30)
25
26        # Move backwards to the starting point
27        needle.backward(90)
28
29        # Rotate 60 degrees to the right to draw six branches
30        needle.right(60)
31
32needle.visualise()
Result from the code above. A snowflake with six arms.

Because we can change direction by changing the sign of the angle, we can use a for loop over -1 and 1 to loop over two different directions:

 1import turtlethread
 2
 3needle = turtlethread.Turtle()
 4with needle.running_stitch(30):
 5
 6    for arm in range(6):
 7        for direction in [-1, 1]:
 8            # Move forward a little bit
 9            needle.forward(90)
10
11            # Draw the "branch", which will point either downards or upwards, depending on the direction
12            needle.right(30*direction)
13            needle.forward(60)
14            needle.backward(60)
15            needle.right(-30*direction)
16        
17            # Move a bit forward and then back to start
18            needle.forward(90)
19            needle.backward(180)
20
21        # Rotate 60 degrees to the right to draw six branches
22        needle.right(60)
23
24needle.visualise()
Result from the code above. It's identical to the image generated by the previous conde snippet.

We can see that this code contains a lot fewer lines!

Finished snowflake#

An image of the finished embroidered snowflake.

Example snowflakes#

Try it yourself:

Use code to embroider your own snowflake with both rotational and reflection symmetry! Below is a gallery of examples you can use as a starting point or for inspiration.

Snowflake 1

A snow flake arm with four branches, the first points backward and the rest point forward.

Snowflake 2

A snow flake arm that looks like a half heart.

Snowflake 3

A snow flake arm with four circles next to each other. Each subsequent circle is smaller than the previous.