Deborah R. Fowler

Updated on March 22  2013

back to MEL Resources

Phyllotactic Pattern - my code in MEL below


// Phyllotactic Pattern Generation
//
// Author: Deborah R. Fowler
//  Date: March 22, 2013
//
// This is the phyllotactic pattern as described by Vogel in Biomathematics 1979, and used in The Alorithmic Beauty of Plants in 1990
//
//  Inputs: GUI Mel interface for amount, size, spread and angle
//  Output: Pattern of spheres on a disc optimally packed
//

if ( `window -exists myWindow` ) deleteUI myWindow;
    window -title "Spiral Phyllotaxis" -widthHeight 500 200 myWindow;
    columnLayout -adj on;
    intSliderGrp -label "amount" -min 1 -max 5000 -value 100 -field true -changeCommand "phyllotaxis" total;
    floatSliderGrp -label "size" -min 1 -max 60 -value 2 -field true -changeCommand "phyllotaxis" size;
    floatSliderGrp -label "size" -min 1 -max 20 -value 2 -field true -changeCommand "phyllotaxis" spread;
    floatSliderGrp -label "angle" -min 0 -max 360 -value 137.508 -pre 3 -field true -changeCommand "phyllotaxis" angle;
showWindow myWindow;


proc phyllotaxis()
{
    // Delete any existing geometry - this is intended as a stand alone demo
    select -all;
    delete;

    // Get the values from the GUI interface
    int $total = `intSliderGrp -q -value total`;

    float $size = `floatSliderGrp -q -value size`;
    float $c = `floatSliderGrp -q -value spread`;
    float $angle = `floatSliderGrp -q -value angle`;

    // Calculate the positions in the spiral phyllotactic pattern
    float $phi;
    float $r;
    float $theta;
    float $x, $y, $xcenter, $ycenter;
    float $PI = 3.14159265359;

    $phi = $angle * ( $PI/180.0 );
    $xcenter = 0.0;
    $ycenter = 0.0;
   
    for ( $n = 0; $n  <  $total;  $n++ )
    {
            $r = $c * sqrt( $n );
            $theta = $n * $phi;
            $x = $r * cos( $theta ) + $xcenter;
            $y = $r * sin( $theta ) + $ycenter;

            // draw a sphere or whatever object you'd like at this position
            sphere -r $size -p $x $y 0;
    }

}


phyllotaxis();



Aside: An interesting comment about accuracy. This formula is very sensitive to the exact angle. With an angle of 137.5 and 5000 total spheres the pattern starts to fall apart at the edges. See the results below with Python on the left and Mel on the right. The pattern starts to fall apart at the edges with the decreased accuracy. During the Algorithmic Beauty of Plants time we were only able to draw on the order of hundreds of spheres in a reasonable time so this was not an issue. I first discovered this when I was playing with this pattern in Houdini in 2008. It is fun to see these now generate so quickly on screen and how important the angle is to Vogels formula.

Python with angle 137.508, 5000 dots
Maya with angle 137.5 rather than 137.508 remember to set the slider's precision with the flag -pre 3 if needed. (Code above is green result).