I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?
A simple way is to save the grid to a box:
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\newbox{\mygrid}
\savebox{\mygrid}{%
\begin{tikzpicture}[x=0.6cm,y=0.8cm]
\foreach \x in {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}
\foreach \y in {0,1,2,3}
{
\pgfmathrandomitem{\RandomColor}{MyRandomColors}
\draw[\RandomColor, fill=\RandomColor] (\x,\y) circle (0.2cm);
}
\end{tikzpicture}
}
%when you want to use the grid, you just call \usebox
\usebox{\mygrid}
\end{document}
You may also place the box within a node for placement control.
Specifying a seed \pgfmathsetseed{1}
within your tikzpicture should fix the problem.
\documentclass[10pt,a4paper]{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfmathdeclarerandomlist{MyRandomColors}{%
{red}%
{blue}%
{green}%
}
\begin{document}
\begin{frame}
\begin{tikzpicture}[x=0.6cm,y=0.8cm]
\pgfmathsetseed{1}%
\foreach \x in {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}
\foreach \y in {0,1,2,3}
{
\pause
\pgfmathrandomitem{\RandomColor}{MyRandomColors}
\draw[\RandomColor, fill=\RandomColor] (\x,\y) circle (0.2cm);
}
\end{tikzpicture}
\end{frame}
\end{document}
Alternatively to saving the grid in a box, you could compute the random color order only once and use it when creating the grid:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{etoolbox}
\pgfmathdeclarerandomlist{MyRandomColors}{%
{red}%
{blue}%
{green}%
}
\makeatletter
\def\colorrows{\@gobble}
\foreach \row in {0,...,3} {
\def\colors{\@gobble}
\foreach \col in {0,...,18} {
\pgfmathrandomitem{\randomcolor}{MyRandomColors}
\xappto\colors{,\randomcolor}
}
\xappto\colorrows{,{\colors}}
}
\edef\colorrows{\colorrows}
\makeatother
\begin{document}
\begin{tikzpicture} [x=0.6cm, y=0.8cm]
\foreach \row [count=\y] in \colorrows {
\foreach \col [count=\x] in \row {
\draw [\col, fill=\col] (\x,\y) circle (0.2cm);
}
}
\end{tikzpicture}
\end{document}
The \@gobble
s get rid of the first comma added by each loop.