Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- screen = turtle
- screen.title('T-square Fractal - PythonTurtle.Academy')
- screen.setup(1000, 1000)
- screen.setworldcoordinates(-1000, -1000, 1000, 1000)
- screen.tracer(0, 0)
- turtle.speed(0)
- screen.bgcolor('white')
- turtle.hideturtle()
- turtle.pencolor('white')
- def stacksquares(x, y, length, n):
- if n == 0: return
- stacksquares(x - length / 2, y - length / 2, length / 2, n - 1)
- stacksquares(x + length / 2, y + length / 2, length / 2, n - 1)
- stacksquares(x - length / 2, y + length / 2, length / 2, n - 1)
- stacksquares(x + length / 2, y - length / 2, length / 2, n - 1)
- turtle.up()
- turtle.goto(x - length / 2, y - length / 2)
- turtle.down()
- turtle.seth(0)
- turtle.begin_fill()
- for _ in range(4):
- turtle.fd(length)
- turtle.left(90)
- turtle.end_fill()
- turtle.up()
- turtle.goto(-800, -800)
- turtle.begin_fill()
- turtle.fillcolor('black')
- for _ in range(4):
- turtle.fd(1600)
- turtle.left(90)
- turtle.end_fill()
- turtle.fillcolor('white')
- stacksquares(0, 0, 800, 7)
- screen.update()
- screen.exitonclick()
- # import turtle
- #
- #
- # def fractal(level, tob, turn_direction=2):
- # global length
- # if level == 1:
- # tob.forward(length)
- # tob.left(90)
- # tob.forward(length)
- # tob.left(90)
- # tob.forward(length)
- # tob.left(90)
- # tob.forward(length)
- # return
- # else:
- # tob.forward(length)
- # length /= 2
- # fractal(level - 1, tob)
- # length *= 2
- # if turn_direction == 0:
- # tob.forward(length)
- # return
- # fractal(level, tob, turn_direction=turn_direction - 1)
- #
- #
- # length = 100
- # wn = turtle.Screen()
- # wn.bgcolor("light green")
- # wn.title("Turtle")
- # tur_ob = turtle.Turtle()
- #
- # fractal(4, tur_ob)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement