科赫曲线绘制源代码
#KochDrawV1.py
importturtle
defkoch(size, n):
ifn ==0:
turtle.fd(size)
else:
forangle in[0, 60, -120, 60]:
turtle.left(angle)
koch(size/3, n-1)
defmain():
turtle.setup(800,400)
turtle.penup()
turtle.goto(-300, -50)
turtle.pendown()
turtle.pensize(2)
koch(600,3) # 0阶科赫曲线长度,阶数
turtle.hideturtle()
main()
科赫雪花绘制源代码
#KochDrawV2.py
importturtle
defkoch(size, n):
ifn ==0:
turtle.fd(size)
else:
forangle in[0, 60, -120, 60]:
turtle.left(angle)
koch(size/3, n-1)
defmain():
turtle.setup(600,600)
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.pensize(2)
level =3# 3阶科赫雪花,阶数
koch(400,level)
turtle.right(120)
koch(400,level)
turtle.right(120)
koch(400,level)
turtle.hideturtle()
main()
网友评论