TikZ: trying to draw a phyllotaxy (sunflower pattern) and get short by computation limits

The problem in your code comes from the computation of the \angle, at the line

\pgfmathsetmacro{\angle} {\goldenAngle * \b}

When \b is greater than 28, the result this product becomes larger than 16384, which is the maximum allowed value. You should refactor your code to avoid computing such values.

One way to do this in this code is to compute the same angle modulo 360. Try the following:

\begin{tikzpicture}
\pgfmathsetmacro {\goldenRatio} {(1+sqrt(5))}
\foreach \b in {1,...,\nbrcircles}{
    \pgfmathsetmacro{\angle}{mod(\goldenRatio * \b,2)*180}
    \pgfmathsetmacro{\sradius}{\b / \nbrcircles * \outerradius / 10}
    \draw[] (\angle:\sradius) circle [radius=\dotradius] ;
}  
\end{tikzpicture}

You can see that we now multiply \b by only 1+sqrt(5), then use the modulo operation before the product with 180. This will give the same result as the previous code, but allow to much bigger values of \b. See for instance this rendering with \nbrcircles set to 1000:

1000 dots


\documentclass[tikz,border=2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin {tikzpicture}
\foreach \x in {0,...,1000}{
    \fill ({mod((1+sqrt(5))*\x,2)*180}:{0.1+sqrt(\x/pi)/2}) circle [radius=0.15];
}
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf