\documentclass{standalone}

\usepackage{luamplib}

\begin{document}

\begin{mplibcode}
warningcheck:=0;
input geom2d;
angleArbre = Pi/5;

vardef ArbrePythagore(expr A,B,n)=
    save C,D,E;
    numeric C,D,E;
    D = SimilitudeACentre(A,B,-Pi/2,1);
    C = SimilitudeACentre(B,A,Pi/2,1);
    colorieAvecTransparence(Polygone(A,B,C,D),DarkBlue,0.4);
    if(n>0):
        E = SimilitudeACentre(C,D,angleArbre,cos(angleArbre));
        ArbrePythagore(D,E,n-1);
        ArbrePythagore(E,C,n-1);
    fi
enddef;
gddU:=0.5cm;

beginfig(1);
A = Point(0,0);
B = Point(1,0);

ArbrePythagore(A,B,10);



endfig;
\end{mplibcode}

\end{document}