Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




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


ActionScript Code:
// Phyllotaxy - Jim Bumgardner// Arranging movies in a sunflower-like (logarithmic/fibonacci) patternvar m = 120; // number of sprites to place in the circlevar w = 140; // radius of circle to fill (movie is 300 pixels wide)var phi = (Math.sqrt(5)+1)/2-1; // the golden ratiovar ga =  phi*2*Math.PI;    // the golden angle - used for phyllotaxis on many plantsfor (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;}



KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 02-12-2004, 06:30 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

    Copyright © 2005-08 www.BigResource.com, All rights reserved