Turtle Snowflakes (with Python) Tutorial
NOTE: A complete lesson (fully mapped to England, Wales, CSTA and ISTE standards) can be found by here:
Turtle snowflakes
Turtle snowflakes
Part 1
Start by running the following code. Can you guess what shape the code is trying to make?
Start by running the following code. Can you guess what shape the code is trying to make?
The above code will create a square using the turtle library in Python.
Let's explore the code:
import turtle - Imports the turtle library
window = turtle.Screen() - Creates a new blank canvas to draw on
timmy = turtle.Turtle() - Creates a new turtle called timmy
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
Challenge 1
Using the sample code (above) draw each of the following shapes:
Sample code:
https://trinket.io/python/ed15bdc4a6
Let's explore the code:
import turtle - Imports the turtle library
window = turtle.Screen() - Creates a new blank canvas to draw on
timmy = turtle.Turtle() - Creates a new turtle called timmy
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
timmy.forward(100) - Move the turtle forward 100 steps
timmy.right(90) - Rotates the turtle right by 90 degrees
Challenge 1
Using the sample code (above) draw each of the following shapes:
- Triangle
- Hexagon
Sample code:
https://trinket.io/python/ed15bdc4a6
Part 2
Can you identify the repeating pattern in the first example (shown above)?
Answer: The instructions forward(100) + right(90) are repeated 4 times!
We can optimise our code by ‘using a loop’. For example:
Can you identify the repeating pattern in the first example (shown above)?
Answer: The instructions forward(100) + right(90) are repeated 4 times!
We can optimise our code by ‘using a loop’. For example:
Challenge 2
Optimise your solutions for each of the shapes in challenge 1 (Triangle & Hexagon) by using loops.
Helpful resources
angles_worksheet.pdf |
Part 3 - Snowflake Challenge
Run the following code:
Run the following code:
Challenge 3
Using the example code above, create your own snowflake in Python.
Worked example:
https://trinket.io/python/144a0d13f5
Using the example code above, create your own snowflake in Python.
Worked example:
https://trinket.io/python/144a0d13f5
Top tip: The last rotation (which in the above example 90 is degrees) can be calculated by dividing 360 degrees by the first 'repeat' value.
For example, if the first repeat is 6 then the last turn should be 360 / 6 = 60. Try it! :)
Advanced Snowflake
Below is another example of a snowflake. Can you make it better?
For example, if the first repeat is 6 then the last turn should be 360 / 6 = 60. Try it! :)
Advanced Snowflake
Below is another example of a snowflake. Can you make it better?
You may also be interested in:
Tags: programming language scratch, scratch programming language, scratch coding language, programming languages scratch, scratch code language, scratch programming language.