2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

tikz/pi: Add

This commit is contained in:
Martin Thoma 2017-05-03 09:30:32 +02:00
parent 7f1684d2c1
commit 2a30558690
5 changed files with 108 additions and 0 deletions

31
tikz/pi/Makefile Normal file
View file

@ -0,0 +1,31 @@
SOURCE = pi
DELAY = 80
DENSITY = 300
WIDTH = 512
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:
#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

10
tikz/pi/README.md Normal file
View file

@ -0,0 +1,10 @@
Compiled example
----------------
![Example](pi.png)
Credits
-------
Cristian Ilies Vasile made this kind of image first:
https://img.washingtonpost.com/wp-apps/imrs.php?src=https%3A%2F%2Fimg.washingtonpost.com%2Fblogs%2Fwonkblog%2Ffiles%2F2015%2F03%2Flinks-pi-cristian.png&w=1484

36
tikz/pi/create.py Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
"""Create a data.csv file."""
import csv
try:
# import version included with old SymPy
from sympy.mpmath import mp
except ImportError:
# import newer version
from mpmath import mp
mp.dps = 1000 # set number of digits
pi = mp.pi
print(pi)
# Split pi in groups of two digits
pi = str(pi)[2:]
split_pi = []
for i in range(0, len(pi), 2):
part = pi[i:i + 2]
if len(part) != 2:
continue
split_pi.append(part)
# Representation of pi
data = [("x", "y", "color")] # header
for e1, e2 in zip(split_pi, split_pi[1:]):
tuple_date = (int(e1), int(e2), "c{}".format(int(int(e1) / 10)))
data.append(tuple_date)
# Write data to csv
with open('data.csv', 'w') as fp:
writer = csv.writer(fp, delimiter=',')
writer.writerows(data)

BIN
tikz/pi/pi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

31
tikz/pi/pi.tex Normal file
View file

@ -0,0 +1,31 @@
\documentclass{standalone}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}
\usepackage{xcolor}
\definecolor{c0}{HTML}{5A311D}
\definecolor{c1}{HTML}{E18B4E}
\definecolor{c2}{HTML}{4A1776}
\definecolor{c3}{HTML}{C966DA}
\definecolor{c4}{HTML}{04676C}
\definecolor{c5}{HTML}{0CE7E1}
\definecolor{c6}{HTML}{004692}
\definecolor{c7}{HTML}{0082FF}
\definecolor{c8}{HTML}{355128}
\definecolor{c9}{HTML}{DF1C24}
\begin{document}
\newcommand{\distance}{6}
\begin{tikzpicture}
\foreach \a in {0,1,...,100}{
\node[draw=none](\a) at (\a/100*360: \distance) {} ;
}
\csvreader[ head to column names]%
{data.csv}{}{%
\path (\x) edge [bend right, \color] (\y);
}
\end{tikzpicture}
\end{document}