Here is a completely different approach from my other answer, and this one takes as its input, a form similar to that mentioned by the OP, namely:
\def\map{
[[2,0,0,0,0,0,0]
[0,3,0,0,0,0,0]
[0,3,2,1,1,0,0]
[0,3,2,2,2,1,1]
[0,3,2,0,0,1,0]
[0,0,0,0,0,1,0]
[0,0,0,0,0,1,0]]
}
In this case, this argument is passed to the macro \boxart
. The box size is set with \setlength{\boxsize}{}
.
EDIT: The OP has asked for a clarification on the code internals of \boxart
. In this routine, I use some macros from the stringstrings
package to strip out left brackets, turn commas into spaces, and turn right brackets into " . " strings. The result is a space-separated string (\thestring
), that will look like
2 0 0 0 0 0 0 . 0 3 0 etc.
The \getargsC
macro from readarray
knows how to efficiently read space-delimited strings and is fed this string. The number of arguments in the string is stored in \narg
and each argument is stored individually in \argi
, \argii
, \argiii
, etc. Once that is done, a loop is set up (to go through \narg
iterations, once for each item in \thestring
), and each argument is checked. If it is a 0
, a \gr
is issued for a green block, and so on for 1
, 2
, and 3
. If a .
is found, a \par
(paragraph) is issued. This while loop is performed inside a \parbox
, so that the local line spacing can be set and the result doesn't have to start in the left column of the document (I should point out that the \parbox
width was set arbitrarily by me, and may need to be manually tweaked by the user).
For the OP's edification, an \edef
is an assignment where the contents of the argument are fully expanded before being assigned. Thus, what is found in \clr
are the individual items from \thestring
successively stored in the \arg...
variables: \argi
is 2
, \argii
is 0
, ..., \argviii
is .
, etc.
\documentclass{article}
\usepackage{xcolor}
\usepackage{stringstrings}
\usepackage{readarray}
\newlength\boxsize
\setlength\boxsize{1ex}
\def\block#1{\fboxsep=0pt\fbox{\color{#1}\rule{\boxsize}{\boxsize}}\kern-\fboxrule}
\def\gr{\block{green}}
\def\rd{\block{red}}
\def\bl{\block{blue}}
\def\wh{\block{white}}
\newcounter{index}%
\newcommand\boxart[1]{%
\setcounter{index}{0}%
\convertchar[q]{#1}{,}{ }%
\convertchar[q]{\thestring}{[}{}%
\convertchar[q]{\thestring}{]}{ . }%
\getargsC{\thestring}%
\parbox[b]{8ex}{%
\baselineskip\boxsize%
\parindent 0ex%
\parskip -.2\boxsize%
\addtolength{\parskip}{-2\fboxrule}%
\whiledo{%
\theindex < \narg}{%
\stepcounter{index}%
\edef\clr{\csname arg\romannumeral\theindex\endcsname}%
\expandafter\if\clr0\gr\fi%
\expandafter\if\clr1\wh\fi%
\expandafter\if\clr2\rd\fi%
\expandafter\if\clr3\bl\fi%
\expandafter\if\clr.\par\fi%
}%
}%
}
\begin{document}
%0 = green (#54ff00)
%1 = white (#ffffff)
%2 = red (#ff0000)
%3 = blue (#0048ff)
\def\map{
[[2,0,0,0,0,0,0]
[0,3,0,0,0,0,0]
[0,3,2,1,1,0,0]
[0,3,2,2,2,1,1]
[0,3,2,0,0,1,0]
[0,0,0,0,0,1,0]
[0,0,0,0,0,1,0]]
}
Here it is: \boxart{\map}
\def\map{
[[2,0,0,0,0]
[0,3,0,0,0]
[0,3,2,0,0]
[0,3,2,1,1]
[0,3,0,1,0]]
}
\setlength{\boxsize}{1.2ex}
Another: \boxart{\map}
\end{document}
Best Answer
Here is one possibility: it's based on a list, but not on
itemize
environments. Indeed I recall Arrows coordinates in TikZ and adapted the things to:Now you have basically to insert your list inside a command
\smartart
or\smartartov
(for the automatic animation), but I don't know how much you will find the answer suitable for your needs.Here is the code:
The diagram created by means of
\smartart
is:The animation created by means of
\smartartov
:I've seen EDIT^3, and I agree that one could also display differently the diagram, for example as a standard flow chart. A couple of weeks ago I built a library to draw switching architectures (link) in which main problem was similar, how to display automatically in a vertical fashion a given number of modules. Putting things together, two new commands are available:
\smartartflow
to create the flow diagram\smartartflowov
to create the flow diagram automatically overlay aware.The code:
The flow diagram created by means of
\smartartflow
is:The animation created by means of
\smartartflowov
:The code developed in the answer has been the base of the package
smartdiagram
. Its macros are built on top of TikZ which is built on top of PGF: ok we can graphically see this with apriority descriptive diagram
.The code:
The result:
One point not yet well documented is the possibility of declaring a priori styles, for example when you want to repeat several times a diagram with the same properties. So it is sufficient to declare:
Then a possible use is: