Iterate once and only once through all the possible configurations of an array

Thanks @josephh, I appreciate the pointer. I read that article a few times but couldn’t quite wrap my head around what to do next. I’m a bit of a noob and probably in over my head. I’ve been able to get every dot to color with either white or black, but I can’t figure out how to (1) make sure I get all the possible combinations, and (2) make sure I get no duplicates. I gather I create a data[] array in which to produce all the possible combinations but I can’t figure out how to do that. If anyone has further advice I definitely welcome it. Here’s what I’ve got so far (with a 2 row, 2 column grid instead of one row):

 import processing.pdf.*;
 boolean savePDF = true;
 
 int colorset;
 color [] colorsetarray = {#FFFFFF, #000000}; 
 
 void setup () {
   size(400, 400);
   noLoop(); //prevents video playback
 }
 
 void draw () {
   beginRecord(PDF, "Arabesque"+year()+"-"+"0"+month()+"-"+day()+"_"+hour()+minute()+"0"+second()+".pdf" );
   
   for (int y=20; y<height; y += 50) {
     for (int x=20; x<width; x += 50) {
    drawGrid(x,y);
     }
   }
 
   // saves the image when you play the sketch with the date and seconds in the sketch folder
   endRecord();
 }
 
 void drawGrid (float x, float y) {
   noStroke();
   fill(colorsetarray[int(random(2))]);
   circle(x,y,6);
   fill(colorsetarray[int(random(2))]);
   circle(x+9,y,6);
   fill(colorsetarray[int(random(2))]);
   circle(x,y+9,6);
   fill(colorsetarray[int(random(2))]);
   circle(x+9,y+9,6);
   }

image

1 Like