# Erase a rectangle

**URL:** <https://discourse.processing.org/t/erase-a-rectangle/33352>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 6, 2021, 2:14am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352 "2021-11-06T02:14:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanmz7](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stefanmz7](https://discourse.processing.org/u/stefanmz7)\
**Post date:** [November 6, 2021, 2:14am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/1 "2021-11-06T02:14:51Z")

</div>

Hey so can I erase a shape after drawing it? For example I want to have a circle and a rectangle and when they collide the rectangle is erased,it’s just gone out of the program. So how do I do the erasing? I got the other part down.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 6, 2021, 2:31am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/2 "2021-11-06T02:31:15Z")

</div>

Please tell us how you are creating the rectangles that you want to destroy. Do you use multiple calls to rect(), do you have a rectangle array, are they derived from a special class?

---

<div class="post-metadata">

**Author:** ![stefanmz7](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stefanmz7](https://discourse.processing.org/u/stefanmz7)\
**Post date:** [November 6, 2021, 2:31am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/3 "2021-11-06T02:31:42Z")

</div>

multiple calls to rect()

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 6, 2021, 2:33am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/4 "2021-11-06T02:33:07Z")

</div>

Are they numbered in any way. How do you know which one was hit?

---

<div class="post-metadata">

**Author:** ![stefanmz7](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stefanmz7](https://discourse.processing.org/u/stefanmz7)\
**Post date:** [November 6, 2021, 2:37am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/5 "2021-11-06T02:37:13Z")

</div>

yeah,I use vectors for the coords of the rectangles and I name them brick1,brick2 so on

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 6, 2021, 2:38am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/6 "2021-11-06T02:38:59Z")

</div>

Setting all the parameters to zero doesn’t work? You are not allocating memory for each brick so perhaps that would work?

---

<div class="post-metadata">

**Author:** ![stefanmz7](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stefanmz7](https://discourse.processing.org/u/stefanmz7)\
**Post date:** [November 6, 2021, 2:41am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/7 "2021-11-06T02:41:36Z")

</div>

so I do brick1.set(0,0) for example so it teleports in the corner and then I do w1,h1=0 so the width and height are also 0 and it disappears but for some reason it still counts as being in the program,the ball either bounces off of it if I don’t move it in the corner,or if I move it,it sometimes gets stuck on it and glitches out. Especially if I put multiple rectangles in the same corner

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 6, 2021, 2:48am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/8 "2021-11-06T02:48:18Z")

</div>

The only thing I can think of that might work is .remove(), but your bricks would have to be in a list. Other forum members might have a better suggestion.

---

<div class="post-metadata">

**Author:** ![stefanmz7](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@stefanmz7](https://discourse.processing.org/u/stefanmz7)\
**Post date:** [November 6, 2021, 2:54am UTC](https://discourse.processing.org/t/erase-a-rectangle/33352/9 "2021-11-06T02:54:54Z")

</div>

I think I actually found the solution,I basically sent them to -500,-500 somewhere in the void out of the window
