mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-19 11:38:05 +02:00
Added Stern-Brocot-Tree
This commit is contained in:
parent
e0923f1d09
commit
23569bea72
4 changed files with 94 additions and 0 deletions
35
tikz/stern-brocot-tree/Makefile
Normal file
35
tikz/stern-brocot-tree/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
SOURCE = stern-brocot-tree
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 1024
|
||||
|
||||
make:
|
||||
pdflatex $(SOURCE).tex -output-format=pdf
|
||||
make clean
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
|
||||
|
||||
gif:
|
||||
pdfcrop $(SOURCE).pdf
|
||||
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
|
||||
make clean
|
||||
|
||||
png:
|
||||
make
|
||||
make svg
|
||||
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
|
||||
|
||||
transparentGif:
|
||||
convert $(SOURCE).pdf -transparent white result.gif
|
||||
make clean
|
||||
|
||||
svg:
|
||||
make
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE).svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
|
||||
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
|
||||
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
|
||||
rm $(SOURCE)2.svg
|
11
tikz/stern-brocot-tree/Readme.md
Normal file
11
tikz/stern-brocot-tree/Readme.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Compiled example
|
||||
----------------
|
||||

|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
Thanks to [Qrrbrbirlbel](http://tex.stackexchange.com/users/16595/qrrbrbirlbel)
|
||||
on [tex.stackexchange](http://tex.stackexchange.com/a/120605/5645)
|
||||
for this amazing work!
|
BIN
tikz/stern-brocot-tree/stern-brocot-tree.png
Normal file
BIN
tikz/stern-brocot-tree/stern-brocot-tree.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
48
tikz/stern-brocot-tree/stern-brocot-tree.tex
Normal file
48
tikz/stern-brocot-tree/stern-brocot-tree.tex
Normal file
|
@ -0,0 +1,48 @@
|
|||
\documentclass[tikz]{standalone}
|
||||
\usepackage{forest}
|
||||
\makeatletter
|
||||
\pgfmathdeclarefunction{strrepeat}{2}{%
|
||||
\begingroup
|
||||
\pgfmathint{#2}\pgfmath@count\pgfmathresult
|
||||
\let\pgfmathresult\pgfutil@empty
|
||||
\pgfutil@loop
|
||||
\ifnum\pgfmath@count>0\relax
|
||||
\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult#1}%
|
||||
\advance\pgfmath@count-1\relax
|
||||
\pgfutil@repeat
|
||||
\pgfmath@smuggleone\pgfmathresult
|
||||
\endgroup}
|
||||
\makeatother
|
||||
\tikzset{
|
||||
Stern Brocot at/.style={at/.pgfmath={
|
||||
strcat("([rotate around=180:(!", strrepeat("#1",\SBLevel),")] !",
|
||||
strrepeat("#1",\SBLevel-1),"2)")}},
|
||||
Stern Brocot at*/.style n args={3}{
|
||||
at/.pgfmath={strcat("(!",strrepeat("#1",#2),"-| SB@#3)")},
|
||||
append after command/.expanded={\ifnum#2<\SBLevel(\noexpand\tikzlastnode)
|
||||
edge[densely dotted] (SB@#3@\the\numexpr\SBLLoop+1\relax)\fi}}}
|
||||
\begin{document}
|
||||
\begin{forest}
|
||||
Stern Brocot*/.style n args={2}{
|
||||
content=$\frac{#1}{#2}$,
|
||||
edge=densely dotted,
|
||||
if={level()<\SBLevel}{append={[,Stern Brocot*={#1}{#2}]}}{}},
|
||||
Stern Brocot/.style n args={5}{
|
||||
/utils/exec=\edef\SBLevel{#5},@Stern Brocot={#1}{#2}{#3}{#4}},
|
||||
@Stern Brocot/.style n args={4}{
|
||||
/utils/exec=\edef\SBTop{\number\numexpr#1+#3\relax}%
|
||||
\edef\SBBottom{\number\numexpr#2+#4\relax},
|
||||
content/.expanded=$\frac{\SBTop}{\SBBottom}$,
|
||||
if/.expanded={level()<\SBLevel}{% true
|
||||
append={[,@Stern Brocot={#1}{#2}{\SBTop}{\SBBottom}]},
|
||||
append={[,Stern Brocot*={\SBTop}{\SBBottom}]},
|
||||
append={[,@Stern Brocot={\SBTop}{\SBBottom}{#3}{#4}]}
|
||||
}{}}% false (empty)
|
||||
[,Stern Brocot={0}{1}{1}{0}{4}]
|
||||
%
|
||||
\coordinate[Stern Brocot at=1] (SB@left) coordinate[Stern Brocot at=3] (SB@right);
|
||||
\foreach \SBLLoop in {\SBLevel, ..., 0}
|
||||
\path node[Stern Brocot at*={1}{\SBLLoop}{left}] (SB@left@\SBLLoop) {$\frac01$}
|
||||
node[Stern Brocot at*={3}{\SBLLoop}{right}] (SB@right@\SBLLoop) {$\frac10$};
|
||||
\end{forest}
|
||||
\end{document}
|
Loading…
Add table
Add a link
Reference in a new issue