0

enter image description here

How to draw a chessboard with (\multido )?

  • 1
    Welcome! Why not 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
  • i think with(\multido ) because the varying color depths of the individual fields – Nizar Jan 28 '20 at 22:17
  • Nothing to do with multido, but see also https://tex.stackexchange.com/questions/168281/how-to-draw-a-chessboard-with-numbers/168304?r=SearchResults&s=1|48.0755#168304 and https://tex.stackexchange.com/questions/140324/chess-opening-document/140351?r=SearchResults&s=2|9.2634#140351 – John Kormylo Jan 29 '20 at 04:05
  • 1
    Anyone considering writing an answer: as far as I can see this might be a homework problem, and if you happen not to meet the requirements of a third party, in this case the instructor of the course, your answer may get unaccepted after having been accepted for a couple of days. The main problem is of course this stupid "accepting" (and "unaccepting") of an answer, but there is the additional problem that the requirements are not clear (as explained above), which is why I vote to close the question as "unclear what you are asking". –  Feb 01 '20 at 22:37

1 Answers1

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}

enter image description here

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.