Is there a tag for super beginners? I currently have a simple sketch that uses a mask to reveal an image below another. For some reason once I convert to p5.js, nothing shows up. I think it might have to do with the beginDraw and endDraw, but I am not sure how to fix this…
PGraphics mask;
PImage bgImage, topImage;
void setup()
{
size(1080, 720);
bgImage = loadImage("Gradient_Test.jpg");
bgImage.resize(width, height);
topImage = loadImage("Black Rectangle.jpg");
topImage.resize(width, height);
mask = createGraphics(width, height);
mask.beginDraw();
mask.background(0);
mask.stroke(255);
mask.strokeWeight(10);
mask.fill(255);
mask.endDraw();
}
void draw()
{
background(0);
mask.beginDraw();
if (mousePressed)
mask.line(mouseX, mouseY, pmouseX, pmouseY);
mask.endDraw();
image(topImage, 0, 0, width, height);
bgImage.mask(mask);
image(bgImage, 0, 0, width, height);
}
This is the p5.js I have so far:
function setup()
{
let bgImage, topImage;
createCanvas(1080, 720);
bgImage = loadImage('Gradient_Test.jpg');
topImage = loadImage('Black Rectangle.jpg');
mask = createGraphics(width, height);
mask.beginDraw();
mask.background(0);
mask.smooth();
mask.stroke(255);
mask.strokeWeight(10);
mask.fill(255);
mask.endDraw();
}
function draw()
{
background(0);
mask.beginDraw();
if (mouseIsPressed) {
mask.line(mouseX, mouseY, pmouseX, pmouseY);
}
mask.endDraw();
image(topImage, 0, 0, width, height);
bgImage.mask(mask);
image(bgImage, 0, 0, width, height);
}
I really appreciate any help!