# Geek Gurl Diaries Episode 33: Xmas Special Make Snowflakes with Turtle # By Carrie Anne Philbin # mod: Matija Lokar, march 2016 # https://www.youtube.com/watch?v=DHmeX7YTHBY import turtle import random def snowflake(turt, size): '''create different size snowflakes''' # move the pen into starting position turt.penup() turt.forward(10*size) turt.left(45) turt.pendown() turt.color(random.choice(sfcolor)) # draw branch 8 times to make a snowflake for i in range(8): branch(turt, size) turt.left(45) def branch(turt, size): '''create one branch of the snowflake''' for i in range(3): for i in range(3): turt.forward(10.0*size/3) turt.backward(10.0*size/3) turt.right(45) turt.left(90) turt.backward(10.0*size/3) turt.left(45) turt.right(90) turt.forward(10.0*size) # setup the window with a background colour wn = turtle.Screen() wn.bgcolor("cyan") # assign a name to your turtle elsa = turtle.Turtle() elsa.speed(0) # create a list of colours sfcolor = ["white", "blue", "purple", "grey", "magenta"] # loop to create 5 different sized snowflakes with different starting co-ordinates for i in range(5): x = random.randint(-200, 200) y = random.randint(-200, 200) sf_size = random.randint(1, 4) elsa.penup() elsa.goto(x, y) elsa.pendown() snowflake(elsa, sf_size) # leave the window open until you click to close elsa.hideturtle() wn.exitonclick()