1
\$\begingroup\$

I've been messing around with a software called Processing, used for user interactions and a lot of cool things. I programmed a pattern from a Chess set but I'm not sure if it's the best way to program it.

void setup() {
   size(400, 400);
   background(255);
}

int patternColor = 255;
void draw() {
   for (int y = 0; y < width; y += 50) {
      for (int x = 0; x < height; x += 50) {
         fill(patternColor);
         rect(x, y, 50, 50);

         if (patternColor == 255) {
            patternColor = 0;
         }
         else {
            patternColor = 255;
         } 
      }

      if (patternColor == 0) {
         patternColor = 255;
      }
      else {
         patternColor = 0;
      }
   }
}
\$\endgroup\$
  • \$\begingroup\$ If background(oneColour) sets "the entire space" to the colour half of the tiles should end up with, it should be enough to fill(otherColour) once and rect(x, y, tileWidth, tileHeight) the other half, only. (Otherwise, think about (x+y)%(2*tileSize), code that, pick what you think *more readable".) \$\endgroup\$ – greybeard Feb 11 '18 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.