-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_turtle_game.py
42 lines (35 loc) · 967 Bytes
/
my_turtle_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import turtle
# Function to draw the Koch curve
def koch_curve(t, length, depth):
if depth == 0:
t.forward(length)
else:
length /= 3.0
koch_curve(t, length, depth-1)
t.left(60)
koch_curve(t, length, depth-1)
t.right(120)
koch_curve(t, length, depth-1)
t.left(60)
koch_curve(t, length, depth-1)
# Function to draw the Koch snowflake
def koch_snowflake(t, length, depth):
for _ in range(3):
koch_curve(t, length, depth)
t.right(120)
# Set up the turtle graphics environment
screen = turtle.Screen()
screen.bgcolor("white")
t = turtle.Turtle()
t.speed(0)
# Set the turtle speed to the maximum
# Draw the Koch snowflake
length = 300 # Length of each side of the snowflake
depth = 4 # Recursion depth
t.penup()
t.goto(-length / 2, length / 3)
t.pendown()
koch_snowflake(t, length, depth)
# Hide the turtle and display the window
t.hideturtle()
turtle.done()