There is already a predefined shading for spherical objects, which is invoked via the "ball" option, but I haven't found a way to switch its color from the default blue to red when using it outside of the "tikzpicture" environment:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations,decorations.pathreplacing}
\begin{document}
\pgfdeclaredecoration{balls}{initial}
{
\state{initial}[width=\pgfdecoratedpathlength/floor(\pgfdecoratedpathlength/5pt)]
{
\pgfpathmoveto{\pgfpoint{1pt}{0pt}}
\pgfusepath{}
\pgfpathcircle{\pgfpoint{0pt}{2pt}}{2.5pt}
\pgfshadepath{ball}{0}{color=red}
\pgfusepath{}
}
\state{final}
{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
}
}
\begin{tikzpicture}
\draw[decorate, decoration={balls}, color=red](0, 0) -- (2, 0);
\end{tikzpicture}
\end{document}
What is the correct way to achieve this?
ball color=red? – Jake Sep 27 '12 at 15:33\draw[decorate, decoration={balls}, ball color=red](0, 0) -- (2, 0);, which worked, but you want to define the color within your\pgfdeclaredecoration, correct? – Jake Sep 27 '12 at 16:23