Random composition within constraints

Hi everyone, I would like to do a small code in Processing for my thesis experimentation but cant figured it how.
I want on the grid of 64 squares (8x8), show all the possible composition of 32 squares in black and 32 squares in white in this grid.
I understand i need to create a loop inside a loop (one for the 8 by 8 grid and one for define my 32 black / 32 white) but dont know how to do it.

Hopefully someone can bring me help. Thank in advance :blush::pray:t2:

This is not GitHub-related. That said considering what you’re asking is relatively simple I will just answer anyway. Loops inside loops are pretty simple to do:

for (int y = 0; y < 8; y++) {
  for (int x = 0; x < 8; x++) {
    // ...

y goes on the outside since that’s how 2D arrays are usually constructed but you can do it the other way too.

Oh really ? I’m sorry if my question dont fit here. A friend advance me to ask on Github but maybe i understand worry. Anyway thank you for the advance i’m gonna try it !

This forum is focused on Git and GitHub related things, but other programming and related questions are still welcome. The #software-development category exists for that. Depending on how specialized your question is a place that’s focusing on e.g. a programming language or tool might have a higher chance of helpful replies, though. :slightly_smiling_face:

@mattfbacon described how to create a loop inside a loop for C-ish languages. If you’d like more help I recommend being a bit more specific in what you’re trying to do, in particular if there is a specific thing you’re stuck with.


To be a little more precise there is four different visual I made manually. A grid of 64 squares (8 by 8) and different composition of 32 black squares and 32 grey squares. I’m trying to create a Processing code who create automatically all the possible composition within those settings to see the different kind of output.