Mask a pattern inside a shape, using only PGraphics
in
Programming Questions
•
2 years ago
Hello all,
Just got this small problem I have been trying to work out.
I want to generate a pattern, in this example simple hatching lines, as a PGraphics obj and then mask them with a shape, currently a Rect, that is another PGraphics obj. I have been playing with blend() and a few things yet I haven't been able to get anything to work well.
Basically something to this likeness, is what I am trying to do:
Any ideas?
- PGraphics canvas;
- PGraphics pg;
- void setup() {
- size(500, 500,P2D);
- canvas = createGraphics(500, 500, P2D);
- pg = createGraphics(500, 500, P2D);
- pg.beginDraw();
- pg.background(0);
- pg.stroke(255);
- //pg.fill(255);
- pg.strokeWeight(2);
- for(int i = 0; i < 800; i = i + 10){
- pg.line(0+i, 0, 500+i, 500);
- pg.line(0-i, 0, 500, 500+i);
- }
- pg.endDraw();
- canvas.beginDraw();
- canvas.background(0);
- canvas.noStroke();
- canvas.rect(width/2,height/2,200,200);
- canvas.blend(pg,0,0, width,height, 0,0,width,height,MULTIPLY);
- canvas.endDraw();
- }
- void draw() {
- image(canvas,0,0);
- }
2