I am drawing a surface composed of rigid "molecules" composed of three spheres each. I want to add some randomness to the surface. I have created this code:
\begin{tikzpicture}
\def\nuPi{3.1459265}
\foreach \i in {11,10,...,0}{
\foreach \j in {5,4,...,0}{
\def\dx{rand*0.1}
\def\dy{rand*0.1}
\shade[ball color=red] (\i+\dx,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)}) circle(0.45);
\shade[ball color=gray] (\i+\dx,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-0.9}) circle(0.45);
\shade[ball color=gray] (\i+\dx,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-1.8}) circle(0.45);
}
}
\end{tikzpicture}
judging by the resulting surface, the \dx
and \dy
are generated each time they are accessed and not once in each loop. Is there a way to store them?