import turtle
def koch(size, n):
if n == 0:
turtle.fd(size)
else:
for angle in [0, 60, -120, 60]:
turtle.left(angle)
koch(size/3, n-1)
def main():
turtle.setup(800,800)
turtle.penup()
turtle.goto(-300, -50)
turtle.pendown()
turtle.pensize(2)
turtle.color('blue')
level = 3
koch(600, level)
turtle.right(120)
koch(600, level)
turtle.right(120)
koch(600, level)
turtle.hideturtle()
turtle.done()
main()
Python (利用递归)科赫雪花的绘制
最新推荐文章于 2024-09-08 20:29:54 发布