Programming Snowflakes

The snowflake module extends the Turtle class to enable the easy creation of simple snowflakes. This module is built into the Python Adventures (pythonadventures.co.uk) online IDE and is also downloadable for use in other IDEs. The module can be downloaded below. The easiest way to use it is to place the file in the same directory as your program.

Snowflake Module Download

Activity

Examine the starter code below and predict what you think will happen when the program runs:

import snowflake

s = snowflake.Snowflake()

def mySnowflake():
    s.drawbranch(60)
    s.drawbranch(60)
    s.drawbranch(60)

s.pencolor("blue")
s.goto(-100,100)
mySnowflake()

s.goto(100,-100)
mySnowflake()

You can load the starter program in Python Adventures or download it and open it in an IDE of your choice. Run the program and test your predictions.

Starter Program Download

Now work through these tasks*:

  1. Improve the mySnowflake function so it draws all six branches of the snowflake.
  2. Adapt the program so it draws two more snowflakes in different locations and with different colours.
  3. There are lots of repeated instructions in the mySnowflake function, use a loop to repeat the instruction the required number of times.
  4. The drawbranch method has optional parameters which allow us to customise the length, number of arms and arm width. The example below shows how they can be used. Customise your snowflake using these optional parameters.
drawbranch(60, length=50, arms=2, armsize=20)

  1. Create a new function that draws a snowflake with 8 branches, with custom parameters of your choice. HINT: You will need to change the angle.
  2. Use your snowflake functions to create your own original design on the canvas.

*these task details can also be accessed by clicking on the ‘i’ button in the Python Adventures version of the activity.

One thought on “Programming Snowflakes

Leave a Reply

Your email address will not be published. Required fields are marked *