I am trying to recreate the following image in TikZ
Using some old code I was able to produce the following result
While I was able to produce the correct result, I feel that my solution was a bit strange as it required two passes. Any suggestions for alternative approaches, or improvements to the code are more than welcome.
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[x=1cm]
\edef\size{4}
\foreach \x in {0,...,\size} \foreach \y in {0,...,\size}
{
\pgfmathparse{mod(\x+\y,\size) ? "none" : "black"}
\edef\colour{\pgfmathresult}
\path[draw=black, fill=\colour] (\x,\y) rectangle ++ (1,1);
\pgfmathparse{\x==\y ? "black" : "none"}
\edef\colour{\pgfmathresult}
\path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--(0,\size+1)--(\size+1,\size+1)--(\size+1,0)--cycle;
\end{tikzpicture}
\end{document}
Best Answer
With
tikz
:Note: Value of
\size
had to be zero or any even natural number (0, 2, 4, ...)addendum:
(current bounding box.south)˙ For series of those images for different value of
size` is: