Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draw a Sierpinski gasket
- import turtle
- def triangle(dist, order):
- if order > 0:
- triangle(dist/2, order-1)
- turtle.forward(dist/2)
- triangle(dist/2, order-1)
- turtle.left(120)
- turtle.forward(dist/2)
- turtle.right(120)
- triangle(dist/2, order-1)
- turtle.right(120)
- turtle.forward(dist/2)
- turtle.left(120)
- else:
- turtle.begin_fill()
- turtle.forward(dist)
- turtle.left(120)
- turtle.forward(dist)
- turtle.left(120)
- turtle.forward(dist)
- turtle.left(120)
- turtle.end_fill()
- # Test
- turtle.setup(500,500)
- turtle.reset()
- turtle.speed(0)
- turtle.hideturtle()
- turtle.penup()
- turtle.goto(-200,-150)
- turtle.pendown()
- triangle(400,3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement