Python Program to Draw Snowflakes Using Turtle
#Draw Snowflakes in Python Using Turtle
import turtle
import random
# setup the window with a background colour
wn = turtle.Screen()
wn.bgcolor("black")
# assign a name to your turtle
elsa = turtle.Turtle()
elsa.speed(0)
# create a list of colours
sfcolor = ["white", "blue", "red", "grey", "magenta"]
# create a function to create different size snowflakes
def snowflake(size):
# move the pen into starting position
elsa.penup()
elsa.forward(10*size)
elsa.left(45)
elsa.pendown()
elsa.color(random.choice(sfcolor))
# draw branch 8 times to make a snowflake
for i in range(8):
branch(size)
elsa.left(45)
# create one branch of the snowflake
def branch(size):
for i in range(3):
for i in range(3):
elsa.forward(10.0*size/3)
elsa.backward(10.0*size/3)
elsa.right(45)
elsa.left(90)
elsa.backward(10.0*size/3)
elsa.left(45)
elsa.right(90)
elsa.forward(10.0*size)
# loop to create 20 different sized snowflakes with different starting co-ordinates
for i in range(20):
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(sf_size)
# leave the window open until you click to close
wn.exitonclick()
Output:
About The Author
Shailendra Bramhvanshi, Founder at Techaroha Solutions Private Limited and CEO at Newtum Solutions Private Limited. BlockChain Experts with 12 years of IT Experience in of all aspects of running Organization and Project Management. I have created different coins to help the business to bring more trust. Recently deployed a stable coin in India TrueINR and working on few cryptocurrency exchanges. My Team is being rated as a top 10 blockchain service provider in India by Silicon India