我想在 TikZ 中绘制一条路径/图,其阴影取决于坐标。例如,我想说类似
\draw[color=black!\x] plot coordinates{ coord1 ... coord100};
即颜色的深浅取决于点的坐标。在我找到的 TikZ 文档中使用颜色的示例中,颜色是为整个路径设置的,不会随着点而改变。有没有办法做我想做的事?
答案1
该手册还包含以下示例(第七部分第一页):
\pgfmathsetseed{1}
\foreach \col in {black,red,green,blue}
{
\begin{tikzpicture}[x=10pt,y=10pt,ultra thick,baseline,line cap=round]
\coordinate (current point) at (0,0);
\coordinate (old velocity) at (0,0);
\coordinate (new velocity) at (rand,rand);
\foreach \i in {0,1,...,100}
{
\draw[\col!\i] (current point)
.. controls ++([scale=-1]old velocity) and
++(new velocity) .. ++(rand,rand)
coordinate (current point);
\coordinate (old velocity) at (new velocity);
\coordinate (new velocity) at (rand,rand);
}
\end{tikzpicture}
}
这也许能给你提供一个如何去做的想法。