I am trying to produce a 6-by-6 checkboard of small circles, alternating colour between red and black.
To do this I have attempted to use \pgfmathparse and \ifnum in order to decide if to colour a circle red or back:
\documentclass[11pt]{article}
\pagestyle{empty}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {0,...,5} \foreach \y in {0,...,5}
{
\pgfmathparse{mod(\x+\y,2)}
\ifnum\pgfmathresult=0{\path[fill=black] (\x*0.5cm,\y*0.5cm) circle (0.1cm);}
\else{\path[fill=red] (\x*0.5cm,\y*0.5cm) circle (0.1cm);}\fi
}
\end{tikzpicture}
\end{document}
Although the code errors when I attempted to run it through pdflatex with ! Missing = inserted for \ifnum. and ! Missing number, treated as zero. it does produce the expected result.
What precisely am I doing wrong with regards to the calculation and how should one go about producing such a picture?

\pgfmathsetmacro{\r}{int(...)}doesn't return an integer (you get the.0on the end), which you need the\let\r\pgfmathresultfor. Also, you never know when a TikZ command will overwrite\pgfmathresult, so saving it is a good idea if you need to refer to it later. However, in a case like this, I don't think there's any need for the\let\r\pgfmathresult. It doesn't hurt, though. – Antal Spector-Zabusky Dec 08 '10 at 02:53\edefis necessary. If you putcolor=\pgfmathresultthen TeX complains (try it). So Antal is correct (on both counts). – Andrew Stacey Dec 08 '10 at 10:44