# Method to 'fill' a non rectangular shape with a pattern

**URL:** https://discourse.processing.org/t/method-to-fill-a-non-rectangular-shape-with-a-pattern/35946
**Category:** Coding Questions
**Created:** [March 26, 2022, 7:05am UTC](https://discourse.processing.org/t/method-to-fill-a-non-rectangular-shape-with-a-pattern/35946 "2022-03-26T07:05:51Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 26, 2022, 9:59am UTC](https://discourse.processing.org/t/method-to-fill-a-non-rectangular-shape-with-a-pattern/35946/2 "2022-03-26T09:59:29Z")

</div>

Hello @GoodJuJu,

> [@GoodJuJu](#):
>
> Does anyone know of a way to identify a shape and use it as some kind of mask?

A related topic:

> [@Filling a PShape](https://discourse.processing.org/t/filling-a-pshape/33644):
>
> I’d like to be able to generate an arbitrary shape and fill it with a simple pattern. Drawing the shape is easy - something like this would do: void setup(){ size(650, 650, P3D); smooth(8); translate(200, 200); beginShape(); vertex(random(100),random(100)); vertex(random(100), random(100)); vertex(random(100), random(100)); vertex(random(100),random(100)); endShape(); } However, if I wanted to fill in that shape with small blue strokes of circles, I would have no …

I modified code above to have 2 _PGraphics_ and did this:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b66407ff3d57c066629e49022a6d53004a9291a0.png)

`pg2.mask(pg1);`

The resources here will have more details:  
[https://processing.org/](https://processing.org/)

References:

- [https://processing.org/reference/PImage.html](https://processing.org/reference/PImage.html)
- [https://processing.org/reference/PImage\_mask\_.html](https://processing.org/reference/PImage_mask_.html)
- [https://processing.org/reference/texture\_.html](https://processing.org/reference/texture_.html)
- See tutorials on _PShapes_ and _Images and Pixels_

`:)`

---

_[View the full topic](https://discourse.processing.org/t/method-to-fill-a-non-rectangular-shape-with-a-pattern/35946)._
