\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
%% $Id: pst-fill-doc.tex 293 2021-10-01 11:24:25Z herbert $
\documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false,
   headings=small, headinclude=false,footinclude=false,oneside]{pst-doc}

\usepackage{hvlogos,hvextern}
\usepackage{pstricks,pst-grad}
\usepackage{pst-text,pst-node}
\usepackage[tiling]{pst-fill}

\input random.tex

\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
\makeatletter
\newcommand\acro[1]{\textsc{#1}\@}
\def\CTAN{\acro{CTAN}}
\let\texttub\textsl              % % redefined in other situations
\def\TUB{\texttub{TUGboat}}
\def\TUG{\TeX\ \UG}
\def\tug{\acro{TUG}}
\def\UG{Users Group}
\newcommand\CTANdirectory[1]{\expandafter\urldef\csname CTAN@#1\endcsname\path}
\newcommand\CTANfile[1]{\expandafter\urldef\csname CTAN@#1\endcsname\path}
\newcommand\CTANref[1]{\expandafter\@setref\csname CTAN@#1\endcsname\relax{#1}}
\makeatother
\CTANdirectory{mpattern}{graphics/metapost/macros/mpattern}
\CTANdirectory{pstricks}{graphics/pstricks}
\CTANdirectory{pst-fill.sty}{graphics/pstricks/latex/pst-fill.sty}
\CTANdirectory{pst-fill}{graphics/pstricks/generic/pst-fill.tex}
\CTANdirectory{Roegel}{graphics/metapost/contrib/macros/truchet}
\CTANdirectory{xypic}{macros/generic/diagrams/xypic}
%
\definecolor{LemonChiffon}{rgb}{1.,0.98,0.8}
\definecolor{LightBlue}   {rgb}{0.8,0.85,0.95}
\definecolor{PaleGreen}   {rgb}{0.88,1,0.88}
\definecolor{PeachPuff}   {rgb}{1.0,0.85,0.73}
%
\newcommand{\FillPackage}{\texttt{`pst-fill'}}
\newcommand{\XYpic}{%
  \leavevmode\hbox{\kern-.1em X\kern-.3em\lower.4ex\hbox{Y\kern-.15em}-pic}}
\psset{dimen=middle}
%
% % Translation in PSTricks from the one drawn by Emmanuel Chailloux and
% % Guy Cousineau for the MLgraph system
% % (see /ftp.ens.fr:/pub/unix/lang/MLgraph/version-2.1/MLgraph-refman.ps.gz)
% % The kangaroo itself is reproduce from an original picture from Raoul Raba
 \newcommand{\DimX}{2.47}
 \newcommand{\DimY}{4.8}
 \newcommand{\DimXDivTwo}{1.235}
%
 \newcommand\KangarooItself[1]{%
 \pspolygon[fillstyle=solid,fillcolor=#1]%
  (52.5,68)(55,72.5)(55.8,76.5)(56.8,79.8)(58.2,83)(60,85.8)(61.5,86.5)
 (64,87)(66,87.5)(67.8,87.3)(70,87)(71.5,87.3)(73,88)(74.7,88.5)
 (76,90.3)(77,91.5)(72.8,93.8)(69,96)(64.5,99)(59.4,103)(56.2,106.3)
 (53,110.5)(49.5,115.5)(47.2,119.9)(45.7,126)(43.2,123)(41.5,121)(37.5,125)
 (37,122.5)(36.8,120)(37,117)(37.6,113.5)(38.6,110)(40,106.3)(42,102.3)
  (43.5,99.5)(45,97)(46.2,94)(46.8,91.7)(47.2,88)(47,83.5)(46.3,80.8)
  (45.3,78.5)(42.5,76.5)(39.5,75.8)(36,75.9)(33,75.9)(29,76.2)(26,77)
  (22.3,77.5)(18,78.4)(12.8,79.3)(8.6,80)(5.5,80.3)(3,80.5)(0,80)
  (-5.2,78.5)(-9,76.3)(-11.2,74.8)(-13,72.5)(-16.5,68)(-16.5,68)(-19.5,62.5)
  (-22,58)(-25.5,53)(-29,48.5)(-32.5,45)(-36,42)(-39,39.5)(-44,37)
  (-49,35)(-51,34)(-53.5,34.5)(-55.5,36)(-56.5,38)(-56.5,40.5)(-55,41.5)
  (-53.5,41)(-51.5,41)(-50.5,43)(-50.5,44.5)(-51,47)(-51.5,47.2)(-56.5,47)
  (-58.5,46.5)(-60,44.7)(-62,42.3)(-63,39.5)(-63.5,36.3)(-63.5,33)(-63.1,29.5)
  (-61.5,26)(-58,23.6)(-54,22.2)(-50.7,22)(-47.5,22)(-44.5,22.3)(-41,23.5)
  (-36.8,25.8)(-33,28)(-28.5,31)(-23.4,35)(-20.2,38.3)(-17,42.5)(-13.5,47.5)
  (-11.2,51.9)(-9.7,58)(-7.2,55)(-5.5,53)(-1.5,57)(-1,54.5)(-0.8,52)
  (-1,49)(-1.6,45.5)(-2.6,42)(-4,38.3)(-6,34.3)(-7.5,31.5)(-9,29)
  (-10.2,26)(-10.8,23.7)(-11.2,20)(-11,15.5)(-10.3,12.8)(-9.3,10.5)(-6.5,8.5)
  (-3.5,7.8)(0,7.9)(3,7.9)(7,8.2)(10,9)(13.7,9.5)(18,10.4)
  (23.2,11.3)(27.4,12)(30.5,12.3)(33,12.5)(36,12)(41.2,10.5)(45,8.3)
  (47.2,6.8)(49,4.5)(52.5,0)(50,4.5)(49.2,8.5)(48.2,11.8)(46.8,15)
  (45,17.8)(43.5,18.5)(41,19)(39,19.5)(37.2,19.3)(35,19)(33.5,19.3)
  (32,20)(30.3,20.5)(29,22.3)(28,23.5)(28,23.5)(24.5,22.3)(21.5,22)
  (18.3,22)(15,22.2)(11,23.6)(7.5,26)(5.9,29.5)(5.5,33)(5.5,36.3)
  (6,39.5)(7,42.3)(9,44.7)(10.5,46.5)(12.5,47)(17.5,47.2)(18,47)
  (18.5,44.5)(18.5,43)(17.5,41)(15.5,41)(14,41.5)(12.5,40.5)(12.5,38)
  (13.5,36)(15.5,34.5)(18,34)(20,35)(25,37)(30,39.5)(33,42)
  (36.5,45)(40,48.5)(43.5,53)(47,58)(49.5,62.5)(52.5,68)
 \pscircle*[linecolor=white](58.2,98.3){2\psxunit}
\pscircle*(58.2,97.3){\psxunit}
% Mouth
\psline(71.5,88)(70,89.3)(68.5,90.3)(67,91.9)%
% Tear
\psline(42,121)(45,118)(47,115.3)(48.5,112.7)(50,110)(51.8,106.5)
      (52.5,103.7)(53,100.5)%
\pspolygon(41.2,115.8)(43.2,114.7)(45,112.5)(47,109.8)(48,107)(49.5,104.2)%
      (50.5,101.6)(51,98.5)(47.7,100.6)(46,102.2)(44.8,104)(43.5,106)
      (42.5,108)(41.7,110.5)(41,113.2)}
%
\newcommand\Kangaroo[1]{%
  \begin{pspicture}(\DimX,\DimY)
  \psset{unit=0.035278cm}%
  \KangarooItself{#1}%
  \end{pspicture}}
%
\newcommand\KangarooPstChart[1]{{%
  \psset{xunit=0.006784,yunit=0.00735,linewidth=0.01}%
  \begin{pspicture}(-65.5,0)(82,126)%
    \KangarooItself{#1}%
  \end{pspicture}}}
%
%
% For the possible index and changes log
\setlength{\columnseprule}{0.6pt}
%
% Beginning of the documentation itself
\title{\texttt{pst-fill}\\A PSTricks package for filling and tiling areas}
%\author{Timothy Van Zandt\thanks{\protect\url{tvz@econ.insead.fr}. (documentation by
\author{Timothy Van Zandt\\Denis Girou\\ Herbert Voß}
%
%\date{\shortstack{\today --- Version 1.00\\
%                 {\small Documentation revised \today}}}

\addbibresource{\jobname.bib}

\begin{document}
\settitle
\tableofcontents
%
\begin{abstract}
 \FillPackage{} is a PSTricks \cite{vanZandt93},\cite{Girou94},\cite{vanZandtGirou94}, 
\cite{Hoenig97},\cite{LGC97} 
package to draw easily
 various kinds of filling and tiling of areas. It is also a good example of
 the great power and flexibility of PSTricks, as in fact it is a very short
 program (it body is around 200~lines long) but nevertheless really powerful.

 It was written in 1994 by Timothy \textsc{van Zandt} but
 publicly available only in PSTricks 97 and without any documentation.
 We describe here the version \emph{97 patch 2} of December 12, 1997, which
 is the original one modified by myself to manage \emph{tilings} in the
 so-called \emph{automatic} mode. This article would like to serve both of
 reference manual and of user's guide.
%
This package is available on \CTAN{} in the
 \texttt{graphics/pstricks} directory (files \texttt{latex/pst-fill.sty} and
 \texttt{generic/pst-fill.tex}).
\end{abstract}
%
\section{Introduction}

 Here we will refer as \emph{filling} as the operation which consist to fill
a defined area by a pattern (or a composition of patterns). We will refer as
\emph{tiling} as the operation which consist to do the same thing, but with
the control of the starting point, which is here the upper left corner.
The pattern is positioned relatively to this point. This make an essential
difference between the two modes, as without control of the starting point we
can't draw \emph{tilings} (sometimes  called \emph{tesselations}) as used in
many fields of Art and Science%
\footnote{For an extensive presentation of tilings, in their history and usage
in many fields, see the reference book \cite{GS87}.

In the \TeX{} world, few work was done on tilings. You can look at the
\emph{tile} extension of the \XYpic{} package \cite{XYpic}, at the articles of
Kees \textsc{van der Laan} \cite[paragraph 7]{LAAN96} (the tiling was in
fact directly done in PostScript) and \cite{LAAN97}, at the \MP{} program
(available on \path{CTAN:graphics/metapost/contrib/macros/truchet}) by Denis \textsc{Roegel} for the
\textsc{Truchet} contest in 1995 \cite{EsperetGirou98} and at the \MP{}
package \cite{Bolek98} to draw patterns, which have a strong connection with
tilings.}

Nevertheless, as tilings are a wide and difficult field in mathematics, this
package is limited to simple ones, mainly \emph{monohedral} tilings with one
prototile (which can be composite, see section \ref{sec:KindTiles}). With some
experience and wiliness we can do more and obtained easily rather
sophisticated results, but obviously hyperbolic tilings like the famous
\textsc{Escher} ones or aperiodic tilings like the \textsc{Penrose} ones are
not in the capabilities of this package. For more complex needs, we must used
low level and more painfull technics, with the basic \cs{multido}
and \cs{multirput} macros.


\newcommand\Square{\begin{pspicture}(1,1)\psframe[dimen=middle](1,1)\end{pspicture}}
\newcommand\Tiling[2][]{%
 \begin{pspicture}#2
     \psframe[fillstyle=boxfill,#1]#2
\end{pspicture}}


\section{Package history and description of it two different modes}
%
 As already said, this package was written in 1994 by Timothy \textsc{van
Zandt}. Two modes were defined, called respectively \emph{manual} and
\emph{automatic}. For both, the pattern is generated on contiguous positions in
a rather large area which include the region to fill, later cut to the
required dimensions by clipping mechanism. In the first mode, the pattern is
explicitely inserted in the PostScript file each time. In the second one, the
result is the same but with an unique explicit insertion of the pattern and a
repetition done by PostScript. Nevertheless, in this method, the control of
the starting point was loosed, so it allowed only to \emph{fill} a region and
not to \emph{tile} it.

Between the two modes, \emph{tiling} and filling is a difference: for filling the current point
is taken into account and two identical objects in a line may differ in the output.

\pstFillSetDefaults
  See the difference between the two modes, \emph{tiling}:
{\psset{unit=0.5}
 \psboxfill{\begin{pspicture}(1,1)\psframe[dimen=middle](1,1)\end{pspicture}}
 \begin{pspicture}(3,3.3)
   \psframe[fillstyle=boxfill](3,3)
 \end{pspicture}
}
and \emph{filling}:
{%
\makeatletter
\pst@def{BoxFill}<%
  gsave
    gsave \tx@STV CM grestore dtransform CM idtransform
    abs /h ED abs /w ED
    pathbbox
    h div round 2 add cvi /y2 ED
    w div round 2 add cvi /x2 ED
    h div round 2 sub cvi /y1 ED
    w div round 2 sub cvi /x1 ED
    /y2 y2 y1 sub def
    /x2 x2 x1 sub def
    CP
    y1 h mul sub neg /y1 ED
    x1 w mul sub neg /x1 ED
    clip
    y2 {
      /x x1 def
      x2 {
        save CP x y1 T moveto Box restore
        /x x w add def
      } repeat
      /y1 y1 h add def
    } repeat
  currentpoint currentfont grestore setfont moveto>
 \makeatother
%
 \psset{unit=0.5}
 \psboxfill{\begin{pspicture}(1,1)\psframe[dimen=middle](1,1)\end{pspicture}}
 \begin{pspicture}(3,3.3)
   \psframe[fillstyle=boxfill](3,3)
 \end{pspicture}
 or
 \begin{pspicture}(3,3.3)
   \psframe[fillstyle=boxfill](3,3)
 \end{pspicture}
}
as we can see that initial position is arbitrary and dependent of
the current point.


It's clear that usage of filling is very restrictive comparing to tiling,
as desired effects required very often the possibility to control the starting 
point. So, this mode was of limited interest, but unfortunately the
\emph{manual} one has the very big disadvantage to require very huge amounts
of ressources, mainly in disk space and consequently in printing time.
A small tiling can require sometimes several megabytes in \emph{manual} mode!
So, it was very often not really usable in practice.

It is why I modified the code, to allow tilings in \emph{automatic} mode,
controlling in this mode too the starting point. And most of the time, that is
to say if some special options are not used, the tiling is done exactly in the
region described, which make it faster. So there is no more reason to use the
\emph{manual} mode, apart very special cases where \emph{automatic} one cannot
work, as explained later -- currently, I know only one case.

 To load this modified \emph{automatic} mode, with \LaTeX{} use
simply:\newline 
\verb+\usepackage[tiling]{pst-fill}+\newline
and in plain \TeX{} after:\newline
\verb+\input{pst-fill}+\newline
add the following definition:\newline
\verb+\def\PstTiling{1}+

To obtain the original behaviour, just don't use the \emph{tiling} optional
keyword at loading.

Take care than in \emph{tiling} mode, I introduce also some other changes.
First I define aliases on some parameter names for consistancy (all specific
parameters will begin by the \texttt{fill} prefix in this case) and I change
some default values, which were not well adapted for tilings (\Lkeyword{fillsep}
is set to 0 and as explained \Lkeyword{fillsize} set to \Lkeyval{auto}). I rename 
\Lkeyword{fillcycle} to \Lkeyword{fillcyclex}. I also restore normal way so that
the frame of the area is drawn and all line (\Lkeyword{linestyle},
\Lkeyword{linecolor}, \texttt{doubleline}, etc.) parameters are now active (but
there are not in non \emph{tiling} mode). And I also introduce new parameters
to control the tilings (see below).

 \textbf{In all the following examples, we will consider only the
\Lkeyword{tiling} mode.}
%
 To do a tiling, we have just to define the pattern with the
\Lcs{psboxfill} macro and to use the new \Lkeyword{fillstyle}
\Lkeyval{boxfill}.
%
 Note that tilings are drawn from left to right and top to bottom, which can
have an importance in some circonstances.
%
 PostScript programmers can be also interested to know that, even in the
\emph{automatic} mode, the iterations of the pattern are managed directly by
the PostScript code of the package which used only PostScript Level 1
operators. The special ones introduced in Level 2 for drawing of patterns
\cite[section 4.9]{PostScript95} are not used.
%
 And first, for conveniance, we define a simple \Lcs{Tiling} macro, which
will simplify our examples:
%
\begin{verbatim}
 \newcommand{\Tiling}[2][]{%
   \begin{pspicture}#2
       \psframe[fillstyle=boxfill,#1]#2
   \end{pspicture}}
\end{verbatim}
%
\subsection{Parameters}
%
 There are \textbf{14} specific parameters available to change the way the
filling/tiling is defined, and one debugging option.
%
\begin{description}
 \item [\Lkeyword{fillangle} (real)\hfill :] the value of the rotation
 applied to the patterns (\emph{Default:~0}).
\end{description}
%
\pstFillSetDefaults
%
  In this case, we must force the tiling area to be notably larger than the
area to cover, to be sure that the defined area will be covered after rotation.
\begin{LTXexample}[width=4cm,pos=l]
\newcommand\Cross{\begin{pspicture}(1,1)
  \psline[linecolor=red,dimen=middle](0,0.5)(1,0.5)
  \psline[linecolor=blue,dimen=middle](0.5,0)(0.5,1) 
\end{pspicture}}
\psset{unit=0.5cm}
\psboxfill{\Cross}
\Tiling[fillangle=0]{(3,3)} \\[2pt]
\Tiling[fillangle=45]{(3,3)}\\[2pt]
\Tiling[fillangle=-60]{(3,3)}
\end{LTXexample}


\begin{description}
  \item[\Lkeyword{fillsepx} (real$\|$dim) :] value of the horizontal
  separation between consecutive patterns (\emph{Default:~0 for
  tilings\footnote{This option is not part of the original package 
  and is available only if the
  \texttt{tiling} keyword is used when loading the package.} , 2pt otherwise}). 
  \item [\Lkeyword{fillsepy} (real$\|$dim)\hfill :] value of the vertical
  separation between consecutive patterns (\emph{Default:~0 for
  ti\-lings\footnote{ebd.}, 2pt otherwise}).
%\addtocounter{footnote}{-1}
  \item [\Lkeyword{fillsep} (real$\|$dim)\hfill :] value of horizontal and
  vertical separations between consecutive patterns (\emph{Default:~0 for
  tilings\footnote{ebd.}, 2pt otherwise}).
\end{description}

  These values can be negative, which allow the tiles to overlap.

\begin{LTXexample}[width=\linewidth]
\psset{unit=0.5cm}
\psboxfill{\Square}
\Tiling[fillsepx=2mm]{(3,3)} \quad
\Tiling[fillsepy=1mm]{(3,3)} \quad
\Tiling[fillsep=0.5]{(3,3)}  \quad
\Tiling[fillsep=-0.5]{(3,3)}
\end{LTXexample}




\begin{description}
  \item [\Lkeyword{fillcyclex}\footnotemark\ (integer)\hfill :] Shift
  coefficient applied to each row (\emph{Default:~0}).
  \footnote{It was \texttt{fillcycle} in the original version.}
  \item [\Lkeyword{fillcycley}\footnotemark\ (integer)\hfill :] Same thing for
  columns (\emph{Default:~0}).
  \item [\Lkeyword{fillcycle}\footnote{ebd.} (integer)\hfill :] Allow to fix
  both \Lkeyword{fillcyclex} and \Lkeyword{fillcycley} directly to the same value
  (\emph{Default:~0}).
\end{description}

  For instance, if \Lkeyword{fillcyclex} is 2, the second row of patterns will
be horizontally shifted by a factor of $\frac{1}{2}=0.5$, and by a factor of
0.333 if \Lkeyword{fillcyclex} is 3, etc.). These values can be negative.

\begin{LTXexample}[width=\linewidth]
\psset{unit=0.5}
\psboxfill{\Square}
\newcommand\TilingA[1]{\Tiling[fillcyclex=#1]{(3,3)}}
\TilingA{0} \TilingA{1} \quad
\TilingA{2} \TilingA{3}\quad
\TilingA{4} \TilingA{5}\quad
\TilingA{6} \TilingA{-3}\\[3mm]
\Tiling[fillcycley=2]{(3,3)}\quad
\Tiling[fillcycley=3]{(3,3)}\quad
\Tiling[fillcycley=-3]{(3,3)}\quad
\Tiling[fillcycle=2]{(3,3)}
\end{LTXexample}

\begin{description}
  \item [\Lkeyword{fillmovex}\footnotemark\ (real$\|$dim)\hfill :] value of the
  horizontal moves between consecutive patterns (\emph{Default:~0}).
  \item [\Lkeyword{fillmovey}\footnotemark\ (real$\|$dim)\hfill :] value of the
  vertical moves between consecutive patterns (\emph{Default:~0}).
  \item [\Lkeyword{fillmove}\footnotemark\ (real$\|$dim)\hfill :] value of
  horizontal and vertical moves between consecutive patterns
  (\emph{Default:~0}).
\end{description}

  These parameters allow the patterns to overlap and to draw some special
kinds of tilings. They are implemented only for the \emph{automatic} and
\emph{tiling} modes and their values can be negative.

  In some cases, the effect of these parameters will be the same that with the 
\texttt{fillcycle?} ones, but you can see that it is not true for some other
values.

\begin{LTXexample}
\psset{unit=0.5}
\psboxfill{\Square}
\Tiling[fillmovex=0.5]{(3,3)}\quad 
\Tiling[fillmovey=0.5]{(3,3)}\quad
\Tiling[fillmove=0.5]{(3,3)}\quad
\Tiling[fillmove=-0.5]{(3,3)}
\end{LTXexample}

\begin{description}
  \item [\Lkeyword{fillsize}
  (auto$\|$\{(real$\|$dim,real$\|$dim)(real$\|$dim,real$\|$dim)\}) :] The
  choice of \emph{automatic} mode or the size of the area in \emph{manual}
  mode. If first pair values are not given, (0,0) is used. (\emph{Default:
  auto when \emph{tiling} mode is used, {(-15cm,-15cm)(15cm,15cm)}
  otherwise}).
\end{description}

  As explained in the introduction, the \emph{manual} mode can require very
huge amount of computer ressources. So, it usage is to discourage in front off
the \emph{automatic} mode. It seems only useful in special circonstances, in
fact when the \emph{automatic} mode failed, which is known only in one case,
for some kinds of EPS files, as the ones produce by dump of portions of
screens (see \ref{sec:GraphicFiles}).

\begin{description}
  \item [\Lkeyword{fillloopaddx}\footnotemark\ (integer)\hfill :] number of
  times the pattern is added on left and right positions (\emph{Default:~0}).
  \item [\Lkeyword{fillloopaddy}\footnotemark\ (integer)\hfill :] number of
  times the pattern is added on top and bottom positions (\emph{Default:~0}).
  \item [\Lkeyword{fillloopadd}\footnotemark\ (integer)\hfill :] number of
  times the pattern is added on left, right, top and bottom positions
  (\emph{Default:~0}).
\end{description}

  These parameters are only useful in special circonstances, as for complex
patterns when the size of the rectangular box used to tile the area doesn't 
correspond to the pattern itself (see an example in Figure~\ref{fig:Sheeps})
and also sometimes when the size of the pattern is not a divisor of the size
of the area to fill and that the number of loop repeats is not properly
computed, which can occur.

  They are implemented only for the \emph{tiling} mode.



\begin{description}
  \item [\Lkeyword{PstDebug}\footnotemark\ (integer, 0 or 1)\hfill :] to
  require to see the exact tiling done, without clipping (\emph{Default:~0}).
\end{description}


  It's mainly useful for debugging or to understand better how the tilings
are done. It is implemented only for the \emph{tiling} mode.


%\begin{LTXexample}[width=\linewidth]
\psset{unit=0.3cm,PstDebug=1}
\psboxfill{\Square}
\psset{linewidth=1mm}
\Tiling{(2,2)}\hfill \Tiling[fillcyclex=2]{(2,2)}\hfill\Tiling[fillmove=0.5]{(2,2)}
%\end{LTXexample}

\begin{lstlisting}
\psset{unit=0.3cm,PstDebug=1}
\psboxfill{\Square}
\psset{linewidth=1mm}
\Tiling{(2,2)}\hfill \Tiling[fillcyclex=2]{(2,2)}\hfill\Tiling[fillmove=0.5]{(2,2)}
\end{lstlisting}

\psset{unit=1cm,PstDebug=0,linewidth=0.8pt}

\section{Examples}

  In fact this unique \Lcs{psboxfill} macro allow a lot a variations and
different usages. We will try here to demonstrate this.

\subsection{Kind of tiles}
\label{sec:KindTiles}

  Of course, we can access to all the power of PSTricks macros to define the
\emph{tiles} (\emph{patterns}) used. So, we can define complicated ones.

  Here we give four other Archimedian tilings (those built with only some
regular polygons) among the twelve existing, first discovered completely by
Johanes \textsc{Kepler} at the beginning of 17th century \cite{GS87}, the two
other \emph{regular} ones with the tiling by squares, formed by a unique
regular polygon, and two other formed by two different regular polygons.

\begin{LTXexample}[pos=t]
  \newcommand{\Triangle}{%
    \begin{pspicture}(1,1)
      \pstriangle[dimen=middle](0.5,0)(1,1)
    \end{pspicture}}
  \newcommand\Hexagon{
    \begin{pspicture}(0.866,0.75)% sin(60)=0.866
      \pspolygon[dimen=middle]% %  Hexagon
        (0.5;30)(0.5;90)(0.5;150)(0.5;210)(0.5;270)(0.5;330)
    \end{pspicture}}
  \psset{unit=0.5cm}
  \psboxfill{\Triangle}
  \Tiling{(4,4)}\qquad
  \Tiling[fillcyclex=2]{(4,4)}\qquad
  \psboxfill{\Hexagon}
  \Tiling[fillcyclex=2,fillloopaddy=1]{(5,5)}
\end{LTXexample}

\begin{LTXexample}[pos=t]
  \newcommand{\ArchimedianA}{%Archimedian tiling 3^2.4.3.4
    \psset{dimen=middle}
     % sin(60)=0.866
    \begin{pspicture}(1.866,1.866)
      \psframe(1,1)
      \psline(1,0)(1.866,0.5)(1,1)(0.5,1.866)(0,1)(-0.866,0.5)
      \psline(0,0)(0.5,-0.866)
    \end{pspicture}}
  \newcommand{\ArchimedianB}{% Archimedian tiling 4.8^2
    \psset{dimen=middle,unit=1.5cm}
     % sin(22.5)=0.3827 ; cos(22.5)=0.9239
    \begin{pspicture}(1.3066,0.6533)
      \SpecialCoor
     % Octogon
      \pspolygon(0.5;22.5)(0.5;67.5)(0.5;112.5)(0.5;157.5)
                (0.5;202.5)(0.5;247.5)(0.5;292.5)(0.5;337.5)
    \end{pspicture}}

  \psset{unit=0.5cm}
  \psboxfill{\ArchimedianA}
  \Tiling[fillmove=0.5]{(7,7)}\hfill
  \psboxfill{\ArchimedianB}
  \Tiling[fillcyclex=2,fillloopaddy=1]{(7,7)}
\end{LTXexample}

  We can of course tile an area arbitrarily defined. And with the
\Lkeyword{addfillstyle} parameter\footnote{Introduced in PSTricks 97.}, we can
easily mix the \Lkeyword{boxfill} style with another one.

\begin{LTXexample}[width=6cm]
  \psset{unit=0.5cm,dimen=middle}
  \psboxfill{%
    \begin{pspicture}(1,1)
      \psframe(1,1)
      \pscircle(0.5,0.5){0.25}
    \end{pspicture}}
  \begin{pspicture}(4,6)
    \pspolygon[fillstyle=boxfill,fillsep=0.25](0,1)(1,4)(4,6)(4,0)(2,1)
  \end{pspicture}\hspace{1em}
  \begin{pspicture}(4,4)
%    \pscircle[linestyle=none,fillstyle=solid,fillcolor=yellow,fillsep=0.5,
%              addfillstyle=boxfill](2,2){2}
  \end{pspicture}
\end{LTXexample}
%
  Various effects can be obtained, sometimes complicated ones very easily, as
in this example reproduced from one shown by Slavik \textsc{Jablan} in the
field of \emph{OpTiles}, inspired by the \emph{Op-art}:

\begin{LTXexample}[pos=t]
\newcommand\ProtoTile{%
 \begin{pspicture}(1,1)%%1/12=0.08333
  \psset{linestyle=none,linewidth=0,
    hatchwidth=0.08333\psunit,hatchsep=0.08333\psunit}
  \psframe[fillstyle=solid,fillcolor=black,addfillstyle=hlines,hatchcolor=white](1,1)
  \pswedge[fillstyle=solid,fillcolor=white,addfillstyle=hlines]{1}{0}{90}
 \end{pspicture}}
\newcommand\BasicTile{%
 \begin{pspicture}(2,1)
   \rput[lb](0,0){\ProtoTile}\rput[lb](1,0){\psrotateleft{\ProtoTile}}
 \end{pspicture}}
\ProtoTile\hfill\BasicTile\hfill
\psboxfill{\BasicTile}
\Tiling[fillcyclex=2]{(4,4)}
\end{LTXexample}

  It is also directly possible to surimpose several different tilings. Here is
the splendid visual proof of the \textsc{Pytha\-gore} theorem done by the arab
mathematician \textsc{Annairizi} around the year 900, given by superposition
of two tilings by squares of different sizes.

\begin{LTXexample}[pos=t]
\psset{unit=1.5,dimen=middle}
\begin{pspicture*}(3,3)
  \psboxfill{\begin{pspicture}(1,1)
    \psframe(1,1)\end{pspicture}}
  \psframe[fillstyle=boxfill](3,3)
  \psboxfill{\begin{pspicture}(1,1)
    \rput{-37}{\psframe[linecolor=red](0.8,0.8)}
  \end{pspicture}}
  \psframe[fillstyle=boxfill](3,4)
  \pspolygon[fillstyle=hlines,hatchangle=90](1,2)(1.64,1.53)(2,2)
\end{pspicture*}
\end{LTXexample}

  In a same way, it is possible to build tilings based on figurative patterns,
in the style of the famous \textsc{Escher} ones. Following an example of
Andr\'e \textsc{Deledicq} \cite{Deledicq97}, we first show a simple tiling of
the \emph{p1} category (according to the international classification of the
17~symmetry groups of the plane first discovered by the russian
crystalographer Jevgraf \textsc{Fedorov} at the end of the 19th century):

\begin{LTXexample}[pos=t]
 \newcommand\SheepHead[1]{%
   \begin{pspicture}(3,1.5)
     \pscustom[liftpen=2,fillstyle=solid,fillcolor=#1]{%
       \pscurve(0.5,-0.2)(0.6,0.5)(0.2,1.3)(0,1.5)(0,1.5)
         (0.4,1.3)(0.8,1.5)(2.2,1.9)(3,1.5)(3,1.5)(3.2,1.3)
         (3.6,0.5)(3.4,-0.3)(3,0)(2.2,0.4)(0.5,-0.2)}
     \pscircle*(2.65,1.25){0.12\psunit} %Eye
     \psccurve*(3.5,0.3)(3.35,0.45)(3.5,0.6)(3.6,0.4)% Muzzle
    %   Mouth
      \pscurve(3,0.35)(3.3,0.1)(3.6,0.05)
    %   Ear
      \pscurve(2.3,1.3)(2.1,1.5)(2.15,1.7)\pscurve(2.1,1.7)(2.35,1.6)(2.45,1.4)
  \end{pspicture}}
 \psboxfill{\psset{unit=0.5}\SheepHead{yellow}\SheepHead{cyan}}
 \Tiling[fillcyclex=2,fillloopadd=1]{(10,5)}
\end{LTXexample}
\label{fig:Sheeps}

  Now a tiling of the \emph{pg} category (the code for the kangaroo itself is
too long to be shown here, but has no difficulties ; the kangaroo is reproduce
from an original picture from Raoul \textsc{Raba} and here is a translation in
PSTricks from the one drawn by Emmanuel \textsc{Chailloux} and Guy
\textsc{Cousineau} for their MLgraph system \cite{MLgraphTSI}):

\begin{LTXexample}[pos=t]
\psboxfill{\psset{unit=0.4}
  \Kangaroo{yellow}\Kangaroo{red}\Kangaroo{cyan}\Kangaroo{green}%
  \psscalebox{-1 1}{%
    \rput(1.235,4.8){\Kangaroo{green}\Kangaroo{cyan}\Kangaroo{red}\Kangaroo{yellow}}}}
  \Tiling[fillloopadd=1]{(10,6)}
\end{LTXexample}

  And here a \textsc{Wang} tiling \cite{Wang65}, \cite[chapter
11]{GS87}, based on very simple tiles of the form of a square and composed
of four colored triangles. Such tilings are built with only a matching color
constraint. Despite of it simplicity, it is an important kind of tilings, as
\textsc{Wang} and others used them to study the special class of
\emph{aperiodic} tilings, and also because it was shown that surprisingly this 
tiling is similar to a \textsc{Turing} machine.

\begin{LTXexample}[pos=t]
  \newcommand{\WangTile}[4]{%
    \begin{pspicture}(1,1)
      \pspolygon*[linecolor=#1](0,0)(0,1)(0.5,0.5)
      \pspolygon*[linecolor=#2](0,1)(1,1)(0.5,0.5)
      \pspolygon*[linecolor=#3](1,1)(1,0)(0.5,0.5)
      \pspolygon*[linecolor=#4](1,0)(0,0)(0.5,0.5)
    \end{pspicture}}
  \newcommand{\WangTileA}{\WangTile{cyan}{yellow}{cyan}{cyan}}
  \newcommand{\WangTileB}{\WangTile{yellow}{cyan}{cyan}{red}}
  \newcommand{\WangTileC}{\WangTile{cyan}{red}{yellow}{yellow}}
  \newcommand{\WangTiles}[1][]{%
    \begin{pspicture}(3,3) \psset{ref=lb}
      \rput(0,2){\WangTileB}  \rput(1,2){\WangTileA}%
      \rput(2,2){\WangTileC}  \rput(0,1){\WangTileC}%
      \rput(1,1){\WangTileB}  \rput(2,1){\WangTileA}
      \rput(0,0){\WangTileA}  \rput(1,0){\WangTileC}%
      \rput(2,0){\WangTileB}
      #1
    \end{pspicture}}
  \WangTileA\hfill\WangTileB\hfill\WangTileC\hfill
  \WangTiles[{\psgrid[subgriddiv=0,gridlabels=0](3,3)}]\hfill
  \psset{unit=0.4} \psboxfill{\WangTiles} \Tiling{(12,12)}
\end{LTXexample}

\subsection{External graphic files}
\label{sec:GraphicFiles}

  We can also fill an arbitrary area with an external image. We have only, 
as usual, to matter of the \emph{BoundingBox} definition if there is no one
provided or if it is not the accurate one, as for the well known
\texttt{tiger} picture part of the \texttt{ghostscript} distribution.

\begin{LTXexample}[pos=t]
  \psboxfill{%Strangely require x1=x2...
    \begin{pspicture}(0,1)(0,4.1)
      \includegraphics[bb=17 176 560 74,width=3cm]{images/tiger}
    \end{pspicture}}
  \Tiling{(6,6.2)}
\end{LTXexample}

  Nevertheless, there are some special files for which the \emph{automatic}
mode doesn't work, specially for some files obtained by a screen dump, as in
the next example, where a picture was reduced before it conversion in the
\emph{Encapsulated PostScript} format by a screen dump utility. In this case,
usage of the \emph{manual} mode is the only alternative, at the price of the
real multiple inclusion of the EPS file. We must take care to specify the
correct \texttt{fillsize} parameter, because otherwise the default values are
large and will load the file many times, perhaps just really using few
occurrences as the other ones would be clipped...

\begin{LTXexample}[pos=t]
  \psboxfill{\includegraphics{images/flowers}}
  \begin{pspicture}(8,4)
    \psellipse[fillstyle=boxfill,fillsize={(8,4)}](4,2)(4,2)
  \end{pspicture}
\end{LTXexample}

\subsection{Tiling of characters}

  We can also use the \cs{psboxfill} macro to fill the interior of characters
for special effects like these ones:

\begin{LTXexample}[pos=t]
  \DeclareFixedFont{\bigsf}{T1}{phv}{b}{n}{4.5cm}
  \DeclareFixedFont{\smallrm}{T1}{ptm}{m}{n}{3mm}
  \psboxfill{\smallrm Since 182 days...}
  \begin{pspicture*}(8,4)
    \centerline{%
      \pscharpath[fillstyle=gradient,gradangle=-45,
                  gradmidpoint=0.5,addfillstyle=boxfill,
                  fillangle=45,fillsep=0.7mm]
                 {\rput[b](0,0.1){\bigsf 2000}}}
  \end{pspicture*}
\end{LTXexample}

\begin{LTXexample}[pos=t]
  \DeclareFixedFont{\mediumrm}{T1}{ptm}{m}{n}{2cm}
  \psboxfill{%
    \psset{unit=0.1,linewidth=0.2pt}
    \Kangaroo{PeachPuff}\Kangaroo{PaleGreen}%
      \Kangaroo{LightBlue}\Kangaroo{LemonChiffon}%
    \psscalebox{-1 1}{%
      \rput(1.235,4.8){%
        \Kangaroo{LemonChiffon}\Kangaroo{LightBlue}%
          \Kangaroo{PaleGreen}\Kangaroo{PeachPuff}}}}%
%   A kangaroo of kangaroos...
  \begin{pspicture}(8,2)
    \pscharpath[linestyle=none,fillstyle=boxfill,fillloopadd=1]
               {\rput[b](4,0){\mediumrm Kangaroo}}
  \end{pspicture}
\end{LTXexample}

\subsection{Other kinds of usage}

  Other kinds of usage can be imagined. For instance, we can use tilings in a
sort of degenerated way to draw some special lines made by a unique or
multiple repeating patterns. But it can be only a special dashed line, as here
with three different dashes:

\begin{LTXexample}[pos=t]
  \newcommand{\Dashes}{%
    \psset{dimen=middle}
    \begin{pspicture}(0,-0.5\pslinewidth)(1,0.5\pslinewidth)
      \rput(0,0){\psline(0.4,0)}%
        \rput(0.5,0){\psline(0.2,0)}%
        \rput(0.8,0){\psline(0.1,0)}
    \end{pspicture}}

  \newcommand{\SpecialDashedLine}[3]{%
    \psboxfill{#3}
    \Tiling[linestyle=none]
           {(#1,-0.5\pslinewidth)(#2,0.5\pslinewidth)}}

  \SpecialDashedLine{0}{7}{\Dashes}

  \psset{unit=0.5,linewidth=1mm,linecolor=red}
  \SpecialDashedLine{0}{10}{\Dashes}
\end{LTXexample}

  It allows also to use special patterns in business graphics, as in the
following example generated by \texttt{PstChart}\footnote{A personal
development to draw business charts with PSTricks, not distributed.}.


\vspace{3mm}
\begin{figure}[!ht]
\centering
\psset{unit=0.75cm}
% Generated by pstchart.sh version 0.21 (11/28/97)
{\psset{dimen=middle}
\psset{xunit=2,yunit=5}
\begin{pspicture}(-0.6,-0.2)(6.6,2.3)
%   Title
  \rput(3,2.200){\shortstack{Fantaisist repartition of kangaroos\\
                            in the world (in thousands)}}
%   Frame background
  \psframe*[linecolor=LemonChiffon!40](0,0)(6,2.000)
%   Graduations
  \multido{\r=0.0+0.500,\n=0+500}{5}{\rput[r](-0.12,\r){\psscalebox{0.8}{\n}}}
%   Minor ticks
  \multips(0,0.100)(0,0.100){19}{\psline[unit=4.8pt](1,0)}
  \multips(6,0.100)(0,0.100){19}{\psline[unit=4.8pt](-1,0)}
%   Major ticks
  \multips(0,0.500)(0,0.500){3}{\psline[unit=9.6pt](1,0)}
  \multips(6,0.500)(0,0.500){3}{\psline[unit=9.6pt](-1,0)}
%   Lines from major ticks marks
  \multips(0,0.500)(0,0.500){3}{\psline[linestyle=dotted,linewidth=0.6pt](6,0)}
%   Drawing for the data
  \psset{linestyle=none,fillcycley=1,fillcyclex=1,fillloopaddy=2}
  \psboxfill{\psset{unit=0.78\psxunit}\KangarooPstChart{red}}
  \rput(0.7,0){\psframe[fillstyle=boxfill](0,0)(0.75,1.8)}
  \psboxfill{\psset{unit=0.78\psxunit}\KangarooPstChart{yellow}}
  \rput(1.7,0){\psframe[fillstyle=boxfill](0,0)(0.75,0.8)}
  \psboxfill{\psset{unit=0.78\psxunit}\KangarooPstChart{cyan}}
  \rput(2.7,0){\psframe[fillstyle=boxfill](0,0)(0.75,0.55)}
  \psboxfill{\psset{unit=0.78\psxunit}\KangarooPstChart{magenta}}
  \rput(3.7,0){\psframe[fillstyle=boxfill](0,0)(0.75,0.5)}
  \psboxfill{\psset{unit=0.78\psxunit}\KangarooPstChart{green}}
  \rput(4.7,0){\psframe[fillstyle=boxfill](0,0)(0.75,0.2)}
%   Bottom labels
  \uput{0.2}[270]{0}(1,0){\psscalebox{0.7}{Oceania}}
  \uput{0.2}[270]{0}(2,0){\psscalebox{0.7}{Africa}}
  \uput{0.2}[270]{0}(3,0){\psscalebox{0.7}{Asia}}
  \uput{0.2}[270]{0}(4,0){\psscalebox{0.7}{America}}
  \uput{0.2}[270]{0}(5,0){\psscalebox{0.7}{Europe}}
%   Frame box around the chart
  \psframe[linestyle=solid](0,0)(6,2.000)
\end{pspicture}}
  \caption{Bar chart generated by PstChart, with bars filled by patterns}
  \label{fig:PstChart}
\end{figure}


\section{``Dynamic'' tilings}

  In some cases, tilings used non \emph{static} tiles, that is to say that the 
\emph{prototile(s)}, even if unique, can have several forms, by instance
specified by different colors or rotations, not fixed before generation or
varying each time.

\subsection{Lewthwaite-Pickover-Truchet tiling}





  We give here for example the so-called \emph{Truchet} tiling, which much be
in fact better called \emph{Lewthwaite-Pick\-over-Truchet (LPT)} tiling%
\footnote{For description of the context, history and references about
S\'ebastien \textsc{Truchet} and this tiling, see \cite{EsperetGirou98}.}.

  The unique prototile is only a square with two opposite circle arcs.
This tile has obviously two positions, if we rotate it from 90 degrees (see
the two tiles on the next figure). A \emph{LPT tiling} is a tiling with
randomly oriented LPT tiles. We can see that even if it is very simple in it
principle, it draw sophisticated curves with strange properties.

  Nevertheless, in the straightforward way \FillPackage{} does not work,
because the \Lcs{psboxfill} macro store the content of the tile used in a
\TeX{} box, which is static. So the calling to the random function is done
only one time, which explain that only one rotation of the tile is used for
all the tiling. It's only the one of the two rotations which could differ from
one drawing to the next one...

% Truchet (Lewthwaite-Pickover-Truchet) tiling
% --------------------------------------------

\begin{LTXexample}[pos=t]
%   LPT prototile
  \newcommand\ProtoTileLPT{%
    \psset{dimen=middle}
    \begin{pspicture}(1,1)
      \psframe(1,1)
      \psarc(0,0){0.5}{0}{90}
      \psarc(1,1){0.5}{-180}{-90}
    \end{pspicture}}

%   LPT tile
  \newcount\Boolean
  \newcommand{\BasicTileLPT}{%
%     From random.tex by Donald Arseneau
    \setrannum{\Boolean}{0}{1}%
    \ifnum\Boolean=0
      \ProtoTileLPT%
    \else
      \psrotateleft{\ProtoTileLPT}%
    \fi}

  \ProtoTileLPT\hfill\psrotateleft{\ProtoTileLPT}\hfill
  \psset{unit=0.5}
  \psboxfill{\BasicTileLPT}
  \Tiling{(5,5)}
\end{LTXexample}


  But, for simple cases, there is a solution to this problem using a mixture
of PSTricks and PostScript programming. Here the PSTricks
construction \Lcs{pscustom}\verb+{+\Lcs{code}\verb+{...}}+ allow to insert PostScript code
inside the \LaTeX{} + PSTricks one.

  Programmation is less straightforward, but it has also the advantage to be
notably faster, as all the tilings operations are done in PostScript, and
mainly to not be limited by \TeX{} memory (the \TeX{} + PSTricks solution
I wrote in 1995 for the colored problem was limited to small sizes for this
reason). Just note also that \Lcs{pslbrace} and \Lcs{psrbrace} are two
PSTricks macros to define and be able to insert the \verb+{+ and \verb+}+
characters.




\begin{LTXexample}[pos=t]
%   LPT prototile
\newcommand\ProtoTileLPT{%
    \psset{dimen=middle}
    \psframe(1,1)
    \psarc[linecolor=blue](0,0){0.5}{0}{90}
    \psarc[linecolor=red](1,1){0.5}{-180}{-90}}

\newcount\InitCounter

\ifPSTlualatex
  \newcommand\BasicTileLPT{%
    \InitCounter=\the\time
    \begin{pspicture}(1,1)
      \pstverb{
        rand \the\InitCounter\space add 2 mod 0 eq  
        {\luaPSTbox\hbox{\ProtoTileLPT}}%
        { 1 0 \csname tx@ScreenCoor\endcsname translate
         \luaPSTbox\hbox{\psrotateleft{\ProtoTileLPT}}} ifelse /.TeXBox findresource exec
      }% 
  \end{pspicture}}
\else
  \newcommand\BasicTileLPT{%
    \InitCounter=\the\time
    \pscustom{\code{%
      rand \the\InitCounter\space add 2 mod 0 eq \pslbrace}}
    \begin{pspicture}(1,1)
      \ProtoTileLPT
    \end{pspicture}%
    \pscustom{\code{\psrbrace \pslbrace}}
    \psrotateleft{\ProtoTileLPT}%
    \pscustom{\code{\psrbrace ifelse}}}
\fi
\psset{fillcycley=1,fillcyclex=1,fillloopaddy=2,unit=0.4,linewidth=0.8pt}
\psboxfill{\BasicTileLPT}
\Tiling{(10,10)}
\end{LTXexample}




  Using the very surprising fact (see \cite{EsperetGirou98}) that
coloration of these tiles do not depend of their neighbors (even if it is
difficult to believe as the opposite seems obvious!) but only of the parity of
the value of row and column positions, we can directly program in the same way
a colored version of the LPT tiling.

  We have also introduce in the \FillPackage{} code for \emph{tiling} mode two
new accessible Post\-Script variables, \texttt{row} and
\texttt{column}\footnotemark, which can be useful in some circonstances, like
this one.





\newcommand\ProtoTileLPT[2]{%
    \psset{dimen=middle,linestyle=none,fillstyle=solid}
    \psframe[fillcolor=#1](1,1)
    \psset{fillcolor=#2}
    \pswedge(0,0){0.5}{0}{90} 
    \pswedge(1,1){0.5}{-180}{-90}}
    
\newcount\InitCounter

\ifPSTlualatex
  \newcommand\BasicTileLPT[2]{%
    \InitCounter=\the\time
    \begin{pspicture}(1,1)%
      \pstverb{
        rand \the\InitCounter\space sub 2 mod 0 eq {
          \txfillDict row column end add 2 mod 0 eq {\luaPSTbox\hbox{%
            \ProtoTileLPT{#1}{#2}%
          }} {\luaPSTbox\hbox{%
             \ProtoTileLPT{#2}{#1}%
          }} ifelse /.TeXBox findresource exec
        } {
          1 0 \csname tx@ScreenCoor\endcsname translate 
             \txfillDict row column end add 2 mod 0 eq {\luaPSTbox\hbox{%
            \psrotateleft{\ProtoTileLPT{#2}{#1}}%
          }} {\luaPSTbox\hbox{%
            \psrotateleft{\ProtoTileLPT{#1}{#2}}%
          }} ifelse /.TeXBox findresource exec
      } ifelse
    }%
  \end{pspicture}}
\else
  \newcommand\BasicTileLPT[2]{%
      \InitCounter=\the\time
      \pscustom{\code{%
        rand \the\InitCounter\space sub 2 mod 0 eq \pslbrace
        row column add 2 mod 0 eq \pslbrace}}
      \begin{pspicture}(1,1)\ProtoTileLPT{#1}{#2}\end{pspicture}%
      \pscustom{\code{\psrbrace \pslbrace}}
      \ProtoTileLPT{#2}{#1}%
      \pscustom{\code{%
        \psrbrace ifelse \psrbrace \pslbrace row column add 2 mod 0 eq \pslbrace}}
      \psrotateleft{\ProtoTileLPT{#2}{#1}}\pscustom{\code{\psrbrace \pslbrace}}
      \psrotateleft{\ProtoTileLPT{#1}{#2}}\pscustom{\code{\psrbrace ifelse \psrbrace ifelse}}}
\fi

\psboxfill{\BasicTileLPT{red}{yellow}}
\Tiling{(4,4)}\hfill
\psset{unit=0.4}\psboxfill{\BasicTileLPT{blue}{cyan}}
\Tiling{(15,15)}


\psset{unit=1cm}
\begin{lstlisting}
\newcommand\ProtoTileLPT[2]{%
    \psset{dimen=middle,linestyle=none,fillstyle=solid}
    \psframe[fillcolor=#1](1,1)
    \psset{fillcolor=#2}
    \pswedge(0,0){0.5}{0}{90} 
    \pswedge(1,1){0.5}{-180}{-90}}
    
\newcount\InitCounter

  \newcommand\BasicTileLPT[2]{%
    \InitCounter=\the\time
    \begin{pspicture}(1,1)%
      \pstverb{
        rand \the\InitCounter\space sub 2 mod 0 eq {
          \txfillDict row column end add 2 mod 0 eq {\luaPSTbox\hbox{%
            \ProtoTileLPT{#1}{#2}%
          }} {\luaPSTbox\hbox{%
             \ProtoTileLPT{#2}{#1}%
          }} ifelse /.TeXBox findresource exec
        } {
          1 0 \csname tx@ScreenCoor\endcsname translate 
             \txfillDict row column end add 2 mod 0 eq {\luaPSTbox\hbox{%
            \psrotateleft{\ProtoTileLPT{#2}{#1}}%
          }} {\luaPSTbox\hbox{%
            \psrotateleft{\ProtoTileLPT{#1}{#2}}%
          }} ifelse /.TeXBox findresource exec
      } ifelse
    }%
  \end{pspicture}}

  \psboxfill{\BasicTileLPT{red}{yellow}}
  \Tiling{(4,4)}\hfill
 \psset{unit=0.4}\psboxfill{\BasicTileLPT{blue}{cyan}}
 \Tiling{(15,15)}
\end{lstlisting}


  Another classic example is to generate coordinates and numerotation for a
grid. Of course, it is possible to do it directly in PSTricks using nested
\Lcs{multido} commands. It would be clearly easy to program, but, nevertheless, 
for users who have a little knowledge of PostScript programming, this offer
an alternative which is useful for large cases, because on this way it will
be notably faster and less computer ressources consuming.

  Remember here that the tiling is drawn from left to right, and top to
bottom, and note that the PostScript variable \texttt{x2} give the total
number of columns.



\begin{externalDocument}[
%  grfOptions={width=0.48\linewidth},
%  pages={1,3},
%  frame,
  compiler=lualatex,
%  showFilename,
  crop,
  cropmargin=5,
  eps,
  force,
  %runs=2,
  code,
  docType=latex,
  %frame,
  %lstOptions={columns=fixed}
  ]{pst-fill-doc}
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress}
\documentclass{article}
\pagestyle{empty}
\usepackage[tiling]{pst-fill}
%StartVisiblePreamble
\newcommand\Square{\begin{pspicture}(1,1)\psframe[dimen=middle](1,1)\end{pspicture}}
\newcommand\Tiling[2][]{%
 \begin{pspicture}#2 \psframe[fillstyle=boxfill,#1]#2\end{pspicture}}
\newcommand\ProtoTile{%
  \Square
  \pscustom{%
      \moveto(-0.9,0.75) % In PSTricks units
      \code{\ifPSTlualatex\txfillDict\fi
        /Times-Italic findfont 8 scalefont setfont
        (\string\() show row 3 string cvs show (,) show 
        column 3 string cvs show (\string\)) show \ifPSTlualatex end \fi}
      \moveto(-0.5,0.25) % In PSTricks units
      \code{\ifPSTlualatex\txfillDict\fi
        /Times-Bold findfont 18 scalefont setfont
        1 0 0 setrgbcolor % Red color
        /center { dup stringwidth pop 2 div neg 0 rmoveto } def
         row 1 sub x2 mul column add 3 string cvs  
        center show \ifPSTlualatex end \fi }}}
%StopVisiblePreamble
\begin{document}
\psset{fillcycley=0,fillcyclex=0,fillloopaddy=0}
\psboxfill{\ProtoTile}
\Tiling{(6,4)}
\end{document}
\end{externalDocument}



\subsection{A complete example: the Poisson equation}

  To finish, we will show a complete real example, a drawing to explain the
method used to solve the \textsc{Poisson} equation by a domain
decomposition method, adapted to distributed memory computers. The
objective is to show the communications required between processes and the
position of the data to exchange. This code also show some useful and powerful
technics for PSTricks programming (look specially at the way some higher level
macros are defined, and how the same object is used to draw the four
neighbors).

\psset{unit=1cm}
\newcommand{\Pattern}[1]{%
  \begin{pspicture}(-0.25,-0.25)(0.25,0.25)\rput{*0}{\psdot[dotstyle=#1]}
  \end{pspicture}}
\newcommand{\West}{\Pattern{o}}   \newcommand{\South}{\Pattern{x}}
\newcommand{\Central}{\Pattern{+}}\newcommand{\North}{\Pattern{square}}
\newcommand{\East}{\Pattern{triangle}}
\newcommand{\Cross}{%
 \pspolygon[unit=0.5,linewidth=0.2,linecolor=red](0,0)(0,1)(1,1)(1,2)(2,2)(2,1)%
             (3,1)(3,0)(2,0)(2,-1)(1,-1)(1,0)}
\newcommand{\StylePosition}[1]{\LARGE\textcolor{red}{\textbf{#1}}}
\newcommand{\SubDomain}[4]{%
   \psboxfill{#4}\begin{psclip}{\psframe[linestyle=none]#1}%
     \psframe[linestyle=#3](5,5)\psframe[fillstyle=boxfill]#2%
   \end{psclip}}
\newcommand{\SendArea}[1]{\psframe[fillstyle=solid,fillcolor=cyan]#1}
\newcommand{\ReceiveData}[2]{%
 \psboxfill{#2}\psframe[fillstyle=solid,fillcolor=yellow,addfillstyle=boxfill]#1}%
\newcommand{\Neighbor}[2]{%
   \begin{pspicture}(5,5)
     \rput{*0}(2.5,2.5){\StylePosition{#1}}
     \ReceiveData{(0.5,0)(4.5,0.5)}{\Central}\SendArea{(0.5,0.5)(4.5,1)}%
     \SubDomain{(5,2)}{(0.5,0.5)(4.5,3)}{dashed}{#2}%
     \pcarc[arcangle=45,arrows=->](0.5,-1.25)(0.5,0.25)%
     \pcarc[arcangle=45,arrows=->,linestyle=dotted,dotsep=2pt](4.5,0.75)(4.5,-0.75)%
   \end{pspicture}}%
 \psset{dimen=middle,dotscale=2,fillloopadd=2}
\begin{pspicture}(-5.7,-5.7)(5.7,5.7)
 \rput(0,0){%
     \begin{pspicture}(5,5)
       \ReceiveData{(0,0.5)(0.5,4.5)}{\West} \ReceiveData{(4.5,0.5)(5,4.5)}{\East}
       \ReceiveData{(0.5,4.5)(4.5,5)}{\North}\ReceiveData{(0.5,0)(4.5,0.5)}{\South}
       \SendArea{(0.5,0.5)(1,4.5)}\SendArea{(4,0.5)(4.5,4.5)}
       \SendArea{(0.5,0.5)(4.5,1)}\SendArea{(0.5,4)(4.5,4.5)}
       \SubDomain{(5,5)}{(0.5,0.5)(4.5,4.5)}{solid}{\Central}
       \psline(1,0.5)(1,4.5)\psline(4,0.5)(4,4.5)%
       \rput(1.5,4){\Cross}\rput(2,2){\Cross}%
     \end{pspicture}}%
 \rput(0,5.5){\Neighbor{N}{\North}}\rput{-90}(5.5,0){\Neighbor{E}{\East}}%
 \rput{90}(-5.5,0){\Neighbor{W}{\West}}\rput{180}(0,-5.5){\Neighbor{S}{\South}}%
\end{pspicture}

\begin{lstlisting}
  \newcommand{\Pattern}[1]{%
    \begin{pspicture}(-0.25,-0.25)(0.25,0.25)\rput{*0}{\psdot[dotstyle=#1]}
    \end{pspicture}}
  \newcommand{\West}{\Pattern{o}}   \newcommand{\South}{\Pattern{x}}
  \newcommand{\Central}{\Pattern{+}}\newcommand{\North}{\Pattern{square}}
  \newcommand{\East}{\Pattern{triangle}}
  \newcommand{\Cross}{%
    \pspolygon[unit=0.5,linewidth=0.2,linecolor=red](0,0)(0,1)(1,1)(1,2)(2,2)(2,1)
              (3,1)(3,0)(2,0)(2,-1)(1,-1)(1,0)}
  \newcommand{\StylePosition}[1]{\LARGE\textcolor{red}{\textbf{#1}}}
  \newcommand{\SubDomain}[4]{%
    \psboxfill{#4}
    \begin{psclip}{\psframe[linestyle=none]#1}
      \psframe[linestyle=#3](5,5)\psframe[fillstyle=boxfill]#2
    \end{psclip}}
  \newcommand{\SendArea}[1]{\psframe[fillstyle=solid,fillcolor=cyan]#1}
  \newcommand{\ReceiveData}[2]{%
    \psboxfill{#2}
    \psframe[fillstyle=solid,fillcolor=yellow,addfillstyle=boxfill]#1}
  \newcommand{\Neighbor}[2]{%
    \begin{pspicture}(5,5)
      \rput{*0}(2.5,2.5){\StylePosition{#1}}
      \ReceiveData{(0.5,0)(4.5,0.5)}{\Central}\SendArea{(0.5,0.5)(4.5,1)}
      \SubDomain{(5,2)}{(0.5,0.5)(4.5,3)}{dashed}{#2}%
%       Receive and send arrows
      \pcarc[arcangle=45,arrows=->](0.5,-1.25)(0.5,0.25)
      \pcarc[arcangle=45,arrows=->,linestyle=dotted,dotsep=2pt](4.5,0.75)(4.5,-0.75)
    \end{pspicture}}
  \psset{dimen=middle,dotscale=2,fillloopadd=2}
  \begin{pspicture}(-5.7,-5.7)(5.7,5.7)
%     Central domain
    \rput(0,0){%
      \begin{pspicture}(5,5)
%         Receive from West, East, North and South
        \ReceiveData{(0,0.5)(0.5,4.5)}{\West} \ReceiveData{(4.5,0.5)(5,4.5)}{\East}
        \ReceiveData{(0.5,4.5)(4.5,5)}{\North}\ReceiveData{(0.5,0)(4.5,0.5)}{\South}
%         send area for West, East, North and South
        \SendArea{(0.5,0.5)(1,4.5)} \SendArea{(4,0.5)(4.5,4.5)}
        \SendArea{(0.5,0.5)(4.5,1)} \SendArea{(0.5,4)(4.5,4.5)}
%         Central domain
        \SubDomain{(5,5)}{(0.5,0.5)(4.5,4.5)}{solid}{\Central}
%         Redraw overlapped linesY
        \psline(1,0.5)(1,4.5)  \psline(4,0.5)(4,4.5)
%         Two crossesY
        \rput(1.5,4){\Cross}  \rput(2,2){\Cross}
      \end{pspicture}}
%     The four neighborsY
    \rput(0,5.5){\Neighbor{N}{\North}}     \rput{-90}(5.5,0){\Neighbor{E}{\East}}
    \rput{90}(-5.5,0){\Neighbor{W}{\West}} \rput{180}(0,-5.5){\Neighbor{S}{\South}}
  \end{pspicture}
\end{lstlisting}
%

\section{Debugging}

For debugging (to debug, set PstDebug=1)
we now use the one from pstricks to prevent a clash with package
pstricks                        2004-06-22
%   \define@key[psset]{pst-fill}{PstDebug}{\pst@getint{#1}\psk@PstDebug}
    \psset{PstDebug=0}

\printbibliography
\printindex


\end{document}

