The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
%% Copyright 2013 Kevin Ryde
%%
%% This file is part of Math-PlanePath.
%%
%% Math-PlanePath is free software; you can redistribute it and/or modify it
%% under the terms of the GNU General Public License as published by the Free
%% Software Foundation; either version 3, or (at your option) any later
%% version.
%%
%% Math-PlanePath is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
%% or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
%% for more details.
%%
%% You should have received a copy of the GNU General Public License along
%% with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.


%% Usage: latex dragon-pgf-latex.tex
%%        xdvi dragon-pgf-latex.dvi

%% See dragon-pgf-plain.tex for more comments.  The F,S here behave
%% the same as there.
%%
%% The rule here is a 45-degree variation which keeps the net
%% direction unchanged after expansion.  This means the curve endpoint
%% remains in a fixed direction horizontal no matter what expansion
%% level is applied.
%%
%% Does Mandelbrot's book ``Fractal Geometry of Nature'' have an
%% expansion like this, but maybe with just a single drawing symbol?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}

\pgfdeclarelindenmayersystem{Dragon curve}{
  \symbol{S}{\pgflsystemdrawforward}
  \rule{F -> -F++S-}
  \rule{S -> +F--S+}
}

\foreach \i in {1,...,8} {
  \hbox{
    order=\i
    \hspace{.5em}
    \begin{tikzpicture}[baseline=0pt]
    \draw
      [lindenmayer system={Dragon curve, step=10pt,angle=45, axiom=F, order=\i}]
      lindenmayer system;
    \end{tikzpicture}
    \hspace{1em}
  }
  \vspace{.5ex}
}
\end{document}