I'm trying to create a command to draw the Sierpinski Triangle to arbitrary levels of precision for me (I need it for presentations on my research). After some fiddling, I got the following \SGlevel command to almost work:
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[margin = 1in]{geometry}
\usepackage{parskip}
\usepackage{verbatim}
\usepackage{ifthen}
\usepackage{fp}
\newcommand{\SGlevel}[3]{
\def \r {0.8660254}
\ifthenelse{\equal{#1}{0}}{
\draw (#2,#3) -- (#2+.5,#3+\r) -- (#2+1,#3) -- cycle;
}{
\pgfmathparse{int(#1-1)}
\let\next\pgfmathresult
\pgfmathparse{#2+2^(#1-2)}
\let\twox\pgfmathresult
\pgfmathparse{#3+2^(#1-1)*\r}
\let\twoy\pgfmathresult
\pgfmathparse{#2+2^(#1-1)}
\let\threex\pgfmathresult
\SGlevel{\next}{#2}{#3}
\SGlevel{\next}{\twox}{\twoy}
\SGlevel{\next}{\threex}{#3}
}
}
\usetikzlibrary{arrows, shapes}
\begin{document}
\begin{figure}[hhhh]
\centering
\begin{tikzpicture}[point/.style={draw,shape=circle,inner sep = 0mm,minimum size = 1mm},scale = 1,>=stealth',auto]
\SGlevel{0}{0}{0}
\end{tikzpicture}
\end{figure}
\end{document}
Thanks