title: Divide canvas into multiple stripes using RGB
body: <p>I want to divide the canvas into 8 vertical black and white Stripes. I wrote a method changeValue to change the value of the color everytime the loop is executed but the canvas is complete white. I think my changeValue method doesn't do as supposed but I can't explain why.</p>
  
  <p>So far I got this:</p>
  
  <pre><code>public class Stripe {
  
      public boolean switch = false;
  
      private void stripes(int[] pixels, int width, int height) {
          // TODO set some values here
          int counter = 1;
          for (int y = 0; y &lt; height; y++) {
              for (int x = 0; x &lt; width; x++) {
                  int pos = y * width + x;
                  int r, g, b;
                  // TODO code for the flag.
                  r = 255;
                  g = 255;
                  b = 255;
  
                  for (int i = 0; i &lt; 8; i++) {
                      if (x &lt; (counter * (width - 1)) / 8) {
                          r = changeValue();
                          g = changeValue();
                          b = changeValue();
                      }
                      counter++;
                      switch ^= true;
  
                  }
  
                  pixels[pos] = 0xFF000000 | (r &lt;&lt; 16) | (g &lt;&lt; 8) | b;
              }
          }
      }
  
      public int changeValue() {
          if (switch) {
              return 255;
          } else {
              return 0;
          }
      }
  }
  </code></pre>
  
  <p>I am supposed not to write 8 If statements for the 8 stripes but this for example is the code for the Italian flag which are 3 vertical Stripes but which actually works:</p>
  
  <pre><code>private void flagItalian(int[] pixels, int width, int height) {
      // TODO set some values here
      for (int y = 0; y &lt; height; y++) {
          for (int x = 0; x &lt; width; x++) {
              int pos = y * width + x;
              int r, g, b;
              // TODO code for the flag.
              r = 255;
              g = 0;
              b = 0;
              if (x &lt; 2 * (width - 1) / 3) {
                  r = 255;
                  g = 255;
                  b = 255;
              }
              if (x &lt; (width - 1) / 3) {
                  r = 0;
                  g = 255;
                  b = 0;
              }
              pixels[pos] = 0xFF000000 | (r &lt;&lt; 16) | (g &lt;&lt; 8) | b;
          }
      }
  }
  </code></pre>