We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is it possible to make something like this (below), where the circular shape masks a rectangular shape? I tried this earlier today but I'm having trouble controlling it myself and wondering if there's a simpler way?
In the end I'm hoping to make a grid of shapes like that where the colors, width of rectangles, and number of rectangles varies. Thanks in advance for your help.
Answers
@Petros -- yes, it is possible.
Here is an example using an image masked by a triangle:
https://forum.processing.org/two/discussion/18819/how-to-copy-a-triangle-out-of-an-image
But you could instead use a rectangle and mask it with a circle. Same principle.
Thanks for the tip. I had seen that post but (I'm a total newbie to processing and definitely a non-programmer), couldn't figure out how to switch the photo to something like an orange rectangle (I guess?) for the background. I tried changing the photo variable (which I'm calling 'backing') to a rectangle, but I'm getting an error: "cannot convert from void to PImage". How do I use a color instead of a photo for the background of the masked object?
The original example shows loading a PImage photo layer, drawing a shape on a PGraphics mask layer, then combining.
Instead, draw something on a PGraphics image layer, then draw a shape on a PGraphics mask layer, then combine:
Yessss! That is killer thank you! I'm still trying to figure out how to keep the rectangle's position relative to the circle mask; I'll probably try dist() or something like that. Here it is modified a bit to use a circle in case anyone stumbles on this in the future:
forking this issue. i have created a PGraphics mask and another Pgraphics canvas and passed the masked result to a Surface Object. i also created antoher PGraphics to use as background. I find some issue that's a bit disturbing about the mask. sometimes it works, most of the time, some times it doesn't. when the new Surface is spawned above a pre-existing surface, sometimes it doesn't spawn with the programmed transparency.
here's an image without background. it has some of these flaws.
here's an image with canvas as background
i've read somewhere, don't rember where about rendering issues with this kind of transparency. can anyone enlight me on this issue?
tks
Can you share the code for the two triangle demo sketch please? I want to understand exactly what you are doing. First guess it looks like perhaps the masked second triangle is drawn into the surface with blendMode=REPLACE, which would set the pixels of the combined surface to the alpha portion of mask 2.
https://processing.org/reference/blendMode_.html
it looks like the supposedly transparent background is overwriting the non-transparent parts of the things behind it
i think there's a hint for this, try the following
or
@jeremydouglas i the specific case have, one PGraphic for Background: PGraphics bgG two arrays: PGraphics[] canvas, PGraphics[] mask three functions: void buildGradient, void buildMask and spawnSurface and one Surface Object that moves the masked PGraphics around
I'm initialing the arrays in their own function in setup and i'm not using any blendMode, other than default.
this is the Surface object
@koogs
hint(ENABLE_DEPTH_SORT);
works perfectly
Don't know if that's documented anywhere but i think it's forcing a sort of all the objects in the scene and drawing the furthest away first - painters' algorithm... It comes with a performance hit but it shouldn't be much.
in this case it works perfectly. i used it in another sketch that's more complex and this got heavy.
If you do all of your compositing in PGraphics then I believe that you don't need to use the hint because it supports alpha -- not sure if that will fix your performance issue, but worth trying.
@eduzal, I tried to run your code above but it seems to be missing something. Thanks anyway, I kind of get the idea by reading your code where to go next.