summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/tufte-latex/graphics/hilbertrecursive.tex
blob: dc30ec12893a812f80ed7afad5371049cf4a24f0 (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
% Draw Hilbert curves. 
% Credits: Based on code by Marc van Dongen
% See: http://www.fauskes.net/pgftikzexamples/hilbert-curve/
\title{Hilbert Curves}
\author{}
\date{}

\documentclass{tufte-handout}

\usepackage{tikz}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{positioning}

\begin{document}

\newdimen\HilbertLastX
\newdimen\HilbertLastY
\newcounter{HilbertOrder}

\def\DrawToNext#1#2{%
   \advance \HilbertLastX by #1
   \advance \HilbertLastY by #2
   \pgfpathlineto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   % Alternative implementation using plot streams:
   % \pgfplotstreampoint{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
}

% \Hilbert[right_x,right_y,left_x,left_x,up_x,up_y,down_x,down_y]
\def\Hilbert[#1,#2,#3,#4,#5,#6,#7,#8] {
  \ifnum\value{HilbertOrder} > 0%
     \addtocounter{HilbertOrder}{-1}
     \Hilbert[#5,#6,#7,#8,#1,#2,#3,#4]
     \DrawToNext {#1} {#2}
     \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]
     \DrawToNext {#5} {#6}
     \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]
     \DrawToNext {#3} {#4}
     \Hilbert[#7,#8,#5,#6,#3,#4,#1,#2]
     \addtocounter{HilbertOrder}{1}
  \fi
}


% \hilbert((x,y),order)
\def\hilbert((#1,#2),#3){%
   \advance \HilbertLastX by #1
   \advance \HilbertLastY by #2
   \pgfpathmoveto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   % Alternative implementation using plot streams:
   % \pgfplothandlerlineto
   % \pgfplotstreamstart
   % \pgfplotstreampoint{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   \setcounter{HilbertOrder}{#3}
   \Hilbert[1mm,0mm,-1mm,0mm,0mm,1mm,0mm,-1mm]
   \pgfusepath{stroke}%
}

\def\scalefac{1}
\maketitle

\begin{figure}[h!]
\begin{tikzpicture}[node distance=0cm,every path/.style={thin}]
    \node[label={above:$n=1$}] (n1) {\tikz[scale=\scalefac*18] \hilbert((0mm,0mm),1);};
    \node[label={above:$n=2$},right=of n1] (n2) {\tikz[scale=\scalefac*6] \hilbert((0mm,0mm),2);};
    \node[label={above:$n=3$},right=of n2] (n3) {\tikz[scale=\scalefac*2.6] \hilbert((0mm,0mm),3);};
    \node[label={above:$n=4$},right=of n3] (n4) {\tikz[scale=\scalefac*1.2] \hilbert((0mm,0mm),4);};
    \node[label={above:$n=5$},right=of n4] (n5) {\tikz[scale=\scalefac*0.58] \hilbert((0mm,0mm),5);};
\end{tikzpicture}
\end{figure}
\end{document}