-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_2.py
37 lines (31 loc) · 1.1 KB
/
task_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import turtle
import math
def draw_pythagoras_tree(order, size, angle=45):
if order == 0:
turtle.forward(size)
turtle.backward(size)
else:
turtle.pensize(2)
turtle.pencolor("blue")
turtle.fillcolor("green")
turtle.begin_fill()
turtle.forward(size)
turtle.left(angle)
draw_pythagoras_tree(order - 1, size * math.cos(math.radians(angle)), angle)
turtle.right(2 * angle)
draw_pythagoras_tree(order - 1, size * math.cos(math.radians(angle)), angle)
turtle.left(angle)
turtle.backward(size)
if __name__ == "__main__":
# Ініціалізація turtle
turtle.speed(0)
turtle.left(90)
screen = turtle.Screen()
screen.title("Дерево Піфагора")
# Отримання рівня рекурсії від користувача
level = int(input("Введіть рівень рекурсії (ціле число): "))
size = 100
# Малювання дерева Піфагора
draw_pythagoras_tree(level, size)
# Завершення роботи turtle
turtle.done()