Amount of color in picture depending on mouse location?

edited January 2016 in Questions about Code

Hello. I've been working on a code that makes a picture blue. And it works perfectly. The problem is that i know need to have the level of blue depending on the location of the mouse. Meaning if the mouse is on the bottom of the picture, it should be almost none blue. And if its on the top, it should be almost completely blue, but the picture still needs to be visible.

My code looks like this so far:

  float light = 1;

  for(int y = 0;y < img.height; y = y + 1){
    for(int x = 0;x < img.width; x = x + 1){
      color getColor = img.get(x, y);{

      float newRed = red(getColor)*light*0;
      float newGreen = green(getColor)*light*0;
      float newBlue = blue(getColor)*light*2;

      color newColor = color(newRed, newGreen, newBlue);

      set(x, y, newColor);




  • It's better to post runnable code. Anyway, you can use map() and mouseY to vary the blueness. In addition, you should use the pixel array directly and bitshift the colors as it's much faster.

Sign In or Register to comment.