Title: Best way to make these tree iterations? Arrays? location marikers? nested etc Post by: Mrz00m on October 01, 2012, 03:39:05 PM Hi there, i am learning fractals in javascript and Unity3d.
I am stuck on this task: rotate a root object 3 times, add 10 cubes in a line to the root object, mark the 10th cube as a new root object, rotate the new root object 3 times, add 30 cubes to teh new root object same as before. I am very stuck on this task: how to i mark the 3 new cubes at the end of each branch as a sub root, seeing as they wont have existed before the rotate function was made in the first place? Should i make an array with "newroot [1,2,3]" where do i place the nested elements of the function? here is the code for the 3 branches.: Code:
where do i place the rotate function? Title: Re: Best way to make these tree iterations? Arrays? location marikers? nested etc Post by: cKleinhuis on October 01, 2012, 04:54:54 PM think easy, you have one basic rule which would be simple recursive ?
func(obj,angle,depth){ obj.rotate as you like via angle newelements[]=create new objects -> e.g. depth*10 -> return as array list call func(newelements[lastelement],angle,depth+1) -> recursive call } if you want a 3 branch to be created by this, you could call the function three times in each step, for example: call func(newelements[lastelement],angle,depth+1) call func(newelements[lastelement-1],angle,depth+1) call func(newelements[lastelement-2],angle,depth+1) Title: Re: Best way to make these tree iterations? Arrays? location marikers? nested etc Post by: Mrz00m on October 01, 2012, 10:56:48 PM Thanks so much!
I was convinced that recursion meant that i could program a loop within a loop and magically use the right words so it would call back on itself in the intended form. actually i have to at least do the over routine and prior to figuring out how it would work in an ad infinitum loop. in 2 minutes of reading your answer it was rolling. Title: Re: Best way to make these tree iterations? Arrays? location marikers? nested etc Post by: cKleinhuis on October 01, 2012, 11:03:21 PM great that it worked, glad to help ;) this is a fantastic starter into branching visualisation, you can even make the branches count random, that whould produce wild structures have fun with it! |