PImage img;
void setup() {
size(1000, 1000);
img = loadImage( "rickroll.jpg" );
}
void draw() {
loadPixels();
img.loadPixels();
for (int x = 0; x < img.width; x++ ) {
for (int y = 0; y < img.height; y++ ) {
int loc = x + y*img.width;
float r = red (img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue (img.pixels[loc]);
float distance = dist(x, y, mouseX, mouseY);
float adjustBrightness = map(distance, 0, 50, 8, 0);
r *= adjustBrightness;
g *= adjustBrightness;
b *= adjustBrightness;
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
color c = color(r, g, b);
pixels[loc] = c;
}
}
updatePixels();
}
The file rickroll.jpg is in the right place, but Processing says that
ArrayIndexOutOfBoundsException: Index 40600 out of bounds for length 40000
for this line: pixels[loc] = c;
I know this is beginner stuff. My brain is just having the hardest time right now. Can you help?