Draw every possible unique combination of a 3x3 circle grid with two colors

Example here to get you started:
https://discourse.processing.org/t/iterate-once-and-only-once-through-all-the-possible-configurations-of-an-array/22366/13

I took my example and modified it to make a 2x2 grid and put it in a loop:

void setup() 
  {
  size(500, 500);    
  background(155, 0, 0);
  }
  
void draw()
  {
  int i =  int(random(0, 15)); 
  int xg = int(random(0, width-10))+5;
  int yg = int(random(0, height-10))+5; 
  
  // This can be a function:
  int a, b;
  int x = 0; 
  int y = 0;
  
  for(int j = 0; j<4; j++)
    {   
    a = i & (0x01<<j);
    b = (a > 0) ? 1 : 0;
    if (b == 1)
      fill(0);
    else
      fill(255);
    
    x = j%2;
    if (j > 0 & x == 0) y++;
    
    circle(x*10 + xg, y*10 + yg, 10); 
    }
  } 

I used the % operator for making the 2x2 grid.
The % operator can also be used to plot all the combinations of the 2x2 grid on a larger grid.

Understanding this example will require some work on your part.

I used the same example and suggestions (scaled up for a 3x3 grid) to create this:

References:

I am comfortable with the math and operators I used.

There are many ways to tackle this; I have worked through many of these and this is what I churned out quickly.
Choose the path that helps you easily understand this and go from there.

:)

1 Like