%% Package `pst-koch2.tex'
%%
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   Draw Koch curves
%%   dessiner les courbes de Koch
\let\PSTKOCHLoaded\endinput
% Requires PSTricks, pst-xkey, pst-plot  packages
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey.tex \fi
\ifx\PSTplotLoaded\endinput\else\input pst-plot.tex\fi
\def\fileversion{2.0}
\def\filedate{2016/10/24}
\message{`PST' v\fileversion, \filedate}

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax

\pst@addfams{pst-koch}

\define@key[psset]{pst-koch}{N}{\def\pst@koch@N{#1 }} % nombre d'itérations
\define@key[psset]{pst-koch}{motif}{\def\pst@koch@motif{#1 }} % motif ou génératrice
\define@key[psset]{pst-koch}{base}{\def\pst@koch@base{#1 }} %  base
\define@key[psset]{pst-koch}{angle}{\def\pst@koch@angle{#1 }} %  angle cesaro
\psset[pst-koch]{N=3,motif=motifA,base=line,angle=85}
%
\def\psKoch{\def\pst@par{}\pst@object{psKoch}}
\def\psKoch@i{%
    \begin@SpecialObj
\addto@pscode{
 (pst-koch-examples.dat) run
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    /cm {\pst@number\psunit mul} bind def % mise à l'échelle
    /angle \pst@koch@angle def
  angle 60 le {/angle 60 def} if
  angle 90 ge {/angle 90 def} if
    /L' 1 2 angle cos 1 add mul div def % for cesaro
%    /H' L' angle sin mul def
/transformation {% les 2 extrémités du segment
2 dict begin
	/y exch def
	/x exch def
		x x2 x1 sub mul y y2 y1 sub mul sub x1 add % x'
		x y2 y1 sub mul y x2 x1 sub mul add y1 add % y'
end
} def
/Generatrice  [\pst@koch@motif] def
/Liste [\pst@koch@base] def
\pst@koch@N {
[
0 2 Liste length 4 sub {/i exch def
	/x1 Liste i get def
	/y1 Liste i 1 add get def
	/x2 Liste i 2 add get def
	/y2 Liste i 3 add get def
0 2	Generatrice length 2 sub {/j exch def
    Generatrice j get
    Generatrice j 1 add get
    transformation
} for
} for
] /Liste exch def
} repeat
}%
\ifPst@HSB
\listplotHSB{Liste aload pop}
\else
\listplot{Liste aload pop}
\fi
        \showpointsfalse
    \end@SpecialObj
    \ignorespaces}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% adaptation de \parametricplotHSB
% à \lisplotHSB
% le 10 juin 2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\define@key[psset]{pst-koch}{HueBegin}{% Between 0 and 1
\edef\PstListplotHSB@HueBegin{#1 }}

\define@key[psset]{pst-koch}{HueEnd}{% Between 0 and 1
\edef\PstListplotHSB@HueEnd{#1 }}

\newif\ifPst@HSB
\define@key[psset]{pst-koch}{HSB}[true]{\@nameuse{Pst@HSB#1}}

% Default values
\psset{HueBegin=0,HueEnd=1,HSB=true}
\def\listplotHSB{\pst@object{listplotHSB}}
\def\listplotHSB@i#1{%
\begin@ClosedObj
  \addto@pscode{%
  1 setlinecap
  /Counter 0 def
     /XY [ #1 ] def
     XY 0 get
     XY 1 get
  \pst@number\psyunit mul exch
  \pst@number\psxunit mul exch
       moveto
     /L XY length def
     2 2 L 2 sub {/i exch def
   /x1  XY i get \pst@number\psxunit mul def
   /y1  XY i 1 add get \pst@number\psyunit mul def
    x1 y1
    \ifPst@HSB
    Counter L 2 div div
    \PstListplotHSB@HueEnd
    \PstListplotHSB@HueBegin sub mul
    \PstListplotHSB@HueBegin add
    1 1 sethsbcolor
    /Counter Counter 1 add def
    \fi
     lineto
     stroke
  x1 y1 moveto
  } for
  }%
\end@ClosedObj}
\catcode`\@=\PstAtCode\relax
\endinput 