The coloring is working. I really appreciate the time @Chrisir and @glv have spent helping me with this. Aside from how non-DRY my code is now, it’s working and I understand it. But I can’t figure out how to make the dot grids align in a big grid.
Here’s without for loops (because those were screwing me up), but x is just incrementing upwards without wrapping to the next line:
//sizes
int a = 20;
int b = 6;
int c = 3;
int d = b+c;
int e = b*3+c*2;
int f = a+e;
//counts
int g = int(pow(2, 9));
//colors
int [] colors = {0, 255};
// grid will be 32 grids wide by 16 tall
// so width=32*e+33*a; or (32*24)+(33*20)
// and height=16*e+17*a;
void setup () {
size(1424, 1064);
noLoop();
noStroke();
}
void draw () {
int x = a;
int y = a;
for (int k=0; k<g; k=k+1) {
println (binary(k, 9));
String binaryk = (binary(k, 9));
char d1 = binaryk.charAt(0);
char d2 = binaryk.charAt(1);
char d3 = binaryk.charAt(2);
char d4 = binaryk.charAt(3);
char d5 = binaryk.charAt(4);
char d6 = binaryk.charAt(5);
char d7 = binaryk.charAt(6);
char d8 = binaryk.charAt(7);
char d9 = binaryk.charAt(8);
int c1 = colors[int(d1+"")];
int c2 = colors[int(d2+"")];
int c3 = colors[int(d3+"")];
int c4 = colors[int(d4+"")];
int c5 = colors[int(d5+"")];
int c6 = colors[int(d6+"")];
int c7 = colors[int(d7+"")];
int c8 = colors[int(d8+"")];
int c9 = colors[int(d9+"")];
println(d1, d2, d3, d4, d5, d6, d7, d8, d9);
println(c1, c2, c3, c4, c5, c6, c7, c8, c9);
fill(c1);
ellipse(x, y, c, c);
fill(c2);
ellipse(x+d, y, c, c);
fill(c3);
ellipse(x+d*2, y, c, c);
fill(c4);
ellipse(x, y+d, c, c);
fill(c5);
ellipse(x+d, y+d, c, c);
fill(c6);
ellipse(x+d*2, y+d, c, c);
fill(c7);
ellipse(x, y+d*2, c, c);
fill(c8);
ellipse(x+d, y+d*2, c, c);
fill(c9);
ellipse(x+d*2, y+d*2, c, c);
x=x+f;
if (x<width) {
y=a;
} else if (x>width && x<(width*2)) {
x=x+f;
y=y+f;
}
}
}
Here’s with for loops, but the mini grids are writing over themselves:
//note: this sketch takes several seconds to render
//sizes and spacings
int a = 20;
int b = 6;
int c = 3;
int d = b+c;
int e = b*3+c*2;
int f = a+e;
//counts
int g = int(pow(2, 9));
//colors
int [] colors = {102, 255};
// grid will be 32 grids wide by 16 tall
// so width=32*e+33*a; or (32*24)+(33*20)
// and height=16*e+17*a;
void setup () {
size(1424, 1064);
noLoop();
noStroke();
}
void draw () {
for (int x=a; x<width; x=x+f) {
for (int y=a; y<height; y=y+f) {
for (int k=0; k<g; k=k+1) {
println (binary(k, 9));
String binaryk = (binary(k, 9));
char d1 = binaryk.charAt(0);
char d2 = binaryk.charAt(1);
char d3 = binaryk.charAt(2);
char d4 = binaryk.charAt(3);
char d5 = binaryk.charAt(4);
char d6 = binaryk.charAt(5);
char d7 = binaryk.charAt(6);
char d8 = binaryk.charAt(7);
char d9 = binaryk.charAt(8);
int c1 = colors[int(d1+"")];
int c2 = colors[int(d2+"")];
int c3 = colors[int(d3+"")];
int c4 = colors[int(d4+"")];
int c5 = colors[int(d5+"")];
int c6 = colors[int(d6+"")];
int c7 = colors[int(d7+"")];
int c8 = colors[int(d8+"")];
int c9 = colors[int(d9+"")];
println(d1, d2, d3, d4, d5, d6, d7, d8, d9);
println(c1, c2, c3, c4, c5, c6, c7, c8, c9);
fill(c1);
ellipse(x, y, c, c);
fill(c2);
ellipse(x+d, y, c, c);
fill(c3);
ellipse(x+d*2, y, c, c);
fill(c4);
ellipse(x, y+d, c, c);
fill(c5);
ellipse(x+d, y+d, c, c);
fill(c6);
ellipse(x+d*2, y+d, c, c);
fill(c7);
ellipse(x, y+d*2, c, c);
fill(c8);
ellipse(x+d, y+d*2, c, c);
fill(c9);
ellipse(x+d*2, y+d*2, c, c);
//y=y+f;
}
}
}
}
Is there a simple change I could make to have the small grids appear within the large grid? If it involves for loops I can’t figure out how to keep them from overwriting each other in the same place.