# Table-aligned, randomized, repeatingly smaller icons for eyesight-chart

My daughter needs to train her eyesight in accordance to the LEA eyesight chart tests.

I have manually created a new chart for her, but it really takes a long time randomzing the four icons and manually aligning them:

I was thinking about automating the process using LaTeX. I have all four icons as separate PDFs (also any other vector format can be derived from that, of course). Would anyone care to help me with this, as I assume it is rather more a "programming LaTeX" then "writing in LaTeX" task ;) I'd be very happy to share the result with a good friend of mine who is a pediatrician as I assume it might help others, too (they give out copies of an old copy of a fax someone received back in the 80's... - not very clean and not much help, either).

If someone could help me I'd be extremely grateful. The distance between each line and the decrease in size can be guessed but should be alterable.

-
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. – Werner Feb 24 '12 at 16:47
Thanks for the note; it's something I do as a matter of habit since the dawn of electronic communication ;) – Christian Feb 24 '12 at 19:03
Err... clicking "Answer your Question" does - nothing?! Chrome dev, Mac OS X 10.7, Adblock. Any ideas at such an early hour? – Christian Feb 25 '12 at 7:35

One way to accomplish this is to use pgfmathdeclarerandomlist{<list name>}{{order 1}{order 2}...{order 24}} to specify all the possible combinations of the pictures, and then use \pgfmathrandomitem to randomly pick one of these and use that as the order of the pictures.

The images are placed in a table with \TableRow{<scale>}, where the <scale> specifies the scale to be applied to the images in that row.

## Notes:

• To increase the spacing between the rows you can include a size at the end of each row. For example: \\[0.3cm].

## Further Enhancements:

• The array of possible combinations should be auto generated.

## Code:

For this to work I saved the images as 1.png, 2.png, 3.png, 4.png in the directory where I had this .tex file.

\documentclass{article}
\usepackage{graphicx}
\usepackage{xstring}
\usepackage{pgf}

% All possible combination of pictures
% Listed here in increasing numerical order for convenience
\pgfmathdeclarerandomlist{MyRandomList}{%
{1234} {2134} {3124} {4123}
{1243} {2143} {3142} {4132}
{1324} {2314} {3214} {4213}
{1342} {2341} {3241} {4232}
{1423} {2413} {3412} {4312}
{1432} {2431} {3421} {4321}
}

\newcommand{\MaxWidth}{2.0}%  width in cm
\newcommand{\MaxHeight}{2.0}% height in cm

\newcommand*{\MyIncludeGraphics}[3]{% #1= scale
\pgfmathsetmacro{\Width}{#1*\MaxWidth}%
\pgfmathsetmacro{\Height}{#1*\MaxHeight}%
\StrChar{#2}{#3}[\FigureToInclude]% Extract digit from the 4 digit random number
\includegraphics[width=\Width cm, height=\Height cm]{\FigureToInclude}%
}%

\newcommand*{\TableRow}[1]{%
\pgfmathrandomitem{\RamdomMemberOfList}{MyRandomList}
\xdef\OrderOfPictures{\RamdomMemberOfList}
\MyIncludeGraphics{#1}{\OrderOfPictures}{1} &
\MyIncludeGraphics{#1}{\OrderOfPictures}{2} &
\MyIncludeGraphics{#1}{\OrderOfPictures}{3} &
\MyIncludeGraphics{#1}{\OrderOfPictures}{4}
}%

\begin{document}
\begin{tabular}{c c c c}
\TableRow{1.0}\\
\TableRow{0.8}\\
\TableRow{0.6}\\
\TableRow{0.4}\\
\TableRow{0.3}\\
\TableRow{0.2}\\
\TableRow{0.1}\\
\end{tabular}
\end{document}

-
Works like a charm - the crude table-and-hand-pasted-graphics I came up with in the meantime dig away in shame ;). I had to add a random seed though, else it came up with the "same random" set each run. THANKS! – Christian Feb 24 '12 at 21:22
@Christian: The random seed should automatically change every minute. Also, you could generate those images directly using tikz. – Peter Grill Feb 24 '12 at 21:29
see above; I will probably generate a few pages after each other, then print them so I added a "faster" random seed. – Christian Feb 24 '12 at 21:32
Are those symbols built-in into tikz? I wasn't able to find a font that had them yet so I grabbed them out of a PDF I found online... – Christian Feb 24 '12 at 21:34
I don't think they are built it (except for the square), but they can be draw fairly easily. The apple/heart may take a bit of work but not too difficult. Have a look at How to create Candle Symbol in LaTeX as that might get you started. If you get stuck you can always ask for help here. – Peter Grill Feb 24 '12 at 21:38