Kamel Ghabte · Course · Free

Phyllotaxis: Golden Angle

Draw sunflower spirals with the golden angle in p5.js.

The concept

Phyllotaxis (leaf arrangement) follows the golden angle: 137.508°. Placing points at angle_n = n × 137.508° and radius_n = c × √n produces the Fibonacci spiral seen in sunflowers, pine cones and pineapples. It's nature's optimal spacing.

The code

// Phyllotaxis (sunflower)
function setup() { createCanvas(400, 280); background(11,15,20); noLoop();
  translate(width/2,height/2);
  let c = 5, phi = 137.508;
  for (let n=0; n<500; n++) {
    let a = n * radians(phi);
    let r = c * sqrt(n);
    let sz = map(n, 0, 500, 6, 2);
    noStroke(); fill(55, 227, 195, map(n,0,500,220,60));
    ellipse(cos(a)*r, sin(a)*r, sz, sz);
  }
}

Going further

Explore other free courses on the Learn page, or book a call to discuss your project.

Want to go further?

Book a discovery call →