Chess board with random dimensions

Hey!

I'm doing a CSC project that requires me to make a chess board that has 64 squares of black and white arranged in traditional chessboard fashion. The board has to be random dimensions each time you run the program, ranging from 80x80 to 800x800 in size. I've made a fair amount of progress, but whenever the variable I used for the length and width of each square is even, the entire board is filled in black! However, when that same variable is odd, it makes the board just fine (the variable I'm speaking of is the universal variable 'c' that I defined at the top of the program). Also I need the colors on the board to be inverted when I press the mouse, which is something I haven't even attempted yet because programming seems to get a temper when I try to put this into "void run ()" mode.

Any help is much appreciated!

Ryan

    int c = int(random(10,100));

      size(c*8+1,c*8+1);
      background(255);
      for (int y = 0; y < width; y = y + c) {
        for (int x = 0; x < width; x = x + c){
          if ((x + y) % 2 != 0) {
            fill(255);
          }
            else {
              fill(0);
            }
          stroke(0);
          rect(x,y,c,c);
        }
      }

      print(c);
Tagged:

Answers

Sign In or Register to comment.