[Python] koch snowflake

import turtle 
def koch(size,n):
if n == 0:
turtle.fd(size) #If n=0 draw a straight line
else:
for angle in [0,60,-120,60]: #n>0 The straight line is not a straight line, it becomes -/\- this shape
turtle.left(angle)
koch(size/3,n-1) #Change from a large number to 0
def main():
turtle.setup(600,600)
turtle.penup ()
turtle.goto(-200,100)
turtle.pendown()
turtle.pensize(2)
level = 3
koch(400,level)
turtle.right(120)
koch(400, level)
turtle.right(120)
koch(400 , level)
turtle.right(120)
turtle.hideturtle()
main()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325161367&siteId=291194637