I'm trying to reproduce this illustration of a high entropy alloy (HEA) in TikZ:
What I have so far looks quite bland because I can't find a way to randomly assign one out of a list of colors.
\documentclass[tikz]{standalone}
\def\colors{{red,green,blue,yellow}}
\begin{document}
\begin{tikzpicture}[]
\foreach \i in {1,...,12} {
\foreach \j in {1,...,6} {
\foreach \k in {1,...,4} {
\pgfmathparse{rnd}
\definecolor{randColor}{rgb}{\pgfmathresult,\pgfmathresult,\pgfmathresult}
\shade[ball color=randColor] (\i, {0.5*\j+\k}) circle(0.4);
}
}
}
\end{tikzpicture}
\end{document}
Two questions:
How can I assign one of
\colors{{red,green,blue,yellow}}
either randomly or seemingly randomly based on e.g.Mod(num, base)
to each of the balls? I was unable to get array indexing to work:\shade[ball color=\colors[Mod(\i+\j+\k, 4)]
and
\pgfmathparse{\i+\j+\k} \shade[ball color=\colors[Mod(\pgfmathresult, 4)]]
both throw errors.
Can the viewing angle be rotated so as to resemble the target image?