Fractal Plant

deligut's icon

I was trying to replicate in Javascript the Fractal Plant example provided by odewahn1 in the O'Reilly forum, originally done in processing. Obviously with little success. Seems the recursion is not working as expected. Any idea how to modify it?

3827.train7.js
js
timtation's icon

there is 'var' missing in line 54 in function fractal():

for (var i = 0; i < branches; i++)

timtation's icon

edited the color and position of the tree...

3875.train6.js
js
deligut's icon

Excellent. Thanks a lot for your help.
Regards
Tim

ujifnotfound's icon

Great !!!
Thank you for the lesson

I am absolutely new in JavaScript so i have primitive questions:
Is it possible to create inlets for dynamic change of parameters such as
branches, depth, minAngle etc
I guess it should be smth like:

function branches(v)
{
    branches = v;
}
and then massage box to the JSobject ( branches $1 ) ......but this doesn`t work

And another question if it possible to "grow" this tree from line to line?

Ps. i know one good answer: "go and learn JS!" )) ..... but anyway

timtation's icon

yes, i think its possible. try
inlets = 0;
if (jsarguments.length >= 2)
    inlets = jsarguments[1];
if (!inlets)
    inlets = 1; // default value
function branches(v){
inlets = v;
branches = v;
paint();
}

ujifnotfound's icon

Thnx.
I`ll try to understand it...