Recursive H

https://learn.arcade.academy/en/latest/chapters/33_recursion/recursion.html#fractals



Disegna ricorsivamente una lettera H finché non raggiunge la ricorsione specificata

import arcade

WIDTH  = 800
HEIGHT = 600
TITLE  = "Recursive H"

COL_LINEA  = arcade.color.WHITE
COL_SFONDO = arcade.color.AMAZON

RECURSION = 5

def disegna_h(x, y, width, height, livello):
    arcade.draw_line(x+width*.25, height/2+y   , x+width*.75, height/2+y    , COL_LINEA, livello)
    arcade.draw_line(x+width*.25, height*.5/2+y, x+width*.25, height*1.5/2+y, COL_LINEA, livello)
    arcade.draw_line(x+width*.75, height*.5/2+y, x+width*.75, height*1.5/2+y, COL_LINEA, livello)

    livello -= 1
    if(livello >= 1):
        disegna_h(x        , y         , width/2, height/2, livello)
        disegna_h(x+width/2, y         , width/2, height/2, livello)
        disegna_h(x        , y+height/2, width/2, height/2, livello)
        disegna_h(x+width/2, y+height/2, width/2, height/2, livello)

class Applicazione(arcade.Window):
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        arcade.set_background_color(COL_SFONDO)

    def on_draw(self):
        self.clear()
        disegna_h(0, 0, WIDTH, HEIGHT, RECURSION)

def main():
    app = Applicazione(WIDTH, HEIGHT, TITLE)
    arcade.run()

if __name__ == "__main__":
    main()