My turtle

Snowfall

 

Task: Build snowfall


Code:

from turtle import *
import random

screen = Screen()
screen.bgcolor("dark blue")
screen.title("Snowfall")
screen.tracer(0) # switch off tracer
def branch(): # create one branch of the snowflake
    for i in range(3):
        for i in range(3):
            forward(7)
            backward(7)
            right(45)
        left(90)
        backward(7)
        left(45)
    right(90)
    forward(20)

def snowflake():
    clear()
    forward(10)
    left(45) 
    pendown()
    color('white')
    for i in range(8):
        branch()
        left(45) 
    hideturtle()
    penup()
    ycor()
    y = ycor()
    if y < -400: # if down go up
        goto(random.randint(-300, 300), 300)
    else:
        sety(y -3) # falling speeed   
    screen.update() # Renew screen
    screen.ontimer(snowflake, 1) # Call function back
snowflake()
mainloop()

2026-07-10 08:02:17

Comments

No comments yet. Be the first to leave one!

Leave a Comment