-
Notifications
You must be signed in to change notification settings - Fork 0
/
sierpinski_carpet.py
56 lines (48 loc) · 1.15 KB
/
sierpinski_carpet.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import turtle
window = turtle.Screen()
window.bgcolor("white")
alpha = turtle.Turtle()
alpha.shape(None)
alpha.color("blue")
alpha.speed(0)
alpha.penup()
alpha.goto(-200,200)
alpha.pendown()
def draw_square(turtle, size):
turtle.fill(True)
for i in range(1,5):
turtle.forward(size)
turtle.right(90)
turtle.fill(False)
def draw_fractal(turtle, size):
"""Draws a larger square with the middle square missing."""
for i in range(1,5):
for i in range(1,3):
draw_square(turtle, size)
turtle.forward(size)
turtle.forward(size)
turtle.right(90)
def draw_fractal2(turtle, size):
for i in range(1,5):
for i in range(1,3):
draw_fractal(turtle, size)
turtle.forward(size * 3)
turtle.forward(size * 3)
turtle.right(90)
def draw_fractal3(turtle, size):
for i in range(1,5):
for i in range(1,3):
draw_fractal2(turtle, size)
turtle.forward(size * 9)
turtle.forward(size * 9)
turtle.right(90)
def draw_fractal4(turtle, size):
for i in range(1,5):
for i in range(1,3):
draw_fractal3(turtle, size)
turtle.forward(size * 27)
turtle.forward(size * 27)
turtle.right(90)
draw_fractal4(alpha, 2)
alpha.hideturtle()
window.exitonclick()