summaryrefslogtreecommitdiff
path: root/ulam-triangular.tex
diff options
context:
space:
mode:
Diffstat (limited to 'ulam-triangular.tex')
-rw-r--r--ulam-triangular.tex76
1 files changed, 76 insertions, 0 deletions
diff --git a/ulam-triangular.tex b/ulam-triangular.tex
new file mode 100644
index 0000000..8e4e0e1
--- /dev/null
+++ b/ulam-triangular.tex
@@ -0,0 +1,76 @@
+ \documentclass[border=10cm]{standalone}
+
+ \usepackage{pgf}
+
+ \newcount\ulami
+ \newcount\ulamj
+ \newcount\ulamlen
+
+ \newcount\ulamx
+ \newcount\ulamy
+ \newcount\ulamdx
+ \newcount\ulamdy
+
+ \ulami=1 %
+ \ulamj=0 %
+ \ulamlen=1 %
+ \ulamdx=-1 %
+ \ulamdy=1 %
+ \ulamx=0 %
+ \ulamy=0 %
+
+ \def\ulamplot#1{%
+ \advance\ulami by 1 %
+ \advance\ulamj by 1 %
+
+ \advance\ulamx by \the\ulamdx %
+ \advance\ulamy by \the\ulamdy %
+
+ \pgfpathmoveto{\pgfpoint{\the\ulamx cm}{\the\ulamy cm}}
+
+ \pgfmathparse{isprime(\the\ulami)}
+ \let\r=\pgfmathresult
+ \ifnum\r=1
+ \pgfpathcircle{\pgfpoint{\the\ulamx cm}{\the\ulamy cm}}{5pt}
+ \fi
+
+ \ifnum\ulamj=\the\ulamlen %
+ \advance\ulamlen by 1 %
+ \ulamj=0 %
+ \ifnum\ulamdx=1 %
+ \ulamdx=-1 %
+ \ulamdy=1 %
+ \else%
+ \ifnum\ulamdx=-1 %
+ \ulamdx=0 %
+ \ulamdy=-1 %
+ \else%
+ \ulamdx=1 %
+ \ulamdy=0 %
+ \fi
+ \fi
+ \fi
+
+ \ifnum#1>0 %
+ \advance#1 by -1 %
+ \ulamplot{#1}%
+ \fi
+ }
+
+ \begin{document}
+
+ \begin{pgfpicture}
+ \pgfmathsetmacro{\x}{cos(60)}
+ \pgfmathsetmacro{\y}{sin(60)}
+ \pgftransformcm{1}{0}{\x}{\y}{\pgfpointorigin}
+
+ \pgfpathmoveto{\pgfpointorigin}
+ \color{blue}
+ \newcount\ulamn
+ \ulamn=400
+ \ulamplot{\ulamn}
+ \pgfusepath{stroke,fill}
+ \end{pgfpicture}
+
+ \end{document}
+