# Fun with PI, E and Phi

I thought this bit of code was pretty interesting - it is used to set up my “light organ” movie (see my previous post) to arrange the spots in a pattern resembling the seeds on a sunflower.

It’s one of the few times where I’ve actually needed to use PI, E, and Phi (the golden ratio) in the same algorithm. So many magic numbers, so little time…

• Jim
``````
// Phyllotaxy - Jim Bumgardner
// Arranging movies in a sunflower-like (logarithmic/fibonacci) pattern

var m = 120; // number of sprites to place in the circle
var w = 140; // radius of circle to fill (movie is 300 pixels wide)

var phi = (Math.sqrt(5)+1)/2-1;	// the golden ratio
var ga =  phi*2*Math.PI;	// the golden angle - used for phyllotaxis on many plants
for (var i = 1; i <= m; ++i)
{
var a = i*ga;				// angle of phyllotaxis
var d = Math.log(1+i*(Math.E-1)/m);	// logarithmic distance to edge of movie (0-1)
var mc = cont.createEmptyMovieClip("sprite_"+i, i-1);
mc._x = Math.sin(a) * d*w;
mc._y = Math.cos(a) * d*w;
mc.a = a;  // store polar coordinates for animation-reference
mc.d = d;
mc.n = i;
}

``````