/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/python/lab-111-020/main.py
30 строк
840 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
import turtle from collections import deque def draw_pythagoras_tree_iterative(base_len: float, depth: int, angle: float = 45.0): t = turtle.Turtle() t.speed(0) stack = deque() # (x, y, heading, length, level) stack.append((0, 0, 90, base_len, 0)) while stack: x, y, heading, length, level = stack.pop() if level > depth: continue t.penup() t.goto(x, y) t.setheading(heading) t.pendown() t.forward(length) new_x, new_y = t.position() # Левая ветвь stack.append((new_x, new_y, heading - angle, length * 0.7, level + 1)) # Правая ветвь stack.append((new_x, new_y, heading + angle, length * 0.7, level + 1)) t.hideturtle() draw_pythagoras_tree_iterative(100, 5) turtle.done()