-
-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
Relevant sub-area for this feature?
Core/Environment/Rendering
Feature details
Feature description
Add beginClip()
and endClip()
to define clipping masks using drawing commands. Shapes drawn between these calls become the mask. An optional invert flag enables inverse masking.
Benefits
- More intuitive and less verbose than
mask()
- Matches p5.js API and reduces cognitive load when switching from one to the other
Challenges
- Not sure
Additional context
See https://p5js.org/reference/p5/beginClip/
Example code
This mask()
code...
// Create pattern graphics
pattern = createGraphics(width, height);
pattern.beginDraw();
pattern.background(255);
pattern.stroke(0);
pattern.strokeWeight(2);
for (int x = 0; x < width; x += 10) {
pattern.line(x, 0, x, height);
}
pattern.endDraw();
// Create mask graphics (white circle on black)
maskImg = createGraphics(width, height);
maskImg.beginDraw();
maskImg.background(0);
maskImg.noStroke();
maskImg.fill(255);
maskImg.ellipse(width/2, height/2, 200, 200);
maskImg.endDraw();
// Apply mask to pattern
pattern.mask(maskImg);
... becomes this using beginClip()
/endClip()
:
// Define clipping region
beginClip();
ellipse(width/2, height/2, 200, 200);
endClip();
// Draw pattern inside the clip
stroke(0);
strokeWeight(2);
for (int x = 0; x < width; x += 10) {
line(x, 0, x, height);
}
Would you like to help implement this feature?
No, I’m just suggesting the feature
hx2A and Stefterv
Metadata
Metadata
Assignees
Labels
No labels