Coloring a mesh/brep with two different color gradients at the same time

Hi!
I have a collection of cubes (will be a x,y,z matrix) and I want to give them a nice gradient color in function to the distance to another brep (sphere for simplicity).
multiple spheres with the same color output is easy, but multiple spheres with different colors is giving me a headache.

I have a “solution” (photo below) but it works by duplicating the cubes for each color and this will be a problem when the number of cubes rises (and it will rise a lot). Also this force me to put a 100%transparent color at the end of each gradient so the farest cubes appear transparent instead of a different color of my choice, and this is minor problem but better if solved.

I tried converting the cubes to meshes and try sprying them but didn’t get anything near my expectation neither!

Also I could get rid of the gradient and just test for what cubes are inside each sphere and dispatch those to different custom previews, but I was hopping to achieve that sweet gradient and color mixing if possible.

thank you very much in advance!

Captura de pantalla (27)|690x388
coloring breps.gh (330.3 KB) .

Welcome @albertocalderonrivas,

Here’s a quick solution using Vornoi cells to group the cubes into clusters belonging to each attractor/sphere.

Instead of the gradients, I use a custom Python component of mine that linearly interpolates between two colours. If you have Pufferfish installed, you can substitute it with Michael’s colour tweening component, however I think it’s always nice to have peek behind the scenes.

For each additional attractor that you add, you also need to add two additional colours two the corresponding Merge components, one to lerp from and one to interpolate to!!
The Graph Mapper can be used to adjust the gradient between the two or more clusters of cubes.

Have fun!

coloring breps V2.gh (331.7 KB)

2 Likes

Wow! I knew this one would be tricky (atleast for me!) Thank you so so much, not only for solving my problem but also because I will be learning a lot from this ““quick solution””.

1 Like