[Tex/LaTex] Randomly assign background colour for each frame

backgroundsbeamerrandom numbers

How can a randomly picked background colour be chosen for each beamer frame?

Note:

This question is asked to round out the question Randomly assign color to background in the PDF whenever page is turned which asks for a solution which alters the colour when the pdf is displayed. On contrast the present question deals with randomly assigning colours during compilation.

Best Answer

Here is one way of doing this in ConTeXt. To set the color of a page, we need:

\definebackgrounds[page][background=color, backgroundcolor=...name...]

At each page, the setups specified in definebackgrounds are re-evaluated. So, to change the color of each page, we can simply change the value of the background color to a random color. It is easier to do so in Lua. So, here is a complete example:

\startluacode
  local random = math.random
  local format = string.format
  commands.change_color = function()
    options = { format("r=%0.3f, g=%0.3f, b=%0.3f", random(), random(), random()) }
    context.definecolor( {"randomcolor"}, options)
  end
\stopluacode

\startsetups change:color
  \ctxcommand{change_color()}
\stopsetups

\setupbackgrounds
   [page]
   [
     background=color,
     setups=change:color, 
     backgroundcolor=randomcolor,
   ]


% Just to visualize the result
\setuppapersize[A6][A2,landscape]
\setuppaper[nx=5,ny=3]
\setuparranging[XY]


\starttext

\dorecurse{15}{\null\page}

\stoptext

which gives enter image description here

Related Question