# small colorful rectangles filling one page

Would it be difficult in LaTeX to generate one full A4 page of small rectangles of size say 2x3mm in colors in the form

\smallbox{step red}{step green}{step blue}{size x}{size y}


where step is some small number like 0.05 (or appropriate size) ranging from 0 to 1 and e.g. "step red" means that that amount of the red color be present? So

\smallbox{1}{0}{0}{2mm}{3mm}


should be 2x3mm red rectangle ?

EDIT I've now got an almost working example : just plug-in colors and distirbute \n over 3 values as in \definecolor{mycolor}{RGB}{219, 48, 122}

\documentclass{article}
\usepackage{amssymb,amsmath}
\usepackage{pgffor}
\usepackage{xcolor}
\definecolor{cmd}{gray}{0.6}
\newcounter{mm}
\setcounter{mm}{0}
\begin{document}
\foreach \n in {1,...,80} {\addtocounter{mm}{1} \themm}

\end{document}

• Not especially difficult, no. – cfr Oct 25 '19 at 13:17
• @cfr what I can do is one rectangle using \hrule with a definite color, like blue. – user2925716 Oct 25 '19 at 13:21
• Then show us what you have done so far. – AlexG Oct 25 '19 at 13:39
• You can look at xcolor for information about colour series. – cfr Oct 25 '19 at 14:36
• @user2925716: So how should the colours change as you're moving left-to-right / top-to-bottom on the page? Should one cycle through the red colours, nested within the blue colours, nested within the green colours? Or just step through them all of once, linearly, from 0,0,0 through to 255,255,255? – Werner Oct 25 '19 at 19:03

Do you want something like this?

\documentclass[a4paper]{article}
\usepackage{geometry,xcolor,pgffor}
\geometry{scale=1}
\definecolorseries{mycolours}{rgb}{last}[rgb]{1,1,1}[rgb]{1,0,0}
\resetcolorseries[98]{mycolours}
\begin{document}
\thispagestyle{empty}
\noindent\foreach \n in {1,...,98} {\color{mycolours!!+}\rule{30mm}{20mm}\hskip1pt}
\end{document}


\geometry{scale=1}


This is just setting the page margins etc. to zero for demonstration purposes i.e. so I can use the whole paper for the coloured rules.

\definecolorseries{mycolours}{rgb}{last}[rgb]{1,1,1}[rgb]{1,0,0}


This defines a colour series mycolours using the colour model rgb, method last, 'base' (starting colour) [rgb]{1,1,1} and 'step' (final colour in this case) [rgb]{1,0,0]. Note this isn't the actual 'step', but the basis for calculating it according to method last.

\resetcolorseries[98]{mycolours}


This calculates the 'step' between colours in the series, given that the series is to have 98 colours.

  \noindent\foreach \n in {1,...,98} {\color{mycolours!!+}\rule{30mm}{20mm}\hskip1pt}


\color{mycolours!!+} selects the current colour from series mycolours and then increments the index so that on the next call, the next colour in the series will be used.

For further explanation, texdoc xcolor can provide all the gory details of colour series, including the algorithms used to calculate the 'step' for each 'method' and the interpretation of the arguments passed to \definecolorseries in each case. It also has lots of examples of colour series and information about calling the colours etc.

Or

\documentclass[a4paper]{article}
\usepackage{geometry,xcolor,pgffor}
\geometry{scale=1}
\definecolorseries{myreds}{rgb}{last}[rgb]{1,1,1}[rgb]{1,0,0}
\resetcolorseries[32]{myreds}
\definecolorseries{myblues}{rgb}{last}[rgb]{1,1,1}[rgb]{0,0,1}
\resetcolorseries[32]{myblues}
\definecolorseries{mygreens}{rgb}{last}[rgb]{1,1,1}[rgb]{0,1,0}
\resetcolorseries[32]{mygreens}
\pagestyle{empty}
\begin{document}
\noindent\foreach \n in {1,...,32} {\foreach \i in {myreds,myblues,mygreens}{\color{\i!!+}\rule{30mm}{20mm}\hskip1pt}}
\end{document}


\definecolorseries and \resetcolorseries are doing the same in this example as in the earlier one, but I'm putting 32 colours into each of 3 series, rather than 98 into just 1. Note that the key word last in all 4 uses of \definecolorseries tells you the 'method' used to calculate the 'step' is the same in each case.

• That's completely OK. I just need to understand what does this \noindent\foreach \n in {1,...,98} {\color{mycolours!!+}\rule{30mm}{20mm}\hskip1pt} esepecially \color{mycolours!!+} ? – user2925716 Oct 25 '19 at 19:28
• I can see now. I don't think I would ever come out with this solution on my own. And what about these commands : \geometry{scale=1} \definecolorseries{myreds}{rgb}{last}[rgb]{1,1,1}[rgb]{1,0,0} \resetcolorseries[32]{myreds} ? – user2925716 Oct 25 '19 at 19:37
• @user2925716 I've added some explanation into the answer. – cfr Oct 25 '19 at 19:51