% Exercise 10.4
\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

% a single triangular tile
\def\caleidotile{%
  \begin{scope}
    % clipping contents to the base tile
    \clip (90:1) -- (210:1) -- (330:1) -- cycle;
    % items
    % todo: feel free to add more items/colours/...!
    \fill[green,opacity=0.5]  (\greenx,\greeny) circle (0.4cm);
    \fill[blue,opacity=0.5]   (\bluex,\bluey) circle (0.6cm);
    \fill[yellow,opacity=0.5] (\yellowx,\yellowy) circle (0.5cm);
    \fill[purple,opacity=0.5] (\purplex,\purpley) circle (0.3cm);
  \end{scope}
  % boundary of the base tile
  \draw[black!10] (90:1) -- (210:1) -- (330:1) -- cycle;
}
% a hexagon of six triangular tiles, reflected appropriately
\def\caleidohexagon{%
  % todo: complete this list of angles for the \foreach loop!
  \foreach \j in {0,120} {%
    \begin{scope}[rotate={\j}]
      \begin{scope}[shift={(30:1)}]
        \caleidotile
      \end{scope}
    \end{scope}
  }
  % todo: complete the definition of the hexagon
  % (watch out for correct reflections; y=-1cm will flip the y-direction of a scope)
}


\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
  % setting a seed for reproducible randomness
  % (convenient for testing! just remove the %)
  % \pgfmathsetseed{42} 
  % random coordinates for the pieces
  \pgfmathsetmacro{\greenx}{rnd}
  \pgfmathsetmacro{\greeny}{rnd}
  \pgfmathsetmacro{\bluex}{rnd}
  \pgfmathsetmacro{\bluey}{rnd}
  \pgfmathsetmacro{\yellowx}{rnd}
  \pgfmathsetmacro{\yellowy}{rnd}
  \pgfmathsetmacro{\purplex}{rnd}
  \pgfmathsetmacro{\purpley}{rnd}
  
  % clip visible range
  \clip (-4,-4) rectangle +(8,8);
  % suitable translations of the base hexagon give the desired filling
  \foreach \x in {-2,...,2} {%
    \foreach \y in {-3,...,3} {%
      % todo: complete this definition by inserting suitable shift coordinates
      \begin{scope}[shift={($(0,0)$)}] 
        \caleidohexagon
      \end{scope}
    }
  }
\end{tikzpicture}
\end{document}
