def draw_background(window): earth = gr.Rectangle(gr.Point(0, window.height // 2), gr.Point(window.width - 1, window.height - 1)) earth.setFill("green") earth.draw(window) sci = gr.Rectangle(gr.Point(0, 0), gr.Point(window.width - 1, window.height // 2)) sci.setFill("cyan") sci.draw(window)
def fractal_rectangle(A, B, C, D, deep=10): """ Рисование вложенных прямоугольников методом рекурсии. A, B, C, D - координаты (x, y). deep - максимальная глубина рекурсии """ if deep < 1: #глубина функции достигла максимума return #выход из рекурсии # Цикл перебора точек квадрата (по двум переменным - пары точек), *A - разворачивание списка, кортежа for M, N in (A, B), (B, C), (C, D), (D, A): gr.Line(gr.Point(*M), gr.Point(*N)).draw(window) A1 = (A[0] * (1 - alpha) + B[0] * alpha, A[1] * (1 - alpha) + B[1] * alpha) B1 = (B[0] * (1 - alpha) + C[0] * alpha, B[1] * (1 - alpha) + C[1] * alpha) C1 = (C[0] * (1 - alpha) + D[0] * alpha, C[1] * (1 - alpha) + D[1] * alpha) D1 = (D[0] * (1 - alpha) + A[0] * alpha, D[1] * (1 - alpha) + A[1] * alpha) fractal_rectangle(A1, B1, C1, D1, deep - 1) #вызов рекурсивной фун
def draw_house_window(window, x, y, width, height): glass = gr.Rectangle(gr.Point(x - width // 2, y), gr.Point(x + width // 2, y - height)) glass.setFill("blue") line1 = gr.Line(gr.Point(x, y), gr.Point(x, y - height)) line2 = gr.Line(gr.Point(x - width // 2, y - height // 2), gr.Point(x + width // 2, y - height // 2)) glass.draw(window) line1.draw(window) line2.draw(window) line1.setOutline("black") line2.setOutline("black") line1.setWidth(2) line2.setWidth(2)
def draw_house_roof(window, x, y, width, height): roof = gr.Polygon(gr.Point(x - width // 2, y), gr.Point(x + width // 2, y), gr.Point(x, y - height)) roof.setFill("green") roof.draw(window)
def draw_house_walls(window, x, y, width, height): walls = gr.Rectangle(gr.Point(x - width // 2, y), gr.Point(x + width // 2, y - height)) walls.setFill("red") walls.draw(window) draw_house_window(window, x, y - height // 4, width // 3, height // 2)
def draw_house_foundation(window, x, y, width, height): foundation = gr.Rectangle(gr.Point(x - width // 2, y), gr.Point(x + width // 2, y - height)) foundation.setFill("brown") foundation.draw(window)