Problem looping through a 4D array

here is my way to split your 4D array into a simpler structure with two 2D grids using a class


PImage img;

PixelRepresentation[][] myList; 

void setup() {
  size(1600, 1600);
  noSmooth(); 

  img=loadImage("IMG_2289.jpg");
  img.resize (200, 200);
  myList = new PixelRepresentation[img.width][img.height];


  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++ ) {
      // Calculate the 1D pixel location
      int loc = x + y*img.width;

      color c1=img.pixels[loc]; 

      myList[x][y] = new PixelRepresentation (c1, x*5, y*5);
    }
  }
}

void draw() {
  //image(img, 10, 10);

  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++ ) {
      myList[x][y].display();
    }
  }
}

// ================================================================

class PixelRepresentation {

  //
  color col;
  float x, y;

  boolean[][] fieldArray = new boolean [ 2 ][ 3 ]; // !!!!!!!!!!!!  

  PixelRepresentation (color col_, 
    float x_, float y_) {
    col=col_;
    x=x_;
    y=y_;
  }

  void display() {
    // use fieldArray here 
    fill(col); 
    stroke(col); 
    //    point(x, y);
    rect(x, y, 
      3, 3 );
  }
}//class
//
2 Likes