I have a recursive macro that relies on a counter within a tikz
\foreach
loop. What I have not achieved is how to get a tikz style (what I've called fillMod) to be dependent on the counter value (i.e. depending on whether \n is odd or even). Below is a MWE of what I so far have.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\newcommand{\pic}[1]{%
\begin{tikzpicture}[scale=3,
fillEven/.style={fill=red},
fillOdd/.style= {fill=blue},
fillMod/.style= {}]
\coordinate (A0) at (0,0);
\foreach \n in {1,2,...,#1}
{
\draw[fillMod,scale={pow(0.8,\n)}] (A0)--++(1,0)node(D0){}--++(0,-1)--++(-1,0)--++(0,1);
\coordinate (A0) at (D0);
\coordinate[below=30mm of A0] (D0);
}
\end{tikzpicture}
}
\pic{2}
\pic{3}
\pic{4}
\pic{5}
\end{document}
I know that I can define within the loop two \draw
paths, one for red and one for blue, but that means I can only produce pictures with an even number of squares. Is there a way to do this?