The ideas for coding in TurtleStitch come from the nature around us. In this multidisciplinary blog posting, I will explore the science, literature and mathematics of snowflakes and the different methods of coding snowflakes in TurtleStitch.
Snowflakes are a thing of beauty and wonder.
An interesting book about snowflakes is Snowflake Bentley, https://www.youtube.com/watch?v=rtyLpo3cWic, by Jacqueline Briggs Martin. This book depicts the true story of child named Wilson Bentley, who was fascinated with snowflakes. Bentley's enthusiasm was misunderstood at the time. He started his passion for snowflakes by drawing them. When he was seventeen, his parents gifted him a microscopic camera to photograph the snowflakes to document the uniqueness of the snowflake shapes.
Here are two ways to make a spoke. It doesn’t matter which one that you choose.
Coding a Snowflake
Here are two versions of code for a snowflake. They both produce the snowflake on the right.
Comparing Coding Techniques
Comparing the snowflake code after one repeat, the turtle is located in different positions. The red arrow represents the starting point of the turtle.
The screen capture above, the turtle has already traversed the same line twice and is positioned to move.The distance travelled in both cases will be the same after six repeats.
Another difference is the turtle travels in a clockwise motion in the screen capture on the left. The turtle moves in a counterclockwise motion on the right.
More Comparisons
The answer is the direction in which the turtle is pointing. This is an important concept in TurtleStitch and it is hard to envision without an example like this. The move is different because it is an interior angle.
In the figure shown, the blue area represents the interior of the hexagon. The angle y forms a 120 degree angle. The angle x in yellow represents the exterior angle and it forms a 60 degree angle.
Both sets of codes accomplish the same result. It is interesting to see mathematical concepts come to life with the move of the turtle in TurtleStitch.
For future reference, to calculate the move for a polygon of n sides, the interior angle formula is:
180 - (360/n)
Adding An Endpoint to the Snowflake Spoke
The first move of 10 steps is to move away from the center of the snowflake to eliminate density warnings.
Looking at the code, the interior loop of ‘repeat 10' means there are 10 branches on each spoke at a 60 degree angle to the spoke in 50 steps.
I did not use a pen up or down when moving the turtle along the branch because I wanted some thread weight to each branch. I turned 180 degrees minus the angle measure to get back to the center of the spoke.
I repeated the 60 degree angle move on the other side of the spoke for each branch and returned back to the center of the spoke.
I moved the turtle 50 steps to the next branch position and repeated the move back and forth across the spoke.
Once the 10 branches were made, the turtle was moved back to the center of the snowflake (0,0).
This spoke code was repeated 6 times to complete the snowflake.
The overlying branches in the center of the snowflake produce the interesting pattern in the center of the snowflake.
Continuing the quest to code beautiful snowflakes.
This program is exactly the same as the previous program except the variable names were given a range of values with the ‘pick random’ block. This generates random numbers between the numbers that were specified.
Each time the program is run, a different randomized snowflake is created with different number of branches, with different angles at which the pair of branches intersect the main spoke, different branch lengths and different spacing between the branches.
If you like a certain snowflake design, write down the randomized number that created the snowflake to recreate it. Remove the ‘pick random’ block and replace it with the values that you like. The values are shown in the stage area.
Another iteration of the snowflake program.
This program generates nine random snowflakes because there are two nested ‘for’ loops which creates the rows and columns of snowflakes. This ‘for’ loop block is in the ‘drop down’ library.
The “for x” value represent the rows and the “for y” value represents the columns.
The interior ‘for’ loop is executed first to create one row of snowflakes.
The exterior ‘for loop’ is then executed to create one column of snowflakes.
The code bounces back and forth between the ‘for’ loops until all the conditions are met.