The following code is straightforward (I have left blank lines to distinguish 5 sections):
\begin{tikzpicture}
\coordinate (B) at (0,0);
\coordinate (A) at (12,0);
\coordinate (C) at (3,5);
\coordinate (f0) at ($(B)!(C)!(A)$);
\coordinate (f1) at ($(C)!(f0)!(A)$);
\coordinate (f2) at ($(B)!(f1)!(A)$);
\coordinate (f3) at ($(C)!(f2)!(A)$);
\coordinate (f4) at ($(B)!(f3)!(A)$);
\coordinate (f5) at ($(C)!(f4)!(A)$);
\coordinate (f6) at ($(B)!(f5)!(A)$);
\draw (B) -- (A) -- (C)
node [midway,above] {$\mathbf b$} --
node [midway, left] {$\mathbf a$} cycle;
\filldraw[fill=blue!5!white, draw=black]
(C) -- (f0) node [midway,left] {$h_0$} --
(f1) node [midway,above,left] {$a_0$} --
(f2) node [midway,left] {$h_1$} --
(f3) node [midway,above,left] {$a_1$} --
(f4) node [midway,left] {$h_2$} --
(f5) node [midway,above,left] {$a_2$};
\draw
(B) --
(f0) node [midway,below] {$c_0$} --
(f2) node [midway,below] {$c_1$} --
(f4) node [midway,below] {$c_2$} --
(f6) node [midway,below] {$c_3$};
\end{tikzpicture}
Defines the coordinates of a right triangle, and the base point of the construction.
Defines each new coordinate as the foot of a height to either segment CA or BA from a previously computed coordinate, starting from the base point.
Draw the triangle.
Draw the heights toward BA and label them.
Draw the heights toward CA.
My question is what is the syntax to automate this process, so that I can do the same, not just 3 steps in, but 5, 10, or variably more steps?
\newcommand
or\def
) cho that task