# Clear() not working properly

**URL:** <https://discourse.processing.org/t/clear-not-working-properly/11924>\
**Category:** Coding Questions\
**Created:** [June 8, 2019, 3:16pm UTC](https://discourse.processing.org/t/clear-not-working-properly/11924 "2019-06-08T15:16:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BallazX](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@BallazX](https://discourse.processing.org/u/BallazX)\
**Post date:** [June 8, 2019, 3:16pm UTC](https://discourse.processing.org/t/clear-not-working-properly/11924/1 "2019-06-08T15:16:53Z")

</div>

Hi All,

I’ve got this code:

```auto
PGraphics myline;
PGraphics myrect;
void setup(){
background(#FFFFFF);
size(600,600);
myline=createGraphics(width,height);
myrect=createGraphics(width,height);
}
void draw(){
  myrect.beginDraw();
  myrect.rect(50,50,198,198);
  myrect.endDraw();
  myline.beginDraw();
  myline.line(147,475,mouseX,mouseY);
  myline.endDraw();  
  image(myrect,0,0);
  image(myline,0,0);  
}
void mousePressed()
{
  myline.beginDraw();
  myline.clear();
  myline.endDraw();
}

```

What I want to do is clear all the lines as I press the mouse. The problem is only those part of the lines will be deleted which are above the rect. What should I do?

 ![bjkbjk](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/99482b8fc6befc41a0fbe2b04ef1460849d1452f.png)

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 8, 2019, 3:25pm UTC](https://discourse.processing.org/t/clear-not-working-properly/11924/2 "2019-06-08T15:25:04Z")

</div>

Hey There!

The lines are being deleted ! But because your not updating the background the pixels are not being refreshed and what was present before still stays.

Before everything in `draw()` just put `background( 255,0,0 )`  
where `( 0 , 0 , 0 )` corresponds to **RGB** and the showcase of each color intensity.

Also a note to add the rectangle your drawing wouldn’t it be drawn over and over in `draw()` because your calling `beginDraw()` on it inside `draw()` ? It seems with your rectangle it be way more efficient to only draw it once if it not going to move to save resources.
