title: Run each pixel through a rectangular PGraphics (Processing)
body: <p>I have a squared PGraphics where I want to read the color of each pixel. I do this with the following lines:</p>
  <pre><code>size(1080,1080, P2D);
  pg = createGraphics(width, height, P2D);
  </code></pre>
  <p>…then in draw:</p>
  <pre><code> pg.loadPixels();
    for (int y = 0; y &lt; pixel; y++) {
      for (int x = 0; x &lt; pixel; x++) {
        int ix = int(size*x);
        int iy = int(size*y);
        color c = pg.pixels[iy * width + ix];
  </code></pre>
  <p>However, if I now change the size so that the PGrpahics or my sketch window is no longer squared I get an <code>ArrayIndexOutOfBoundsException</code> error message. I know that you can also read the pixels from rectangular sketches, for example with:</p>
  <pre><code>   pixels[x+y*width] = …etc
  </code></pre>
  <p>Works fine – but what is it that I am missing above if I change the size to lets say <code>size(1920,1080, P2D);</code>?</p>