Getting an alpha mask to stick with PGraphics
in
Core Library Questions
•
1 year ago
Hi,
I'm trying to allow the user to draw over an image so that it reveals partially transparent camera video underneath. I'm able to get an ellipse to show up that can be dragged around, but I want to make it so that the ellipses "stick" and are drawn in a continuous line (that also stays there when the user releases the mouse). Here is my code:
- import processing.video.*;
- Capture cam;
- PImage window1;
- PGraphics topLayer;
- void setup() {
- size(700, 500);
- cam = new Capture(this, 700, 500);
- window1 = loadImage("window1.png");
- topLayer = createGraphics(width, height, P2D);
- }
- void draw() {
- if (cam.available()) {
- cam.read();
- }
- image(window1, 0, 0);
- if (mousePressed) {
- topLayer.beginDraw();
- topLayer.background(0, 0);
- topLayer.fill(128);
- topLayer.stroke(128);
- topLayer.strokeWeight(10);
- topLayer.ellipse(mouseX, mouseY, 100, 100);
- topLayer.endDraw();
- // Camera feed will be unmasked where user paints
- cam.mask(topLayer);
- image(cam, 0, 0);
- }
- }
1