# Fun with PI, E and Phi

**URL:** https://forum.kirupa.com/t/fun-with-pi-e-and-phi/101703
**Category:** Uncategorized
**Created:** [February 12, 2004, 10:30pm UTC](https://forum.kirupa.com/t/fun-with-pi-e-and-phi/101703 "2004-02-12T22:30:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jbum](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jbum/32/440_2.png) [@jbum](https://forum.kirupa.com/u/jbum)
#### Post date: [February 12, 2004, 10:30pm UTC](https://forum.kirupa.com/t/fun-with-pi-e-and-phi/101703/1 "2004-02-12T22:30:34Z")

</div>

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

```auto

// 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;
}

```
