Diffusion Limited Aggregation Script

Hi All,

im trying to do a simple DLA script, I found this code online and modified it to try to have it work with grasshopper, but I dont know how to keep going anymore… how Can i generate points and have them stick? After I check the states? am i doing things wrong? are there other approaches? i just want to achieve something like this I cant seem to find a solution, your help will be Much appreciated! Thank you!

dla question.gh (2.6 KB)

You can use the output a of your GHPython component to output geometry! It can also rename it. Other outputs can be added as well, by zooming in onto the component and clicking on one of the small +s that appear.

In your script, you can for instance define a as an empty list, by putting a = [] before for particle in xrange(numParticles):. After your while loop you may now append your pos to it, but not as a list of two numbers, but as rg.Point2d(pos[0], pos[1]). This yields the following result:

Screenshot 2021-01-07 at 10.09.19

Now, I don’t know if this is what you expected?

Diffusion-limited aggregation is usually done by having a root or start point and a cloud of random, moving points. Once a mover gets within a certain radius of the root point, its position gets frozen and it becomes a root point as well that active movers can stick to. The process is run until there are no more moving points.

The algorithm itself gets really slow after awhile! At the start, there is a single root point and each step all the movers’ distances to this start point need to get computed. After some time, there is more than one root point and each one of them needs to calculate its distance to all remaining movers.
You can for instance improve the speed by measuring the distance squared, because the square root calculation, involved in computing the distance between two points is expensive. You can then compare it to a radius squared.
Furthermore, you can incorporate a tree data structure (i.e. octree, rtree, etc.) to speed up nearest neighbour searches considerably. It is more complex though.

However, you should first try to get the basic algorithm going.

1 Like

That’s a classic recursive approach (you’ll need code for that IF you don’t want to wait for a couple of days for some result). Recursion is something that calls itself until something happens and it stops. People (in general) argue on recursion because of memory issues … but keep reading.

  1. Imagine a historyTree that stores results for each recursion call (the loops, that is).
  2. Imagine some rules related with the generation of new items. In case of lines (to simplify things) these could affect direction, clash events, length (random or not) etc etc.
  3. Set loop 0 and start from a point and do your lines. Store them into the Tree at branch loop (i.e. 0). Set loop++;
  4. Into the recursion Method get in a previousList the items from the historyTree.Branch(loop-1) . Define an empty nextList for the new generation of items. For each create candidate items, check them (for clash events or VS some other rule etc) and store each valid one in the nextList.
  5. Add the nextList in the historyTree path(loop).
  6. Set loop++;
  7. If loop >= maxloops stop the party.
  8. Go to 4.

You can attempt to do this with native components (and Anemone) … but … well … I would strongly suggest the code way (and if things are complex and/or the number of items is big then a a thread safe // programming approach is the way to go).

Here’s an ancient script I posted for DLA in GH
It’s VB, but should be possible to translate to Python

1 Like

I also have another version (VB) that I prepared for a university class.

1 Like

Thank you so much, I finally was able to translate it into python and have it work!

DLAsimpleWithAnemone.gh (12.5 KB)

1 Like