summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-fractal/pst-fractal.tex
blob: c6f701476583b2259a172d9bb6dc6190fce9dce5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
%%
%% This is file `pst-fractal.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Package `pst-fractal.tex'
%%
%% Herbert Voss <voss _at_ pstricks dot de>
%%
%% 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:
%%   `pst-fractal' is a PSTricks package to draw Julia and
%%       Mandelbrot sets as well as Sierpinski, ...
%%
\csname PSTfractalLoaded\endcsname
\let\PSTfractalLoaded\endinput
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTricksAddLoaded\endinput\else\input pstricks-add.tex\fi
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi
%
\def\fileversion{0.03}
\def\filedate{2007/04/05}
\message{`PST-fractal' v\fileversion, \filedate\space (hv)}
%
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-fractal}
%\SpecialCoor
%
\newdimen\psk@fractal@xWidth
\define@key[psset]{pst-fractal}{xWidth}{\pssetlength\psk@fractal@xWidth{#1}}
\newdimen\psk@fractal@yWidth
\define@key[psset]{pst-fractal}{yWidth}{\pssetlength\psk@fractal@yWidth{#1}}
\psset[pst-fractal]{xWidth=1cm,yWidth=1cm}
\define@key[psset]{pst-fractal}{type}{\def\pst@fractal@type{#1}}
\psset[pst-fractal]{type=Julia}% or type=Mandel
\def\pst@fractal@Julia{Julia}\def\pst@fractal@Mandel{Mandel}
\define@key[psset]{pst-fractal}{baseColor}{\pst@getcolor{#1}\pst@fractal@baseColor}
\psset[pst-fractal]{baseColor=black}
%
\define@key[psset]{pst-fractal}{cx}{\def\psk@fractal@cx{#1 }}
\define@key[psset]{pst-fractal}{cy}{\def\psk@fractal@cy{#1 }}
\define@key[psset]{pst-fractal}{dIter}{\def\psk@fractal@dIter{#1 }}
\psset[pst-fractal]{cx=0,cy=0,dIter=1}
\define@key[psset]{pst-fractal}{maxIter}{\pst@checknum{#1}\pst@fractal@maxIter}
\define@key[psset]{pst-fractal}{maxRadius}{\pst@checknum{#1}\pst@fractal@maxRadius}
\psset[pst-fractal]{maxIter=255,maxRadius=100}
\define@key[psset]{pst-fractal}{plotpoints}{\pst@checknum{#1}\pst@fractal@plotpoints}
\psset[pst-fractal]{plotpoints=2000}
%
\def\psfractal{\pst@object{psfractal}}
\def\psfractal@i{\@ifnextchar({\psfractal@ii}{\psfractal@ii(-1,-1)}}%
\def\psfractal@ii(#1){\@ifnextchar({\psfractal@iii(#1)}{\psfractal@iii(#1)(1,1)}}% 
\def\psfractal@iii(#1)(#2){%
  \begin@SpecialObj
  \psset{unit=1pt}
  \pst@getcoor{#1}\pst@temp@A
  \pst@getcoor{#2}\pst@temp@B
  \pspicture(\psk@fractal@xWidth,\psk@fractal@yWidth)%
  \addto@pscode{
    \pst@temp@A /MinY ED /MinX ED
    \pst@temp@B /MaxY ED /MaxX ED
    /MaxXPixel \pst@number\psk@fractal@xWidth def
    /MaxYPixel \pst@number\psk@fractal@yWidth def
    /PixelDicke 0.5 def
    /cx \psk@fractal@cx def
    /cy \psk@fractal@cy def 
    /totMaxIter \pst@fractal@maxIter\space \psk@fractal@dIter\space mul def
%
    /DX MaxX MinX sub def
    /DY MaxY MinY sub def
    /dx DX MaxXPixel div def
    /dy DY MaxYPixel div def
%
    /convertX { MinX sub DX sub dx div } def % user -> pt
    /convertY { MinY sub dy div } def        % user -> pt
    /convertXY { convertY exch convertX exch } def
%
    /putPixel {%  x y auf dem Stack in Benutzerkoordinaten
      convertXY
      PixelDicke 0 360 arc fill 
    } def
%
    MinX dx MaxX {
      \ifx\pst@fractal@type\pst@fractal@Julia /x exch def \else /cx exch def /x 0.0 def \fi
      MinY dy MaxY {
        \ifx\pst@fractal@type\pst@fractal@Julia /y exch def \else /cy exch def /y 0.0 def \fi
	/iter 0 def
	/zx x def
	/zy y def
	/plot true def
	totMaxIter cvi {
	    zx dup mul zy dup mul add \pst@fractal@maxRadius\space 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@fractal@dIter add def
	    } ifelse
	} repeat
	plot{ 
	  \pst@usecolor\pst@fractal@baseColor 
	  x y putPixel
	}{  iter 400 add tx@addDict begin wavelengthToRGB 
	    Red Green Blue setrgbcolor end
            \ifx\pst@fractal@type\pst@fractal@Julia x y \else cx cy \fi
	    putPixel stroke
	}ifelse		% Plot point if point is in set
    } for
  } for
  }% end add@pscode
  \endpspicture% end box
  \end@SpecialObj% 
  \ignorespaces}
%
\def\psSier{\pst@object{psSier}}
\def\psSier@i(#1)(#2)(#3){{%
  \pst@getcoor{#1}\pst@temp@A
  \pst@getcoor{#2}\pst@temp@B
  \pst@getcoor{#3}\pst@temp@C
  \begin@SpecialObj%
  \addto@pscode{
    /Coor [ \pst@temp@A 
            \pst@temp@B 
	    \pst@temp@C ] def
    /Sx 0 def /Sy 0 def
    /putPixel {	0.5 0 360 arc stroke } def % x y on stack
    /newPosition {			% point # on stack
	Coor 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 putPixel 
    } def
    /drawFrame {
	Coor aload pop
	newpath
	moveto
	nCoor 1 sub { lineto } repeat % n-1 times
	gsave 0.9 setgray fill grestore 
	\pst@usecolor\pslinecolor
	closepath
	stroke 
    } def
    /nCoor Coor length 2 div 0.5 add cvi def % # of dots
    drawFrame
    \pst@fractal@plotpoints\space cvi {
	rand nCoor mod 
	dup add newPosition   
    } repeat
  }% end add@pscode
  \end@SpecialObj%
}}

%
\catcode`\@=\PstAtCode\relax
%
%% END: pst-fractal.tex
\endinput