%% 
%%  Ein Beispiel der DANTE-Edition
%% 
%% 
%%  Copyright (C) 2010 Herbert Voss
%% 
%%  It may be distributed and/or modified under the conditions
%%  of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%% 
%%  See http://www.latex-project.org/lppl.txt for details.
%% 
%% 
%% ==== 
% Show page(s) 1
%% 
\documentclass[]{exaarticle}
\pagestyle{empty}
\setlength\textwidth{392.64803pt}
\StartShownPreambleCommands
\usepackage{pstricks,pst-xkey}
\SpecialCoor
\makeatletter
\pst@addfams{pst-chaos} % eine eigene Familie festlegen
\newdimen\psk@chaos@xWidth
\define@key[psset]{pst-chaos}{xWidth}{\pssetlength\psk@chaos@xWidth{#1}}
\newdimen\psk@chaos@yWidth
\define@key[psset]{pst-chaos}{yWidth}{\pssetlength\psk@chaos@yWidth{#1}}
\define@key[psset]{pst-chaos}{dColor}{\def\psk@dColor{#1 }}
\define@boolkey[psset]{pst-chaos}[Pst@]{Julia}[true]{}
\psset[pst-chaos]{xWidth=1cm,yWidth=1cm,dColor=1,Julia}

\define@key[psset]{pst-chaos}{plotpoints}{\pst@checknum{#1}\pst@chaos@plotpoints}
\psset[pst-chaos]{plotpoints=100}

\def\psSier{\pst@object{psSier}}
\def\psSier@i(#1)(#2)(#3){%
  \pst@getcoor{#1}\pst@tempA
  \pst@getcoor{#2}\pst@tempB
  \pst@getcoor{#3}\pst@tempC
  \begin@SpecialObj%
  \addto@pscode{
    /Koor [ \pst@tempA
            \pst@tempB
    \pst@tempC ] def
    /Sx 0 def /Sy 0 def
    /setzePixel { % x y auf dem Stack
0.5 0 360 arc stroke
    } def
    /neuePosition { % Punktnummer auf dem Stack
Koor exch 2 getinterval aload pop
/y exch def  /x exch def
x Sx sub 2 div Sx add /Sx exch def
y Sy sub 2 div Sy add /Sy exch def
Sx Sy setzePixel
    } def
    /zeichneRahmen {
Koor aload pop
newpath
moveto
nKoor 1 sub { % nur noch n-1 mal
         lineto
} repeat
gsave 0.9 setgray fill grestore
\pst@usecolor\pslinecolor
closepath
stroke
% 0 setgray
    } def
    /nKoor Koor length 2 div 0.5 add cvi def % Anzahl Punkte
    zeichneRahmen
    \pst@chaos@plotpoints\space cvi {
rand nKoor mod
dup add neuePosition
    } repeat
  }% end add@pscode
  \end@SpecialObj%
}
\def\pschaos{\pst@object{pschaos}}
\def\pschaos@i{\@ifnextchar({\pschaos@ii}{\pschaos@ii(-1,-1)}}%
\def\pschaos@ii(#1,#2){\@ifnextchar({\pschaos@iii(#1,#2)}{\pschaos@ii(#1,#2)(1,1)}}%
\def\pschaos@iii(#1,#2)(#3,#4){%
  \begin@SpecialObj%
  \pspicture(\psk@chaos@xWidth,\psk@chaos@yWidth)%
  \addto@pscode{
    /MinX #1 def
    /MaxX #3 def
    /MinY #2 def
    /MaxY #4 def
    /MaxXPixel \pst@number\psk@chaos@xWidth def
    /MaxYPixel \pst@number\psk@chaos@yWidth def
    /PixelDicke 0.5 def
    /maxIter 100 def
    /maxR 100 def
%
    /dx MaxX MinX sub MaxXPixel div def
    /dy MaxY MinY sub MaxYPixel div def
%
    /convertX {% erwartet x-Wert auf dem Stack
      MaxX sub dx div % Umrechnung in Pixel
    } def
    /convertY {% erwartet x-Wert auf dem Stack
      MinY sub dy div % Umrechnung in Pixel
    } def
    /convertXY {% erwartet x y auf dem Stack
      convertY exch convertX exch
    } def
%
    /setzePixel {%  x y auf dem Stack in Benutzerkoordinaten
      convertXY
      PixelDicke 0 360 arc fill
    } def
    MinX dx MaxX {
      /x exch def
      MinY dy MaxY {
/y exch def
/iter 0 def
             \ifPst@Julia
               /cx 0 def
               /cy 0 def
/zx x def
/zy y def
             \else
              /cx x def
              /cy y def
/zx 0 def
/zy 0 def
             \fi
/plot true def
maxIter {
    zx dup mul zy dup mul add maxR gt {/plot false def exit}
{% Calculate next value
    2 zx zy mul mul cy add
    /zx zx dup mul zy dup mul sub cx add def
    /zy exch def
    /iter iter \psk@dColor add def
    } ifelse
} repeat
plot{
    0 0 0 setrgbcolor
    x y setzePixel
}{
    1 iter sub 0 1 setrgbcolor
    iter 1 ge {0 iter 1 sub 2 iter sub setrgbcolor} if
    iter 2 ge {iter 2 sub 1 0 setrgbcolor} if
    iter 3 ge {1 4 iter sub .35 mul .65 add 0 setrgbcolor} if
    iter 4 ge {1 5 iter sub .65 mul 0 setrgbcolor} if
    x y setzePixel stroke
}ifelse % Plot point if point is in set
    } for
  } for
  }% end add@pscode
  \endpspicture% end box
  \end@SpecialObj%
}
\makeatother
\StopShownPreambleCommands
\begin{document}
\begin{center}
\begin{minipage}{0.45\textwidth}\centering
Eine Mandelbrotmenge: \\[10pt]
\begin{pspicture}(6,6)
\pschaos[xWidth=6cm,yWidth=6cm,dColor=1,Julia=false](-2,-1.25)(0.5,1.25)
\end{pspicture}
\end{minipage}~
\begin{minipage}{0.45\textwidth}\centering
Ein Sierpinskidreieck: \\[10pt]
\begin{pspicture}(6,6)
  \psSier[plotpoints=5000](0,0)(2,6)(6,0)
\end{pspicture}
\end{minipage}

\bigskip
Eine Juliamenge:\\[10pt]
\pschaos[xWidth=5cm,yWidth=5cm,dColor=0.5](-1.5,-1.5)(1.5,1.5)
\end{center}
\end{document}
