Do you need the resulting clusters to be packed together tightly as your diagram suggests or do you need them to just cluster into looser islands near the home base?
Yes. The array will be fully populated at the start and remain so at the end. The number of colours, number of cells per colour and location of home points will vary from one run to another (There will always be one home location per colour).
As my post said, I was looking to find out if there is any pre-existing code or plug-in that might help before starting to code. I didn’t particularly want to reinvent the wheel. Pasting a stub gh file that generates an array of rectangles is not going to help someone remember a useful plugin.
I wasn’t asking for anyone to write code, but on behalf of the others for whom you did so, thank you.
I don’t think there is a way to do this without custom code.
Using a bool array to store which cells have been visited, starting from the home locations and adding squares from the sides to the center in an iterative process.
I fear you are right, but I think it will need to be more complicated, with an ability for a set colour to be displaced from a cell because the adjacent colour has run out of room. And perhaps an optimiser to prefer rounded regions to long thin ones. My thoughts are heading towards implementing a state machine to run this rather than simple iteration. First step though will be to come up with robust algorithms. I foresee a lot of work.
Code is awful, not optimized, does not always work. But maybe a step in the right direction ?
The idea is to find the square that is furthest away from its home, and try to swap it with the nearest wrong tile from this home - checking it’s not the same color and that the result indeed gives overall a better distance.
This seems related to voronoi.
Weighted voronoi maybe, where weights are a dynamic function calculated by counting the amount of cell centers inclusion (area). (maybe a custom kangaroo goal?)
(Let’s try to not step over others trying to help…)
Thanks for the example. It is using a component called Rainbow Display which I don’t have. I couldn’t find this via the package manager or food4rhino: do you recall where it came from?
It’s a custom component of mine, I made a change to the file and forgot to remove it when re-uploading
It doesn’t affect the main C# method but anyway here is another version with Gradient.