We are about to switch to a new forum software. Until then we have removed the registration on this forum.
We have a project to filter images based on pressing a certain key, and my image will change to grayscale when I press 1, but it will revert back to the original when I release 1, and I was wondering how I could keep it grayscale until a different button is pushed! I know it has to do with my if statement...but I'm unsure how I'd keep the filter after pressing 1
Here's my code:
void draw(){
image(img,0,0);
//turn the image to grayscale if you press 1
if (keyPressed == true && (key == '1')){
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++){
color c = get(x,y);
float red = red(c);
float green = green(c);
float blue = blue(c);
int grey = (int)(red+green+blue)/3;
color Color =color(grey,grey,grey);
set(x,y,Color);
}
}
}
}
Answers
https://Processing.org/reference/keyPressed_.html