Skip to content

Commit ab26728

Browse files
authored
Merge pull request #11 from deshpande-shruti/koch_snowflake
created snowflakes using Turtle graphics
2 parents 496df9e + 966a98b commit ab26728

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Turtle-a-thon/Snowflakes/snowflake.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import turtle
2+
t = turtle.Turtle()
3+
t.hideturtle()
4+
#turtle.tracer(0)
5+
6+
def draw_koch_curve(t, length, depth):
7+
if depth == 0:
8+
t.forward(length)
9+
else:
10+
for angle in [60, -120, 60, 0]:
11+
draw_koch_curve(t, length / 3, depth - 1)
12+
t.left(angle)
13+
14+
def draw_koch_snowflake(t, start_pos, length, depth, color):
15+
t.penup()
16+
t.goto(start_pos)
17+
t.pendown()
18+
19+
t.begin_fill()
20+
for i in range(3):
21+
t.pencolor(color)
22+
t.fillcolor(color)
23+
draw_koch_curve(t, length, depth)
24+
t.right(120)
25+
t.end_fill()
26+
27+
# Turtle setup
28+
turtle.bgcolor('black')
29+
t.speed(0)
30+
31+
draw_koch_snowflake(t, (-150, 90), 300, 4, '#0000FF')
32+
draw_koch_snowflake(t, (-100, 65), 200, 4, '#007FFF')
33+
draw_koch_snowflake(t, (-50, 35), 100, 4, '#00BFFF')
34+
draw_koch_snowflake(t, (-25, 15), 50, 4, '#00FFFF')
35+
draw_koch_snowflake(t, (-14, 8), 25, 4, '#B0E0E6')
36+
37+
turtle.done()

Turtle-a-thon/Snowflakes/snowflakes.gif

Loading

0 commit comments

Comments
 (0)