how to apply fade in and out smoothly (slowly) ?

i’m trying to applying fade in and out it working but not smoothly (slowly) code :



PImage bg, img1, img2, img3;
int alpha = 128;

void setup() {
  size(900, 720);
  bg = loadImage("bg.jpg");

  img1 = loadImage("1.jpg");
  img2 = loadImage("2.jpg");
  img3 = loadImage("3.jpg");
}

void draw() {

  background(0);

  tint(255, alpha); 
  image(img1, 150, 150, 200, 400);
  image(img2, 350, 150, 200, 400);
  image(img3, 550, 150, 200, 400);

  if ( mouseX < 350  && mouseX > 150 ) {
    noTint();
    image(img1, 120, 100, 240, 500);
  }


  if ( mouseX < 550  && mouseX > 350 ) {
    noTint();
    image(img2, 320, 100, 240, 500);
  }

  if ( mouseX < 750  && mouseX > 550 ) {
    noTint();
    image(img3, 520, 100, 240, 500);
  }


  fill(255, 0, 0);
  textSize(30);
  text("x " + mouseX + " y" + mouseY, 200, height - 100);

}


Answers

  • edited January 2016 Answer ✓

    You can do something like this:

    float dif = tintStart - tintEnd;
    float damping = 20;
    tintStart -= dif/damping;
    
  • edited March 2016

    thanks for your help !

Sign In or Register to comment.