Example 8: Basic Phyllotaxy Spiral

refresh(dc, width, height) // Sample code by Jim Bumgardner
{
  dc.clearRect(0,0,width,height);
  
  dc.fillStyle='#000';
  var nbr_circles = 200;
  
  var phi = (Math.sqrt(5)+1)/2 - 1;            // golden ratio
  var golden_angle = phi*2*Math.PI;            // golden angle
  var lg_rad = width * .45;
  
  var sm_rad = 2;
  var cx = width/2;
  var cy = height/2;
  
  for (var i = 1; i <= nbr_circles; ++i) {
    dc.beginPath();
    var ratio = i/nbr_circles;
    var angle = i*golden_angle;
    var spiral_rad = ratio * lg_rad;
    var x = cx + Math.cos(angle) * spiral_rad;
    var y = cy + Math.sin(angle) * spiral_rad;
    dc.arc(x, y, sm_rad, 0, 2*Math.PI, false);
    dc.fill();
  }
  
}