Grasshopper : how to generate Random adjacent boxes in grids?

Hi,
I’m trying to set a group of blocks as the root (or ankor point: the black boxes )
and randomly generate blocks that grow from the root box or boxes ( the red ones ).
I want the growth to be based on the grid and its minimum unit.

I think using random population somehow in grasshopper may be the answer, but I really don’t know where to start… Can anyone suggest a starting point for this?

thanks.

If you have specific seed spots … then a Recursive grow (with various Random min/max vars) is the way to go. A “separation” option is also a must. In real life we use a bool [ , , ] Array to keep track on visited nodes. Elementary with code … but I have no idea how to do it with components.

If on the other hand you are after some 100% Random/Karma related result (using a zillion of options including grow “around” spots, attractors in push/pull mode, probability to take something … blah, blah) in some 2/3Grid that’s also very easy via code … but … see above.

See some cases where you can control Random pts (and in your case using an “ortho coord pt mode + spots” to define the center of your Voxels [ in x/y/z Intervals: [-value/2.0, value/2.0]).





If you want an entry level C# demo notify.

2 Likes

I believe this is flawed and it’s definitely slow - but I need a break, so here it is, for now. Uses Anemone.
grow_regions_2022Oct16a2


grow_regions_2022Oct16a.gh (36.4 KB)

Breaks are crucial for programming. Get out of your chair, take a walk and creative alternatives flow, not constrained by the fixations of debug mode. Code is simpler, better and faster.



grow_regions_2022Oct16b.gh (30.8 KB)

P.S. I found a way to make it faster. Instead of finding boxes adjacent to the regions AND checking all boxes to see if they are inside any region (each time through the loop), I do those operations sequentially. So InCurve operates on far fewer points.


grow_regions_2022Oct16c.gh (31.2 KB)

1 Like

oh my. I’d try this quickly to see the logic. Thanks !!

Ooh. thanks for having my ideas explored. I should try it too !

In general a Recursive grow can work IF there’s an Adjacency Connectivity available (or there’s some suitable rule(s) around) . For your 2/3d Grid is rather obvious (not so if you have holes/voids)

For the example below this AC is a classic FF Mesh Connectivity (i.e a Tree of type int where a path is the index of a given Face in a MeshFace List and items are the indices of the adjacent Faces in the very same MeshFace List).

So using a Quad Mesh and picking Randomly some seed (start) Faces by index and:

  1. Setting option Stop (i.e. terminate after sampling N items per Cluster) to false ,
  2. Setting option Separate to false

… we get this (real-tme no matter the size of any - valid and manifold - Mesh) :

BTW: this is “closer” to some sort of 2dGrid (with voids: i.e. a Matrix where 0 means void and 1 means some item):


1 Like

Joseph, I’ve been using your way and thanks to the loop I have been getting interesting results from it.
One last thing I’m trying and could not find an easy way with using Anemone,

Is there a way I could introduce certain areas as boundaries that the growth would not expand over?

Sure, as long as the constraining shape doesn’t exceed the grid from ArrRec.
I added the cyan group using an ellipse to limit the solution to rectangles whose center points are inside that boundary. Any boundary shape will do instead of the ellipse.


grow_regions_2022Oct19a.gh (37.4 KB)

You could write this differently to start with a boundary shape, use it’s bounding box to create the rectangular grid of boxes, then use the cyan group to cull only the boxes within the boundary.

P.S. For this one, I just drew a boundary curve by hand that doesn’t exceed the RUnion space and internalized it.


grow_regions_2022Oct19b.gh (36.5 KB)

1 Like

Exactly what I was looking for! thank you :slight_smile: