[Tex/LaTex] Beamer: Blackboard theme and overlays

beamertikz-pgf

I am currently preparing my beamer presentation for my PhD defense.

I took the example at the url blackboardTheme to get a black board style presentation.

This template includes a short script which uses a random-generator to randomly scatter dust-trails on the black background to mimic chalk traces (see MWE below).

The thing is that parallel to that, I am also using overlays to uncover my slide layout by layout.
The script is executed each time I am using a layout command which slows down the compilation quite substantially.
I am not so familiar with control statements in latex,
so here is my question:

How can-I modify this script for the background to be refreshed only when the slide is over, and not after each layout command?

Remarks:

1) I am using the Augie font, but I didn't included it in the MWE so that it can be compiled more easily

2) In case, it should make a difference I am also using the \begin{textblock*} \end{textblock*} environment from the textpos package to position text on the slide.

Here is my MWE:

\documentclass[10pt,mathserif]{beamer}

\usepackage[francais,english]{babel}
\usepackage[utf8] {inputenc} %for ISOlatin1 (8859-1) sources
\usepackage[T1] {fontenc}      %for polices DC 8bits 

%%%Fancy fonts
%\usepackage{emerald}
%\usepackage{eulervm}
%%%

%%Extra packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\usepackage[absolute,overlay]{textpos}


 %set text colors for different objects
\setbeamercolor{frametitle}{fg=white}
\setbeamercolor{structure}{fg=white}
\setbeamercolor{normal text}{fg=white}
\setbeamercolor{alerted text}{fg=white}
\setbeamercolor{example text}{fg=white}


%%Black background
\setbeamercolor{background canvas}{bg=black}



%%%%%%%%%%%%%%%%%%%%%%
%%%%%Script: Random Dust Trails%%%%%%%%%%%%%%%
\pgfmathsetseed{\number\pdfrandomseed} % seed for random generator
\setbeamertemplate{background}{
    \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight); 
      \foreach \i in {1,...,30} {
            \pgfmathsetmacro{\x}{random(0,10000)/5000-1}%
            \pgfmathsetmacro{\y}{random(0,10000)/10000-0.1}%
            \pgfmathsetmacro{\r}{random(0,10000)/1000-5}%
            \rotatebox{\r}{
                \pgftext[at=\pgfpoint{\x\paperwidth}{\y\paperheight}, left, base]{\includegraphics[width=\textwidth]{paintstroke.png}}
            }
        }; 
    \end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%

%%No navigation bar
\setbeamertemplate{navigation symbols}{}

\begin{document}

    \begin{frame}

        \begin{itemize}
            \item<1-> bla slide 1
            \item<2-> blu slide 1
            \item<3-> blub slide 1
        \end{itemize}

    \end{frame}

%%I want the background to be refreshed with the Dust Trails script only at the end of the frame    

    \begin{frame}

        \begin{itemize}
            \item<1-> bla slide 2
            \item<2-> blu slide 2
            \item<3-> blub slide 2
        \end{itemize}

    \end{frame}

\end{document}

This is my first post, so please be kind if I did something illegal on the formatting of the message ;-).

Thanks in advance,

Yannick

Best Answer

To prevent the random generation at each overlay, here is a solution which stores the picture in a savebox and reuses it. With the command \background the dust trails can be refreshed.

\documentclass[10pt,mathserif]{beamer}

\usepackage[francais,english]{babel}
\usepackage[utf8] {inputenc} %for ISOlatin1 (8859-1) sources
\usepackage[T1] {fontenc}      %for polices DC 8bits 

%%%Fancy fonts
%\usepackage{emerald}
%\usepackage{eulervm}
%%%

%%Extra packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\usepackage[absolute,overlay]{textpos}
\usepackage{etoolbox}

%set text colors for different objects
\setbeamercolor{frametitle}{fg=white}
\setbeamercolor{structure}{fg=white}
\setbeamercolor{normal text}{fg=white}
\setbeamercolor{alerted text}{fg=white}
\setbeamercolor{example text}{fg=white}

%%Black background
\setbeamercolor{background canvas}{bg=black}

%%%%%%%%%%%%%%%%%%%%%%
%%%%%Script: Random Dust Trails%%%%%%%%%%%%%%%
\pgfmathsetseed{\number\pdfrandomseed} % seed for random generator
\setbeamertemplate{background}{
  \usebox{\mypicture}
}
%%%%%%%%%%%%%%%%%%%%%%

\BeforeBeginEnvironment{frame}{%
    \begin{lrbox}{\mypicture}
        \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight); 
        \foreach \i in {1,...,30} {
            \pgfmathsetmacro{\x}{random(0,10000)/5000-1}%
            \pgfmathsetmacro{\y}{random(0,10000)/10000-0.1}%
            \pgfmathsetmacro{\r}{random(0,10000)/1000-5}%
            \rotatebox{\r}{
                \pgftext[at=\pgfpoint{\x\paperwidth}{\y\paperheight}, left, base]{\includegraphics[width=\textwidth]{paintstroke.png}}
            }
        }; 
        \end{tikzpicture}
    \end{lrbox}
}

%%No navigation bar
\setbeamertemplate{navigation symbols}{}

\begin{document}

    \newsavebox{\mypicture}
    \begin{frame}

        \begin{itemize}
            \item<1-> bla slide 1
            \item<2-> blu slide 1
            \item<3-> blub slide 1
        \end{itemize}

    \end{frame}

    \begin{frame}

        \begin{itemize}
            \item<1-> bla slide 2
            \item<2-> blu slide 2
            \item<3-> blub slide 2
        \end{itemize}

    \end{frame}

\end{document}