It makes a 13x13 grid with 30px squares. The first two rows have alternating colors of dark green and green. I want to make it repeat so it keeps going down until I have a checkerboard pattern on the game board. Do I need more variables? Thanks in advance.
but once you have some code ( and problems / questions )
you are welcome to ask here,
++ with good error description
++ pasting full ( running ) ( reduced to the problem ) code
here using the </> Preformatted text button.
it looks already good, but just to see other coding take a test/look here:
// grid of rectangles,
int x = 10, y = x, w = 30, h = w, offset = 2;
int grid = 13, many = grid*grid;
color col1 = color(62, 219, 59);
color col2 = color(33, 181, 72);
boolean switchcol = true;
void setup() {
size(440, 440);
println("x "+x+" y "+y+" w "+w+" h "+h+" offset "+offset+" grid "+grid+" many "+many);
}
void draw() {
drawGrid();
}
void selcol() {
if ( switchcol ) fill(col1);
else fill(col2);
switchcol = ! switchcol;
}
void drawGrid() {
switchcol = true;
for (int i = 0; i < many; i++) {
selcol();
rect(x+(i%grid)*(w+offset), y+(floor(i/grid))*(h+offset), w, h); // or any other shape/text on that position
}
}
That grid from @kll is so pro , you can take it or continue with your own grid, in this whay, check this:
This for is incomplete and nearly unnecessary (for the whole grid), just draws the first two rows .
Think about your other for loop, it draws the whole grid. What about toggle the color with an if statement and a flag (like the variable “switchcol” by @kll)?
You go over the x axis and for each col, you fill each row with squares, that’s nice .
Now try to toggle the color every time you draw a square (once you have done that, try to figure out how to toggle every column ) and when you have that solved, the grid will be done and we can continue with the next step
we talk about a grid of rectangles,
one rectangle has
x,y,w,h aka xpos,ypos,wide,height of the rectangle
also there can be a gap between them: offset
and a println(""); does a print to console, so you see the settings.
grid means how many to the right. 13 rects ( as you ordered )
if many = grid*grid its a symmetric setup, the total amount of rectangles.
but also you can say grid = 2, many = 8 and you get
1 2
3 4
5 6
7 8