prologues := 3;
Linethickness = 1pt;
beginfig(1);
recursion_depth := 6;
const := 2.2;
numeric length;
length := 1.3in / (const**recursion_depth);
pickup pencircle scaled Linethickness;
picture p, q, r;
for i = 1 upto recursion_depth - 2:
draw (0,0) -- (length,0);
draw (0,-length) -- (0,length);
length := length * const;
currentpicture := currentpicture shifted (length,0);
p := currentpicture rotated 90;
q := p yscaled -1;
addto currentpicture also p;
addto currentpicture also q;
endfor;
draw (0,0) -- (length,0);
draw (0,-length) -- (0,length);
length := length * const;
currentpicture := currentpicture shifted (length,0);
p := currentpicture rotated 90;
q := p yscaled -1;
r := currentpicture xscaled -1;
addto currentpicture also p;
addto currentpicture also q;
addto currentpicture also r;
draw (-length,0) -- (length,0);
draw (0,-length) -- (0,length);
dotlabel.urt(btex$e$etex, (0,0));
dotlabel.ulft(btex$a$etex, (length,0));
dotlabel.lrt(btex$b$etex, (0,length));
pair P, Q, R;
P := (-0.5length, 0.5length);
Q := (-length, 0.9length);
draw P .. Q .. (-2length,0) .. Q yscaled -1 .. P yscaled -1
.. cycle withcolor red;
label.top(btex$S(a^{-1})$etex, (-1.2length, 0.9length)) withcolor red;
Q := (length, length);
R := (0, 2length);
draw P xscaled -1 --- Q .. R .. (-2.2length, 0) .. R yscaled -1
.. Q yscaled -1 --- P scaled -1 .. cycle withcolor blue;
label.rt(btex$aS(a^{-1})$etex, (1.1length,1.1length)) withcolor blue;
currentpicture := currentpicture shifted (10cm,10cm);
endfig;
end;