How to keep an image filtered?

edited February 2016 in How To...

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);
      }
    }
  }
}
Tagged:
Sign In or Register to comment.