Skip to content
Advertisement

How to move ellipse filled with an image to mask similar background?

I am a super early user of coding from Italy. I came up with an idea to promote a company logo on their website and I almost reached the goal so I am sharing this problem.

The idea is to obtain a sort of clipping mask effect when the mouse/cursor move on the image I’ve made so far a code that does the work with a still ellipse.

When I set the position parameters of the ellipse as mouseX and mouseY the effect does not work if not just a bit of a glitch at the start. How can I make it work as intended?

Here you can find the link of what I have now: https://editor.p5js.org/francesco.ficini.designer/full/FLBuhggW-

Here the code:

JavaScript

Advertisement

Answer

The thing about the p5.Image.mask function is that it modifies the image that is being masked. Which means that any pixels that are cleared by the mask are gone for good. So if you want to dynamically change the mask you will need to make a copy of the original and re-apply the modified mask any time it changes.

Additionally you will want to avoid creating images and graphics objects in your draw() function because this can result in excessive memory allocation. Instead create a single set of graphics/images and re-use them.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement