Random.list and adjacent families

It’s true that my code only works for orthogonal grids but I think you could get it to work with varying row lengths just by adding a try loop.

try:
     panelBelow = rowBelow[p]
except:
     panelBelow = None

I think the important part (in my solution at least) is maintaining a list of adjacent geometries and/or their colors. As long as you’re assigning values one panel at a time, you can always retrieve the adjacent panels and query their color. Any panel without a color (None) won’t hurt anything when comparing against your list of available colors.

1 Like

I think the simplicity of your solution is quite nice! And must admit that the solution I suppose is quite a bit heavier.
Though If panels are not organised by a continuous list of adjacent panels (grouped by rows) it will unfortunately not work, this is why I’m trying to utilize the geometry and find the intersecting panels and using this as the “sorting” criteria.

This is definitely a more inclusive approach. Unfortunately it probably comes down to geometry intersection. However, with simple panel geometry it might not be a big deal. You could take your current panel and filter for all other intersecting (coincident) geometry. Take the assigned colors from the adjacent panels (again, None values are fine here, and expected) and compare them to your list of available colors. Now you have your list of allowable colors for the current panel and you just have to randomly select one.

That indeed is the plan, though I do not see it as a linear problem, as you are iterating over the bars:

for bar in bars
if barcolor in adjacentbarcolor
set barcolor random (Not same color)
else
pass

Though if I change the color of bar 1 based on the colors of bar 4 and 5 and I have to change the color of bar 4 caused by bar 7, then the color 1 is no longer valid. I might be over-complicating the issue. I simply find the problem quite interesting though challenging.

Edit: Let me rephrase that for clarity.

You need to check all adjacent panels at once to avoid that problem. You can’t assign a color based on one adjacent panel then hope that you don’t run into issues later on. If you use the actual panel geometry or a single perimeter curve this should be straight forward. A single panel (in this example) can have up to 4 adjacent panels, however no more than 2 will ever have colors assigned as they’re being checked for the current panel.

1 Like