Receiving error but cannot debug: ArrayIndexOutOfBoundsException

int currentScreen;
int col = 15;
int row = 50;
int a, b, x, y, speed;
mark[][] mymark = new mark[col][row];

PImage img;
PImage img0;
PImage img1;
PImage img2;
PImage img3;

import processing.sound.*;
SoundFile file, file2;

void setup() {
  size (1000, 683);
  //noStroke();

  img = loadImage ("batman.jpeg");
  img0 = loadImage ("joker.jpg");
  img0.resize(1000, 683);
  
  img1 = loadImage("jolaugh.jpg");
  img1.resize(1000, 683);
  
  img2 = loadImage("riddler.jpeg");
  img2.resize(1000, 683);
  
  img3 = loadImage("rid.png");
  img3.resize(20,10);

  file = new SoundFile(this, "jlaugh.mp3");
  file2 = new SoundFile(this, "rmt.mp3");
  
}

void draw() {

  switch (currentScreen) {

  case 1: 
    keyPressedOne(); 
    break;

  case 2: 
    keyReleasedOne(); 
    for (int i=0; i<col; i++) {
    for (int j=0; j<row; j++) {
      mymark[i][j] = new mark(color(random(255)), i*40, j*8, random(1,5));
    }
  }
    break;

    case 3: 
    keyReleasedTwo(); 
    break;

  default: 
    image(img, 0, 0); 
    break;
  }

  fill(255); 
  text(currentScreen, width-23, 23);
}

void mousePressed() {
  currentScreen++;
  if (currentScreen > 4) {
    currentScreen = 0;
  }
}

void keyPressedOne() {
  if (keyPressed) {
    if (key == 'a') {
      noStroke();
    fill(img.get(mouseX, mouseY), 128);
  //fill(img.get(x, y), 128);
  rect(mouseX, mouseY, 10, 10);
  
  int x = int (random(width));
  int y = int (random(height));
  x+= int (random(-speed, speed));
  y += int (random(-speed, speed));
  color c = img.get(x, y);
  fill(c, 50);
  ellipse(x, y, 20, 20);
    }
  } else {
    background (200);
  }
}

void keyReleasedOne() {
    boolean a = false;
  if (!a) {
      img1.loadPixels();
      for (int x = 0; x < img1.width; x++ ) {
        for (int y = 0; y < img1.height; y++ ) {

          int loc = x + y*img1.width;

          float r = red  (img1.pixels[loc]);
          float g = green(img1.pixels[loc]);
          float b = blue (img1.pixels[loc]);

          //float adjustBrightness = map(mouseX, 0, width, 0, 8); 
          ////r *= adjustBrightness;
          ////g *= adjustBrightness;
          ////b *= adjustBrightness;
          
          color c = color(r, g, b);
          if (y > mouseX)
            c = color(200, random(60,100), r, 0);
          if (x > mouseY/2)
            c = color(random(0,150),b, 50, 0);
          if (x > mouseY)
            c = color(r/2+62, b*1.5, g/2+50, 0);
            
          r = constrain(r, 0, 255); 
          g = constrain(g, 0, 255);
          b = constrain(b, 0, 255);
          
          //noStroke();
          //fill(c);
          //ellipse(x,y,10,10);

         img1.pixels[loc] = c;
        }
        img1.updatePixels();
      image(img1, 0, 0);
      }//for 
      

    if(!file.isPlaying()){
    file.play();
    }
  } else {

    img0.resize(1000, 683);
    image(img0, 0, 0);
  }
}

void keyReleasedTwo() {
  if (keyPressed){
    if ( key == '2') {
      //background(img2);
      ////blend(img3, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
      ////blend(img3, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
      
      //int i = 1;
      //while (i < 100) {
      //  image(img3, i*10, i*5);
      //    i = i + 20;
      

  background(255);
  for (int i=0; i<col; i++) {
    for (int j=0; j<row; j++) {
      mymark[i][j].move();
      mymark[i][j].display();
    }
  }
      } 
      if(!file2.isPlaying()){
      file2.play();
      }
    } else {
    image(img2, 0, 0);
  }
}

I tried this method, no luck

1 Like