浏览代码

tikz/pi: Add

Martin Thoma 8 年之前
父节点
当前提交
2a30558690
共有 5 个文件被更改,包括 108 次插入0 次删除
  1. 31 0
      tikz/pi/Makefile
  2. 10 0
      tikz/pi/README.md
  3. 36 0
      tikz/pi/create.py
  4. 二进制
      tikz/pi/pi.png
  5. 31 0
      tikz/pi/pi.tex

+ 31 - 0
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

+ 10 - 0
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

+ 36 - 0
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)

二进制
tikz/pi/pi.png


+ 31 - 0
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}