# Different background, Different item by mousePressed

**URL:** <https://discourse.processing.org/t/different-background-different-item-by-mousepressed/24530>\
**Category:** Coding Questions\
**Created:** [October 12, 2020, 1:49am UTC](https://discourse.processing.org/t/different-background-different-item-by-mousepressed/24530 "2020-10-12T01:49:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fisher](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@fisher](https://discourse.processing.org/u/fisher)\
**Post date:** [October 12, 2020, 1:49am UTC](https://discourse.processing.org/t/different-background-different-item-by-mousepressed/24530/1 "2020-10-12T01:49:31Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I’m making day/night animation where I use “mousePressed” on locating the sun on the blue sky according to the mouseX,mouseY. When the key ‘n’ is pressed, the sky turns to dark and the sun disappears. So, HOW to replace the sun with a moon image in the night sky and locate it the same way as the sun using the “mousePressed” and mouseX/Y??

Here’s what I did:

```auto
boolean sun = false;
int sunX; 
int sunY;
boolean night = false;

void setup() {
  size(400, 400);

  ellipseMode(CENTER);
}

void draw() {

  if (night == true) {
    background(0, 0, 80);
  } else {
    background(0, 200, 200);
  }

  if (sun == true) {
    fill(255, 255, 0);
    ellipse(sunX, sunY, 80, 80);
  }
}

void mousePressed() {
  sun = true;  
  sunX = mouseX;
  sunY = mouseY;
}

void keyPressed() {
  if (key=='n') {
    night = true;
    sun = false;
  }  
}

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [October 12, 2020, 7:15am UTC](https://discourse.processing.org/t/different-background-different-item-by-mousepressed/24530/2 "2020-10-12T07:15:05Z")

</div>

Welcome to the forum.

mouseX and mouseY values are always available, not just in mouse events. So you can store them when n key pressed.

```auto
void keyPressed() {
  if (key=='n') {
    night = true;
    sun = false;
    moonX = mouseX;
    moonY = mouseY;
  }  
}
```
