diff --git a/tikz/pi/Makefile b/tikz/pi/Makefile new file mode 100644 index 0000000..48fdc19 --- /dev/null +++ b/tikz/pi/Makefile @@ -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 diff --git a/tikz/pi/README.md b/tikz/pi/README.md new file mode 100644 index 0000000..4f54bd4 --- /dev/null +++ b/tikz/pi/README.md @@ -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 \ No newline at end of file diff --git a/tikz/pi/create.py b/tikz/pi/create.py new file mode 100644 index 0000000..a969585 --- /dev/null +++ b/tikz/pi/create.py @@ -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) diff --git a/tikz/pi/pi.png b/tikz/pi/pi.png new file mode 100644 index 0000000..6a4f679 Binary files /dev/null and b/tikz/pi/pi.png differ diff --git a/tikz/pi/pi.tex b/tikz/pi/pi.tex new file mode 100644 index 0000000..7825171 --- /dev/null +++ b/tikz/pi/pi.tex @@ -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}