2

Can someone help me I am kind of new at programming but was working in processing and need to create a pogram which combines two arrays into one and displays them exactly on the same position? So it cycles through one array, which is like 23 images and then the other array which is 8 images. I have this so far:

PImage[][] mEyes1 = new PImage[23][8];
// PImage[] mEyes2 = new PImage[8];

void setup() {
  size(620, 400); 
  // fullScreen();
  frameRate(60);
  smooth();

  for (int i = 0; i < mEyes1.length; i++) 
    for (int j = 0; j < mEyes1.length; j++) {
      PImage img = loadImage(i + "h.jpg");
      PImage img1 = loadImage(j + "j.jpg");

      // r
      mEyes1[i][j] = img.get(130, 170, 310, 100); 
      mEyes1[i][j] = img1.get(130, 170, 310, 100); //Get a portion of the loaded image with displaying it

      int idy = (int)map(mouseY, 0, 2*width, 0.0, mEyes1[i].length -1);
      int idx = (int)map(mouseX, 0, 2*width, 0.0, mEyes1[j].length -1);

      image(mEyes1[idx][idy], 0, 0, mEyes1[idx][idy].width, mEyes1[idx][idy].height -1);
      // image(mEyes1[idy][idx], 0, 0, mEyes1[idy][idx].width, mEyes1[idy][idx].height -1);

      println(idx,idy);
    }
}

void draw() {
}

I know it looks wrong, but I want to display a series of images at the same position after it goes through the first 23?

Thanks!

2
  • Could you please edit your question to clarify what you mean? You talk about two goals - a program that "combines two arrays into one and displays them exactly on the same position", and "cycles through one array, which is like 23 images and then the other array which is 8 images". If you could add a mockup, screenshot, or a link to an example that already implements what you want, it would be very helpful. Commented Apr 26, 2016 at 19:35
  • Your question doesn't make a ton of sense. Can you describe exactly what you mean by combining two arrays and displaying them at the same position? Put together some simple mockup images. What exactly do you mean by displaying a series of images at the same position? Can you be more specific? What does this code do? How does its execution differ from what you expect it to do? Commented Apr 26, 2016 at 19:43

1 Answer 1

1

Look at this line:

PImage[][] mEyes1 = new PImage[23][8];

This is creating a 2D array, which is an array of arrays. In other words, you're creating 23 arrays of length 8, for a total of 184 (23*8) indexes. I don't think this is what you want to do.

Instead, it sounds like you simply want to create an array of 31 (23+8) indexes:

PImage[] mEyes1 = new PImage[31];

Then you could use two for loops to loop through your image files and add them to the array:

for(int i = 0; i < hImageCount; i++){
  PImage img = loadImage(i + "h.jpg");
  mEyes1[i] = img;
}

for(int j = 0; j < jImageCount; j++){
  PImage img1 = loadImage(j + "j.jpg");
  mEyes1[hImageCount+j] = img1;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.