I want to draw Sierpinski's triangle in Pascal's triangle in tikz for 30 rows or more but my code only works for 13 rows.
\documentclass{article}
\usepackage{tikz}
\usepackage{pdfpages}
\begin{document}
\begin{center}
\newdimen\R
\R=.4cm
\newcommand\mycolor{white}
\newcommand\thik{\pgflinewidth}
\begin{tikzpicture}[line width=.8pt]
\foreach \k in {0,...,13}{
\begin{scope}[shift={(-60:{sqrt(3)*\R*\k})}]
\pgfmathtruncatemacro\ystart{13-\k}
\foreach \n in {0,...,\ystart}{
\pgfmathtruncatemacro\newn{\n+\k}
%binomila ceeficients
\pgfmathsetmacro{\value}{1};
\ifthenelse{\k>0}{
\foreach \b in {1,...,\k}{
\pgfmathtruncatemacro{\value}{\value*(\newn-\b+1)/\b)};
\global\let\value=\value
}
}{};
\pgfmathtruncatemacro{\rest}{mod(\value,2)};
\ifthenelse{\rest=0}{\def\mycolor{green}}{}
\begin{scope}[shift={(-120:{sqrt(3)*\R*\n})}]
\draw[top color=\mycolor!20,bottom color=\mycolor!60]
(30:\R) \foreach \x in {90,150,...,330} {
-- (\x:\R)}
--cycle (90:0) node {\tiny $\mathbf{\value}$};
\end{scope}
}
\end{scope}
}
\end{tikzpicture}
\end{center}
\end{document}
center
environement. But it requirespdfpages
, which doesn't seem to be required AFAIK. I have the feeling something is not right here ... and this shows up if you got to 30 but not with 13.\end{center}
, then it compiles.\pgfmathtruncatemacro{\value}{\value*(\newn-\b+1)/\b)};
TikZ uses TeX dimensions, and these registers can only hold values±16383.99999
. See e.g. the article \pgfmathsetmacro - dimension too large (biggest value allowed?)pgfplots
and thefpu
library.[tikz]{standalone}
class it does not work as well ... as I said, very weird