# Drawing a gear with Tikz

I need some help to modify the \gear macro of this answer in order to be able to fill the drawn gear with a solid color.

I've tried to move the \draw command outside the loop, but it does not work as expected (missing semicolon???):

\newcommand{\gear}[3]{%
\def\modu{#1}
\def\Zb{#2}
\def\AngleA{#3}

\pgfmathsetmacro{\Rpr}{\Zb*\modu/2}
\pgfmathsetmacro{\Rb}{\Rpr*cos(\AngleA)}
\pgfmathsetmacro{\Rt}{\Rpr+\modu}
\pgfmathsetmacro{\Rp}{\Rpr-1.25*\modu}
\pgfmathsetmacro{\AngleT}{pi/180*acos(\Rb/\Rt)}
\pgfmathsetmacro{\AnglePr}{pi/180*acos(\Rb/\Rpr)}
\pgfmathsetmacro{\demiAngle}{180/\Zb}
\pgfmathsetmacro{\Angledecal}{(\demiAngle-2*\AnglePr)/2}

\draw[fill=black!20] \foreach \zz in{1,2,...,\Zb}{
({(\zz))/\Zb*360-\Angledecal}:\Rb)
-- (\zz/\Zb*360-\Angledecal:\Rp)
to[bend right=\demiAngle] (\zz/\Zb*360+\Angledecal:\Rp)
-- plot[domain=-0:\AngleT,smooth,variable=\t]
({{180/pi*(-\t+tan(180/pi*\t))+\zz/\Zb*360+\Angledecal}:\Rb/cos(180/pi*\t)})
%
to[bend right=\demiAngle]
({{180/pi*(\AngleT+tan(180/pi*-\AngleT)) +(\zz+1)/\Zb*360-\Angledecal}:
\Rb/cos(180/pi*-\AngleT)})
%
plot[domain=-\AngleT:-0,smooth,variable=\t]
({{180/pi*(-\t+tan(180/pi*\t)) +(\zz+1)/\Zb*360-\Angledecal}:
\Rb/cos(180/pi*\t)})
} -- cycle;
}


As I see it, the \draw is already outside of the loop? Does replacing \draw with \fill or \filldraw not work? – Qrrbrbirlbel Jan 28 at 12:12
Ah, yes, sorry. But still, why don’t you replace the \draw with \fill(draw) or just add fill=<color> to its optional argument? Okay, scratch that, I’ve just tested it, of course it doesn’t work with sepearate \draw commands. – Qrrbrbirlbel Jan 28 at 12:20