1 import turtle as t
2 def kehe(size,n):
3 if n==0:
4 t.fd(size)
5 else:
6 for i in [0,60,-120,60]:
7 t.left(i)
8 kehe(size/3,n-1) #递归函数
9 def main():
10 t.setup(600,600,0,0)
11 t.penup()
12 t.goto(-100,100)
13 t.pensize(3)
14 t.pencolor("tomato")
15 t.pendown()
16 t.speed(20) #调整速度,画的快一点
17
18 level=3 #3阶科赫雪花
19 t.fillcolor("blue")
20 t.begin_fill() #填充颜色
21
22 kehe(200,level)
23 t.right(120)
24 kehe(200,level)
25 t.right(120)
26 kehe(200,level)
27 t.right(120)
28
29 t.end_fill() #结束填充
30 t.hideturtle() #隐藏画笔
31 t.done()
32 main()