# Contour rectangle with an ellipse

**URL:** <https://discourse.processing.org/t/contour-rectangle-with-an-ellipse/30408>\
**Category:** Coding Questions\
**Created:** [June 1, 2021, 8:53am UTC](https://discourse.processing.org/t/contour-rectangle-with-an-ellipse/30408 "2021-06-01T08:53:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 1, 2021, 3:54pm UTC](https://discourse.processing.org/t/contour-rectangle-with-an-ellipse/30408/2 "2021-06-01T15:54:16Z")

</div>

Hi @guidoDimasi ,

Welcome to the forum! 😉

You can use the `PImage.mask()` function to do that :

> **[mask() / Reference](https://processing.org/reference/PImage_mask_.html)**
>
> Masks part of an image from displaying by loading another image and using it as an alpha channel. This mask image should only contain grayscale data, but only the blue color channel is used. The mask …

> Masks part of an image from displaying by loading another image and using it as an alpha channel. This mask image should only contain grayscale data, but only the blue color channel is used. The mask image needs to be the same size as the image to which it is applied.

You can also check a previous message I did on a masking technique with PGraphics :

> [@blendMode and transparency](https://discourse.processing.org/t/blendmode-and-transparency/27781/6):
>
> Hi again! Thanks @behreajj for the insight on how to do this with Java AWT! wink Just for fun, here’s a method that support arbitrary shapes by using a mask (of black pixels) that we then fill with the gradient using PGraphics : /\*\* \* Draw a rhombus shape mask of size s \*/ void rhombusMask(PGraphics mask, int s) { // It's important to fill it with black mask.beginDraw(); mask.fill(0); mask.noStroke(); mask.translate(mask.width / 2, mask.height / 2 - s); mask.beginShap…

---

_[View the full topic](https://discourse.processing.org/t/contour-rectangle-with-an-ellipse/30408)._
