Simple Koch curve

Simple Koch curve

将一段直线等距分为三段,中间的那一段为突起的等边三角形,阶数越大的话,重复前面的操作

import turtle
def kock(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.speed(10)
    turtle.setup(800, 400)
    turtle.penup()
    turtle.goto(-300, -50)
    turtle.pendown()
    turtle.pensize(2)
    koch(500, 3)
    turtle.hideturtle()


main()

你可能感兴趣的:(Self-taught,Python)