Hi,
I am trying to make a little animation using ilyas’ chaos fractal tree script, found at: http://www.kirupa.com/developer/actionscript/chaos_fractal.htm
What I am trying to do is have the function called from an empty clip (with start x and y parameters created with math.random, so that the ‘trees’ appear all over the stage one by one when someone clicks…)
Then I can duplicate the clip that calls the makeBranch function, and have each clip/tree fade out after a set time. I hope I’m explaining what I’m trying to do well enough - it may be that I’m trying to go about what I’m trying to do completely wrong?
Anyway,I’m having issues calling the function from the clip, it just isnt working (maybe a function scope issue? i’m not really sure…)
Below is the code from when before I was mucking with the idea of duplicated clips - just to give you a sense of what I’m trying to do. The problem with this is that its all occuring on the root -they all fade together, not separately, making it impossible to make new trees once the alpha hits 0. (which would be fine if i could create each tree in its own clip…) I figured it would be easy to just call the function from an mc, so that it would fade independently from other duplicated clips, that were duplicated when you clicked. Bah, nothing’s easy… =]
[AS]
//thx to Ilyas Usal for the fractals tutorial
function makeBranch(start_x, start_y, length, angle, size){
if (size > 0)
{
this.lineStyle(size, 0x009900, 100);
this.moveTo(start_x, start_y);
var end_x:Number = start_x + length * Math.cos(angle);
var end_y:Number = start_y + length * Math.sin(angle);
this.lineTo(end_x, end_y);
var sub_branch:Number = random(max_sub_branch) + 2;
var branch_length_dimin:Number = 0.500000 + Math.random() / 2;
var i:Number = 0;
while (i < sub_branch)
{
var newLength:Number = length * branch_length_dimin;
var newAngle:Number = angle + Math.random() * max_sub_angle - max_sub_angle / 2;
var newSize:Number = size - 1;
makeBranch(end_x, end_y, newLength, newAngle, newSize);
i++;
} // end while
} // end if
this.onEnterFrame = function(){
this._alpha -= 0.2;
if(this._alpha < 1){
this.clear();
}
}
} // End of the function
var max_sub_branch:Number = 3;
var max_sub_angle:Number = 1.884956;
var max_size:Number = 6;
var branch_length:Number = 50;
this.onMouseDown = function ()
{
makeBranch(Math.random()*710, Math.random()*385, branch_length, -1.570796, max_size);
}
[/AS]
Any help or suggestions would be greatly appreciated!
Thanks=]