# Specific Image fade issues

**URL:** <https://discourse.processing.org/t/specific-image-fade-issues/2582>\
**Category:** Coding Questions\
**Created:** [August 13, 2018, 1:44am UTC](https://discourse.processing.org/t/specific-image-fade-issues/2582 "2018-08-13T01:44:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nedelstein](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nedelstein](https://discourse.processing.org/u/Nedelstein)\
**Post date:** [August 13, 2018, 1:44am UTC](https://discourse.processing.org/t/specific-image-fade-issues/2582/1 "2018-08-13T01:44:30Z")

</div>

Hi all,

I have multiple images on my sketch and am trying to only get one to fade out, but I can’t seem to get the fade to only work for the one image. It’s fading out everything when I run it. Any help would be really appreciated!

I’m trying to get the “lightning” image to fade slowly after it appears.

`

```auto
PImage stormMountain;
PImage lightning;

flash[] boom = new flash[1];
raindrop[] rain = new raindrop[30]; 

void setup() {
  size(350, 350);
  frameRate(15);
  for (int i = 0; i<30; i++) {
    rain[i] = new raindrop(random(width), random(height));
    
  }
  for (int i = 0; i<1; i++){
boom[i] = new flash(random(width), random(height));
}

  ///mountain image///
  stormMountain = loadImage("stormMountain.png");
  ///lightning image
  lightning = loadImage("lightning.png");
}

void draw() {
  background(255);

  rect(0,0,width,height);
  
  imageMode(CENTER);
  image(stormMountain, width/2, height/2);

  for (int i = 0; i<30; i++) {
    rain[i].displayRain();
    rain[i].moveDrop();
    //loop();
  }
  for (int i = 0; i<1; i++){
  boom[i].lightingStrike();
  boom[i].moveLightning(); 
}
}
`

```

and then my lightning class:

```auto
class flash {

  float x, y;
  float xMove, yMove;
  float strike;
  float transparency;

  flash(float tempX, float tempY) {
    x = tempX;
    y = tempY;
    xMove = random(width);
    yMove = random(height);
    strike = random(0,20);
    transparency = 255;
  }

  void lightingStrike() {
    if (frameCount % 20 == 0){
      if(transparency>0){
    transparency -=10; 
    }
    tint(255, transparency);
    image(lightning, x, y);
    y = random(height);
    x = random(width);
    
  }
  }
    void moveLightning() {
    y = random(height);
    x = random(width);
    if(transparency>0){
    transparency -=10; 
    }
    tint(255, transparency);
  
}
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [August 13, 2018, 6:04am UTC](https://discourse.processing.org/t/specific-image-fade-issues/2582/2 "2018-08-13T06:04:49Z")

</div>

Did you try to put `noTint()` at the beginning of your `draw()` function?  
I don’t know if the tint got reinitialized when a new loop starts 🤔.

Also can you please create a github repository for us to be able to run your example? You have images that we don’t have access to so it is hard to see exactly what you mean.

---

<div class="post-metadata">

**Author:** ![Nedelstein](https://avatars.discourse-cdn.com/v4/letter/n/db5fbb/32.png) [@Nedelstein](https://discourse.processing.org/u/Nedelstein)\
**Post date:** [August 13, 2018, 3:27pm UTC](https://discourse.processing.org/t/specific-image-fade-issues/2582/3 "2018-08-13T15:27:47Z")

</div>

Ah yes, sorry about that. Here you go: [https://github.com/Nedelstein/Lightning-Sketch.git](https://github.com/Nedelstein/Lightning-Sketch.git)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 13, 2018, 7:52pm UTC](https://discourse.processing.org/t/specific-image-fade-issues/2582/4 "2018-08-13T19:52:40Z")

</div>

Check the changes in the sketch. I didn’t touch the rain class. Use by clicking on the sketch.

Kf

```java
//import com.temboo.core.*;
//import com.temboo.Library.Yahoo.Weather.*;

PImage stormMountain;
PImage lightning;

flash[] boom = new flash[1];
raindrop[] rain = new raindrop[30]; 

void setup() {
  size(350, 350);
  //frameRate(15);
  for (int i = 0; i<30; i++) {
    rain[i] = new raindrop(random(width), random(height));
  }
  for (int i = 0; i<1; i++) {
    boom[i] = new flash(random(width), random(height));
  }

  stormMountain = loadImage("stormMountain.png");
  lightning = loadImage("lightning.png");

  imageMode(CENTER);
}

void draw() {
  noTint();
  background(255);

  image(stormMountain, width/2, height/2);

  for (int i = 0; i<30; i++) {
    rain[i].displayRain();
    rain[i].moveDrop();
    //loop();
  }

  boom[0].lightingStrike();
  //boom[i].moveLightning();
}

void mousePressed() {
  boom[0].transparency=255;
  boom[0].y = mouseY;//random(height);
  boom[0].x = mouseX;//random(width);
}

class flash {

  float x, y;
  float xMove, yMove;
  float strike;
  float transparency;

  flash(float tempX, float tempY) {
    x = tempX;
    y = tempY;
    xMove = random(width/2);
    yMove = random(height/2);
    strike = random(0, 20);
    transparency = 255;
  }

  void lightingStrike() {

    if (frameCount % 5 == 0)
      if (transparency>0) {
        transparency -=20;
      } else {
        y = mouseY;//random(height);
        x = mouseX;//random(width);
        return;
      }

    tint(255, transparency);
    image(lightning, x, y);
  }

  //void moveLightning() {
  // y = random(height);
  // x = random(width);
  // if (transparency>0) {
  // //transparency -=10;
  // }
  // //tint(255, transparency);
  //}
}

```
