Array error/ help
in
Programming Questions
•
2 years ago
Hello all. I'm very new to processing and this is my first post here.
I have a project to do that requires the use of an image of myself and along with some other image. There needs to be an interactive part of the images and they must include some type of image processing (such as blur or edge detection).
My beginning idea was to have an image of me with the center having the flashlight effect as shown in Daniel Shiffman's example on this site as well as his site. My first issue came up when I was trying to replicate that by using the code directly. I got an array out of bounds exception error and I cant for the life of me find the problem.
Second, I would like to make it so if you clicked in the center portion of the image there would no longer be the flashlight effect but that part would all show up normally. Any tips or help would be greatly appreciated (excuse my commented code or strange errors, I'm struggling with this class having never programmed before.)
Here is what I have so far, and it doesn't work. The error occurs on the line with pixels[loc] = c;
I have a project to do that requires the use of an image of myself and along with some other image. There needs to be an interactive part of the images and they must include some type of image processing (such as blur or edge detection).
My beginning idea was to have an image of me with the center having the flashlight effect as shown in Daniel Shiffman's example on this site as well as his site. My first issue came up when I was trying to replicate that by using the code directly. I got an array out of bounds exception error and I cant for the life of me find the problem.
Second, I would like to make it so if you clicked in the center portion of the image there would no longer be the flashlight effect but that part would all show up normally. Any tips or help would be greatly appreciated (excuse my commented code or strange errors, I'm struggling with this class having never programmed before.)
Here is what I have so far, and it doesn't work. The error occurs on the line with pixels[loc] = c;
- PImage img;
float maxdist, d, adjustbrightness, r, b, g;
boolean draw_on;
void setup() {
size(640, 438);
img = loadImage("Myself.jpg");
image(img, 0, 0, 640, 438);
//draw_on = false;
}
void mousePressed() {
if(mouseX > 0 && mouseX < 320 && mouseY > 0 && mouseY < 417) {
image(img, 0, 0, 640, 438);
}
}
void draw1() {
fill(34, 164, 80);
ellipse(100, 100, 10, 10);
}
void draw() {
loadPixels();
//if(draw_on == false) {
for(int x = 0; x < img.width; x++) {
for(int y = 0; y < img.height; y++) {
int loc = x + y*img.width;
r = red(img.pixels[loc]);
g = green(img.pixels[loc]);
b = blue(img.pixels[loc]);
d = dist(x, y, mouseX, mouseY);
adjustbrightness = (50-d)/50;
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();
}
1