Recursive Fractals in LSL

I’ve been wondering for a while if it was possible to script the building of a fractal object.  I know with prim limitations it would be totally useless and very limited but still I wanted to try.

The object I thought I’d  have a go at was a fractal tree. If you want to see some examples of good fractal trees, just browse through Google images one day.  The basic algorithm is fairly straight forward:

  • Draw your trunk
  • Calculate the angles for your branches
  • treat each branch as if its a trunk and do it all again

This is often implemented using a recursive algorithm, which means that once you have a “draw trunk and calculate branches” function, you just keep calling that same function from within itself treating each new branch as if it was a trunk of a miniature tree.

However, LSL is an event driven language and lots of the things I wanted to do (rez prims, link them, shape them, etc) will use those events which will mean jumping out of functions and not returning, thus breaking the recursive nature of the algorithm.

Well my solution to that was to have two scripts – one running the recursive algorithm and one waiting for instructions on what to rez.  This worked fairly well – however to be sure, I built in a few extra delays just to give things time to rez, etc.  So all in all, my final algorithm was something like this:

  • Send a message to the rezzing script to rez the trunk
  • Wait for a short time to give it a chance to rez
  • Calculate the angles for your branches
  • treat each branch as if its a trunk and do it all again

Once I had a simple 2D tree being generated I thought I’d go for a 3D one, so decide that when calculating angles for branches, I’d use a Z rotation of 0+/- 15 degrees, 120 +- 15 degrees and 240 +/- 15 degrees.  This is applied to each branch in turn and generates a reasonable effect.

I did wonder about immediately unlinking  each branch once rezzed and setting it to temporary, but the garbage collector is a bit too quick for me. I was getting branches disappearing before the full tree was built … so full prims it will have to be.

I have a 3- branch, 4-level deep tree rezzing (it takes a good few minutes) and the final prim count is 121 prims.  As I said totally impractical, but it was interesting to see that it can be done.  And somewhat hypnotic (until it gets dull) watching it build itself.

Feel free to see for yourself here – www.youtube.com/watch?v=WqJZZ48cTAc (but don’t ask me for those 6 minutes of your life back ;))

I am not planning on releasing these scripts atm … I think there is too much potential for getting things wrong and doing some damage. But if you have an interesting idea for using recursive prim rezzing (with safeguards and limits naturally) or an interesting fractal algorithm you’d like to play with, give me a shout.

Also, if you’ve seen anything interesting done in SL with recursive algorithms or fractals, again I’d really like to see it – do please pass on a landmark to me in-world.

Kimm

Advertisements

~ by kimmpaulino on January 8, 2012.

2 Responses to “Recursive Fractals in LSL”

  1. I always suspected you were intelligent; I love when I find out I’m right. *smile

  2. Ahem … well, one might argue that the intelligent thing to do is not spend one’s time designing impractical frivolities!

    :)

    K.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: