4
$\begingroup$

Pic 1

to make it less confusing, lets say I have 8 bricks with different colors, now I want to lay them in a pattern as shown below but the main condition is that they mustn't merge/ if they have same color then they shouldn't be close to each other as shown in second pic [ I just realized the pink bricks in top layers merging. pls ignore that error]

I just need to know if it's possible since I haven't even started exploring geo nodes yet, and it'd be very helpful to me if there's any videos which shows something close to this

Thank you.

Pic 2

$\endgroup$
1
  • 2
    $\begingroup$ It's a nice question. In case of bricks it certainly is possible if you limit the randomness in just the right way. Alternatively you can detect if a brick has the same color as one of the neighbors and then change the color of that brick to one different than one of the neighbors… $\endgroup$ Commented Feb 12, 2023 at 10:04

1 Answer 1

4
$\begingroup$

The difficulty of it varies greatly depending on two important parameters:

  • the (maximum?) number of colors,
  • the random distribution (how random is it really).

Unfortunately there are no loops in Geometry Nodes. You can use fields together with a group of things like points to do many things that loops can accomplish, but you can't manage state during a loop, except for "Accumulate Field" node, which is, however, quite limited: it just sums all elements, giving access to a sum of all elements up to the current element (excluding or including the current element). So while in a normal programming language you would just iterate over bricks and for each (4) randomize a color different than the preceding bricks (1-3), in Geonodes it's not yet possible:

So here's a much worse solution:

  1. Define 3 pools of colors:
    • basic pool of colors used for the 1st pass,
    • 2 replacement colors used for odd rows,
    • 2 replacement colors used for even rows.
  2. Randomize brick colors out of the basic pool.
  3. For each brick check if it ended up with one of the colors of its 3 preceding neighbors. If so:
    • pick a replacement pool depending on the row being odd or even,
    • pick the 1st or the 2nd color of the replacement pool depending on the brick being odd or even on this row.

This means you need at least 4 colors (in which case you just get alternating colors), with each additional color (one added to the basic pool) improving the random distribution.

There is some room for improvement for this algorithm, like Accumulate Field nodes could be used to not glue specific replacement colors to the alternating pattern, so you would modulo the accumulated value (which would accumulate only on replacements) rather than $x$, also a random value may be generated for each row, deciding which of the two colors of the replacement pool should be first on each row.

$\endgroup$
2
  • 1
    $\begingroup$ Markus... it seems you are in the nodes hell! but... UV, ok... $\endgroup$
    – lemon
    Commented Feb 12, 2023 at 19:26
  • $\begingroup$ Damn, Can't believe you actually came up with something like that, I don't have much time right now but your setup just blew my mind, I'll definitely take some time off just to understand this, Once again thank you very much Markus for making it possible $\endgroup$
    – Ace
    Commented Feb 13, 2023 at 17:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .