Example 8: Basic Phyllotaxy Spiral
// Processing.js example by Jim Bumgardner
size(400,400);
smooth();
ellipseMode(RADIUS);
background(255);
fill(0);
int nbr_circles = 200;
float phi = (sqrt(5)+1)/2 - 1; // golden ratio
float golden_angle = phi * TWO_PI; // golden angle
float lg_rad = width * .45;
float sm_rad = 2;
float cx = width/2;
float cy = height/2;
for (int i = 1; i <= nbr_circles; ++i) {
float ratio = i/(float)nbr_circles;
float angle = i*golden_angle;
float spiral_rad = ratio * lg_rad;
float x = cx + cos(angle) * spiral_rad;
float y = cy + sin(angle) * spiral_rad;
ellipse(x, y, sm_rad, sm_rad);
}