# Masking several polygons

**URL:** <https://discourse.processing.org/t/masking-several-polygons/35718>\
**Category:** Beginners\
**Created:** [March 13, 2022, 6:54pm UTC](https://discourse.processing.org/t/masking-several-polygons/35718 "2022-03-13T18:54:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardgarcia](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@ricardgarcia](https://discourse.processing.org/u/ricardgarcia)\
**Post date:** [March 13, 2022, 6:54pm UTC](https://discourse.processing.org/t/masking-several-polygons/35718/1 "2022-03-13T18:54:47Z")

</div>

Hey there,

I’m a bit new to creative coding and even more using p5js. I’m currently working on a sketch in which I need to mask a letter several times (several rows and a cut letter inside) in the canvas.

I was approaching this sketch but all of a sudden I saw there’s no way to mask polygons, only images. I’ve tried to mask an image with the letter with `createGraphics()` but apparently I can only have one of these un a sketch and I couldn’t make it work.

How can we mask several polygons (many rows)?

Thanks!

---

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [March 14, 2022, 8:17pm UTC](https://discourse.processing.org/t/masking-several-polygons/35718/2 "2022-03-14T20:17:07Z")

</div>

You can use [`erase()`](https://p5js.org/reference/#/p5/erase) and `noErase()` with arbitrary shape drawing functions in order to remove shapes from a `p5.Graphics` buffer (however if you prefer to specify what shapes to keep rather that which to remove then this is less helpful). Additionally you can use `drawingContext.globalCompositeOperation = 'destination-in';` to perform the equivalent of `mask()` on either a `p5.Graphics` buffer or on the main canvas (in this mode the subsequent drawing instructions will effectively just replace the alpha channel of what is already there). Lastly you can get an image representation of a `p5.Graphics` buffer using the `get()` function, at which point you can use the built in `mask()` function.

---

<div class="post-metadata">

**Author:** ![ricardgarcia](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@ricardgarcia](https://discourse.processing.org/u/ricardgarcia)\
**Post date:** [March 16, 2022, 8:02am UTC](https://discourse.processing.org/t/masking-several-polygons/35718/3 "2022-03-16T08:02:38Z")

</div>

Cool! Thank you so much for this detailed answer, Paul. I’ll definitely go for the second option since it sounds more like what I need.

Thank you so much!
