Koch snowflake
Koch curve is a geometric curve like snowflakes, snowflake curve it is also known, it is a special case of de Rham curve. Koch snowflake is seen in Helge von Koch's papers, it is a fractal curve.
Painting:
1, a draw any equilateral triangle, each side and the trisection;
2, while the intermediate section of the edge is taken as an equilateral triangle trisection outwardly, and this "middle section" erased;
3, repeating the above two steps, shown smaller triangles.
4, is repeated until infinity, drawn curve called the Koch snowflake.
- from Baidu-Baike
Python programming Koch snowflake
Of course, it is represented by Turtle ~
import turtle
def koch(len, n):
if n == 0:
turtle.fd(len)
else:
for i in [0, 60, -120, 60]:
turtle.left(i)
koch(len/3, n-1)
level = int(input())
def main():
turtle.penup()
turtle.goto(-250, 150)
turtle.pensize(2)
turtle.color('orange')
turtle.pendown()
koch(500, level)
turtle.right(120)
koch(500, level)
turtle.right(120)
koch(500, level)
turtle.right(120)
turtle.hideturtle()
turtle.done()
main()