# How can I change Image background with mouse click?

**URL:** <https://discourse.processing.org/t/how-can-i-change-image-background-with-mouse-click/38189>\
**Category:** Beginners\
**Created:** [August 1, 2022, 3:27pm UTC](https://discourse.processing.org/t/how-can-i-change-image-background-with-mouse-click/38189 "2022-08-01T15:27:26Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [August 2, 2022, 1:04pm UTC](https://discourse.processing.org/t/how-can-i-change-image-background-with-mouse-click/38189/7 "2022-08-02T13:04:33Z")

</div>

Hi @steven,

you can use the same approch as from your other topic…

> [@Changing image background with given specific time](https://discourse.processing.org/t/changing-image-background-with-given-specific-time/38186/3):
>
> Hi @steven, Pretty much everything listed you need by @glv. Maybe some meta description… On start Create an array with available images. Initialize variables for currentImageindex and nextUpdateTime with suitable values On draw loop check if currentTime \>= nextUpdateTime If true increment currentImageindex mod size of image array add interval to nextUpdateTime set background using currentImageIndex on available images Cheers — mnse

but instead of changing the background, switch on and off the text output …

Cheers  
— mnse

PS:

```auto
final String myMessage="Hello World!";
int nextOne = 0;
boolean showText = false;

void setup() {
  size(500, 500);
  textSize(50);
  fill(255);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0);
  if (millis() > nextOne) {
    showText = !showText;
    nextOne = millis() + floor(map(mouseX, 0, width, 500, 50));
  }
  if (showText)
    text(myMessage, width/2, height/2);
}

```

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-change-image-background-with-mouse-click/38189)._
