summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/lisp-on-tex/examples/fpnummodule-mandelbrot.tex
blob: f0cf68798b5f7fb549c3542fc2a8deea9517566b (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
\documentclass{article}
\usepackage[pdftex,a3paper,margin=1pt,landscape]{geometry}
\newcount\mlength
\newcount\cstate
\newdimen\mandelunit
\mandelunit=0.5pt

\def\w{%
  \ifnum\cstate=1 \global\advance\mlength1
  \else \vrule width \mlength\mandelunit height \mandelunit depth 0pt \global\mlength1 \fi
  \global\cstate1}
\def\b{%
  \ifnum\cstate=-1 \global\advance\mlength1
  \else \hspace*{\mlength\mandelunit}\global\mlength1 \fi
  \global\cstate-1}
\def\r{%
  \ifnum\cstate=1\hspace*{\mlength\mandelunit}\else\vrule width \mlength\mandelunit height \mandelunit depth 0pt \fi
  \global\cstate0 \global\mlength0}

\usepackage{lisp-on-tex}
\usepackage{lisp-mod-fpnum}
\lispinterp{%
  (\define \maxloop :20)
  (\define \scale +{fpnum::0.002})
  (\define \isMandell
    (\lambda (\a \b \k \x \y)
      (\lispif (\< \maxloop \k) /t
        (\lispif (\fplt +{fpnum::4.0} (\fpplus (\fpmul \x \x) (\fpmul \y \y)))
          /f
          (\isMandell \a \b (\+ \k :1)
            (\fpplus \a (\fpmul \x \x) (\fpminus (\fpmul \y \y)))
            (\fpplus \b (\fpmul +{fpnum::2.0} \x \y)))))))
  (\define \drawMandell (\lambda (\a \b)
    (\begin
      (\lispif (\isMandell \a \b :0 +{fpnum::0} +{fpnum::0})
        (\texprint '\b') (\texprint '\w'))
      (\immediatewrite))))
  (\define \loopMandell (\lambda (\a \b)
    (\lispif (\fplt \b +{fpnum::-1.0}) ()
      (\begin
        (\drawMandell \a \b)
        (\lispif  (\fplt +{fpnum::0.5} \a)
          (\begin
            (\texprint '\r\\')
            (\immediatewrite)
            (\loopMandell +{fpnum::-1.5} (\fpminus \b \scale)))
          (\loopMandell (\fpplus \a \scale) \b))))))
}

\begin{document}
	\thispagestyle{empty}
  \noindent
  \leavevmode\baselineskip=\mandelunit
  \lispinterp{(\loopMandell +{fpnum::-1.5} +{fpnum::1.0})}
\end{document}