How to draw a chessboard with (\multido )?
Asked
Active
Viewed 500 times
1 Answers
2
The varying color is IMHO way easier to implement with \foreach than with \multido.
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \X in {0,...,7}
{\foreach \Y in {0,...,7}
{\unless\ifodd\numexpr\X+\Y
\pgfmathtruncatemacro{\Z}{20+8*\Y}
\fill \unless\ifodd\Y [black!\Z!white] \fi (\X,\Y) rectangle ++(1,1);
\fi}}
\draw (0,0) grid (8,8);
\end{tikzpicture}
\end{document}
Here the color varies only if \Y is even and only along the \Y direction. This is controlled by the color fraction
\pgfmathtruncatemacro{\Z}{20+8*\Y}
and the \unless\ifodd\Y statement. Of course, you can implement any variation by changing this.


foreach?\documentclass[tikz,border=3mm]{standalone} \begin{document} \begin{tikzpicture} \draw (0,0) grid (8,8); \fill foreach \X in {0,...,7} {foreach \Y in {0,...,7} {\unless\ifodd\numexpr\X+\Y (\X,\Y) rectangle ++(1,1) \fi}}; \end{tikzpicture} \end{document}– Jan 28 '20 at 22:08