已经有一个针对球形物体的预定义阴影,可以通过“球”选项调用,但是在“tikzpicture”环境之外使用时,我还没有找到将其颜色从默认的蓝色切换为红色的方法:
\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}
实现这一目标的正确方法是什么?