# Clear PGraphic after image()

**URL:** <https://discourse.processing.org/t/clear-pgraphic-after-image/35074>\
**Category:** Processing\
**Created:** [February 10, 2022, 2:04pm UTC](https://discourse.processing.org/t/clear-pgraphic-after-image/35074 "2022-02-10T14:04:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://discourse.processing.org/u/Omri)\
**Post date:** [February 10, 2022, 2:04pm UTC](https://discourse.processing.org/t/clear-pgraphic-after-image/35074/1 "2022-02-10T14:04:18Z")

</div>

Hey, I have some problem I can’t figure out:  
I want to draw a circle on a screen by the mouseX mouseY cords (I want the draw to stay on the screen so I refresh the background un the draw function) , and above it I’m trying to draw a smaller circle that is keeping the mouseX mouseY cords. So I thought to use PGraphics and to draw the smaller circle and use clear every frame.  
the problem is that when I use the Image() function to show the PGraphics Its stays on the screen so I see the trail of the smaller circle.

Does anyone have any idea what can I do differently? 🤔

---

<div class="post-metadata">

**Author:** ![SamTech](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/samtech/32/12897_2.png) [@SamTech](https://discourse.processing.org/u/SamTech)\
**Post date:** [February 10, 2022, 2:39pm UTC](https://discourse.processing.org/t/clear-pgraphic-after-image/35074/2 "2022-02-10T14:39:57Z")

</div>

The problem is that you try to keep that part of your graphics that is changed when the image()-function is called. You could solve your problem by switching your graphics.

```auto
PGraphics background;
void setup() {
  size(300, 300);
  background=createGraphics(300, 300);
  background.beginDraw();

  //you can draw whatever you wanna draw :)
  for (int i=0; i<10000; i++) {
    background.stroke(random(255), random(255), random(255));
    background.strokeWeight(4);
    background.point(random(300), random(300));
  }

  background.endDraw();
}

void draw() {
  background(background);
  stroke(0);
  fill(0, 0);
  strokeWeight(3);
  circle(mouseX, mouseY, 30);
  youcanevenchangeit();
}

//change the background
void youcanevenchangeit() {
  background.beginDraw();
  background.stroke(random(255), random(255), random(255));
  background.strokeWeight(4);
  background.point(random(300), random(300));
  background.endDraw();
}

```

---

<div class="post-metadata">

**Author:** ![Omri](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@Omri](https://discourse.processing.org/u/Omri)\
**Post date:** [February 11, 2022, 11:04am UTC](https://discourse.processing.org/t/clear-pgraphic-after-image/35074/3 "2022-02-11T11:04:32Z")

</div>

Amazing!  
Had no idea that I can use the background function instead of the image.  
Thank you 🙂
