# Ways to Erase Part of a Line? (Preserve background)

**URL:** <https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207>\
**Category:** Coding Questions\
**Created:** [November 14, 2023, 4:01pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207 "2023-11-14T16:01:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cottonchipper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cottonchipper/32/10594_2.png) [@cottonchipper](https://discourse.processing.org/u/cottonchipper)\
**Post date:** [November 14, 2023, 4:01pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/1 "2023-11-14T16:01:49Z")

</div>

In Setup I’ve got a gradient being applied to the entire canvas.  
In Draw, I’m drawing some lines using a wide strokeWeight. I’d like to be able to erase part of the line and have the gradient below show through. Is there a way to erase only the line and not the underlying background that was drawn in Setup?

I haven’t tried yet, but I’m thinking I might be able to use createCanvas to draw the lines on a second canvas and erase them there.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 14, 2023, 4:37pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/2 "2023-11-14T16:37:29Z")

</div>

You can store the background in setup as PImage using get and show it as a background

Instead of deleting from the line can’t you draw the  
2 parts separately?

---

<div class="post-metadata">

**Author:** ![cottonchipper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cottonchipper/32/10594_2.png) [@cottonchipper](https://discourse.processing.org/u/cottonchipper)\
**Post date:** [November 14, 2023, 5:06pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/3 "2023-11-14T17:06:34Z")

</div>

What I’m doing is drawing lines with a wide strokeWidth and then erasing parts of the line, for example a shape cut out of one edge of the line.

---

<div class="post-metadata">

**Author:** ![cottonchipper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cottonchipper/32/10594_2.png) [@cottonchipper](https://discourse.processing.org/u/cottonchipper)\
**Post date:** [November 14, 2023, 5:43pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/4 "2023-11-14T17:43:06Z")

</div>

As in this example, creating the letter ‘B’ from lines and attempting to erase a triangular shape on the right edge, but the erase function erases the background too.

 ![IMG_8001](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/e/5e68c20c9895f3609f8ad0ed5760a1a7d1619f6b.jpeg)

---

<div class="post-metadata">

**Author:** ![cottonchipper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cottonchipper/32/10594_2.png) [@cottonchipper](https://discourse.processing.org/u/cottonchipper)\
**Post date:** [November 14, 2023, 6:22pm UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/5 "2023-11-14T18:22:33Z")

</div>

I decided to use createGraphics and draw the lines (and erasures) on a second canvas on top of the original canvas with the gradient. This works.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 15, 2023, 1:44am UTC](https://discourse.processing.org/t/ways-to-erase-part-of-a-line-preserve-background/43207/6 "2023-11-15T01:44:59Z")

</div>

Sorry, I was offline.

Good job!
