Advertisement
Danila_lipatov

kop-5

Apr 15th, 2024
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. import turtle
  2.  
  3. screen = turtle
  4. screen.title('T-square Fractal - PythonTurtle.Academy')
  5. screen.setup(1000, 1000)
  6. screen.setworldcoordinates(-1000, -1000, 1000, 1000)
  7. screen.tracer(0, 0)
  8. turtle.speed(0)
  9. screen.bgcolor('white')
  10. turtle.hideturtle()
  11. turtle.pencolor('white')
  12.  
  13.  
  14. def stacksquares(x, y, length, n):
  15.     if n == 0: return
  16.     stacksquares(x - length / 2, y - length / 2, length / 2, n - 1)
  17.     stacksquares(x + length / 2, y + length / 2, length / 2, n - 1)
  18.     stacksquares(x - length / 2, y + length / 2, length / 2, n - 1)
  19.     stacksquares(x + length / 2, y - length / 2, length / 2, n - 1)
  20.  
  21.     turtle.up()
  22.     turtle.goto(x - length / 2, y - length / 2)
  23.     turtle.down()
  24.     turtle.seth(0)
  25.     turtle.begin_fill()
  26.     for _ in range(4):
  27.         turtle.fd(length)
  28.         turtle.left(90)
  29.     turtle.end_fill()
  30.  
  31.  
  32. turtle.up()
  33. turtle.goto(-800, -800)
  34. turtle.begin_fill()
  35. turtle.fillcolor('black')
  36. for _ in range(4):
  37.     turtle.fd(1600)
  38.     turtle.left(90)
  39. turtle.end_fill()
  40. turtle.fillcolor('white')
  41. stacksquares(0, 0, 800, 7)
  42. screen.update()
  43. screen.exitonclick()
  44. # import turtle
  45. #
  46. #
  47. # def fractal(level, tob, turn_direction=2):
  48. #     global length
  49. #     if level == 1:
  50. #         tob.forward(length)
  51. #         tob.left(90)
  52. #         tob.forward(length)
  53. #         tob.left(90)
  54. #         tob.forward(length)
  55. #         tob.left(90)
  56. #         tob.forward(length)
  57. #         return
  58. #     else:
  59. #         tob.forward(length)
  60. #         length /= 2
  61. #         fractal(level - 1, tob)
  62. #         length *= 2
  63. #         if turn_direction == 0:
  64. #             tob.forward(length)
  65. #             return
  66. #         fractal(level, tob, turn_direction=turn_direction - 1)
  67. #
  68. #
  69. # length = 100
  70. # wn = turtle.Screen()
  71. # wn.bgcolor("light green")
  72. # wn.title("Turtle")
  73. # tur_ob = turtle.Turtle()
  74. #
  75. # fractal(4, tur_ob)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement