Sunflower pattern (Phyllotaxy)

This is an adaptation of a Processing.js example originally written by Jim Bumgardner.

His tutorial entitled "Circles, Spirals and Sunflowers" can be found here: http://krazydad.com/tutorials/circles_js/

Following code adapts Jim's example #10.

Credit also goes to TonioElGringo on stackexchange, for the help he provided here: http://tex.stackexchange.com/questions/192028/


phyllotaxy

Edit and compile if you like:

% Phyllotaxy
% Author: David Convent
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\def\nbrcircles {377}
\def\outerradius {30mm}
\def\deviation {.9}
\def\fudge {.62}
\newcounter{cumulArea}
\setcounter{cumulArea}{0}
\begin{document}
\begin{tikzpicture}[scale=.32]
\pgfmathsetmacro {\goldenRatio} {(1+sqrt(5))}
\pgfmathsetmacro {\meanArea}
{pow(\outerradius * 10 / \nbrcircles, 2) * pi}
\pgfmathsetmacro {\minArea} {\meanArea * (1 - \deviation)}
\pgfmathsetmacro {\midArea} {\meanArea * (1 + \deviation) - \minArea}
\foreach \b in {0,...,\nbrcircles}{
% mod() must be used in order to calculate the right angle.
% otherwise, when \b is greater than 28 the angle is greater
% than 16384 and an error is raised ('Dimension too large').
% -- thx Tonio for this one.
\pgfmathsetmacro{\angle}{mod(\goldenRatio * \b, 2) * 180}
\pgfmathsetmacro{\sratio}{\b / \nbrcircles}
\pgfmathsetmacro{\smArea}{\minArea + \sratio * \midArea}
\pgfmathsetmacro{\smRadius}{sqrt(\smArea / pi) / 2 * \fudge}
\addtocounter{cumulArea}{\smArea};
\pgfmathparse{sqrt(\value{cumulArea} / pi) / 2}
\fill[] (\angle:\pgfmathresult) circle [radius=\smRadius] ;
}
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Click to download: phyllotaxy.texphyllotaxy.pdf
Open in Overleaf: phyllotaxy.tex