Thursday, May 1

Recursive Growth_01

It took me some time to understand how Recursion (link1, link2, thxs link3!) works, and to code a recursive version of the last script.
In the older version of the script, each element may only create one new element, so that one single path of growth is created. Yet, in the function below, elements are copied and moved as before, but each new element may trigger the creation of several new ones, meaning that the system grows in all directions, like a branching tree.

Since the recursive function has to be able to stop itself at some level of depth, I added an 'internal' generation counter G. Also, there is an internal element counter (n) that is necessary for the recursive algorithm to add elements in the right branch order of the growth tree.
However, in order to have all distributed elements stored in an array (and to be able to search for elements, like checking for occupied positions), there must be an “external” counter, in this case t, which counts the actual elements being added.


























































'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function functRecGrowth (n, t, arrVec, arrPoints, strVolume, arrFlakes, arrReloc, G)


Dim j

If G >= 20 Then Exit Function

For j = 0 To 5
ReDim Preserve arrVec(n)
ReDim Preserve arrFlakes(n)
ReDim Preserve arrPoints(t)
If (Rnd > 0.7) Then
arrVec(n) = PointAdd (arrVec(n-1), arrReloc(j))
arrPoints(t) = arrVec(n)
If functOccupied (arrPoints, t) = False And IsPointInSurface (strVolume, arrPoints(t))Then
arrFlakes(n) = CopyObject (arrFlakes(0), arrVec(0), arrVec(n))
t = t + 1
'Print ("t = " & t & ", n = " & n)
Call functRecGrowth (n+1, t, arrVec, arrPoints, strVolume, arrFlakes, arrReloc, G+1)
End If
End If
Next

End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


With a bunch of snowflakes (here abstracted),
the first experiments into fractal behaviour/
recursive division...







1 comment:

Anonymous said...

hab dich! lg aus london. moritz.