File: mandel.tex

package info (click to toggle)
texlive-extra 2014.20141024-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,016,484 kB
  • ctags: 21,582
  • sloc: perl: 140,144; python: 16,926; makefile: 12,969; sh: 9,285; ansic: 3,415; java: 3,090; csh: 2,987; xml: 1,050; lisp: 630; ruby: 487; lex: 358; tcl: 142; sed: 36; pascal: 25; cpp: 18; awk: 10; haskell: 5
file content (64 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download
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
\documentclass{article}
\usepackage[pdftex,a3paper,margin=1pt,landscape]{geometry}
\usepackage{perltex}
\newcount\mlength
\newcount\cstate
\newdimen\mandelunit
\mandelunit=0.5pt

\def\w{%
  \ifnum\cstate=1 \global\advance\mlength1
  \else\ifnum\cstate=-1 \vrule width \mlength\mandelunit height \mandelunit depth 0pt \global\mlength1 \fi\fi
  \global\cstate1}
\def\b{%
  \ifnum\cstate=-1 \global\advance\mlength1
  \else\ifnum\cstate=1 \hspace*{\mlength\mandelunit}\global\mlength1 \fi\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}

\perlnewcommand{\isMandel}[2]{
  my $maxloop=20;
  my $x = 0;
  my $y = 0;
  my $xx = 0;
  my $yy = 0;
  for(my $k=0; $k<=$maxloop; $k++){
    $xx = $x ** 2;
    $yy = $y ** 2;
    if($xx + $yy > 4.0) { return 0; }
    $y = 2*$x*$y + $_[1];
    $x = $xx - $yy + $_[0];
  }
  return 1;
}
\perlnewcommand{\loopMandel}{
  my $scale=0.002;
  my $ret = "";
  for(my $b=1.0; $b >=-1.0; $b-=$scale){
    $ret = $ret . "\\loopMandelInner{" . $b . "}\\r\\\\";
  }
  return $ret;
}
\perlnewcommand{\loopMandelInner}[1]{
  my $scale=0.002;
  my $ret = "";
  my $b = $_[0];
  for(my $a=-1.5; $a<=0.5; $a+=$scale){
    if(latex_isMandel($a, $b)){
      $ret .= "\\b";
    } else {
      $ret .= "\\w";
    }
  }
  return $ret;
}


\begin{document}
  \thispagestyle{empty}
  \noindent
  \leavevmode\baselineskip=\mandelunit
  \loopMandel
\end{document}