p5.js - using mask() on createGraphics() object

I noticed that mask() does not work on an object created from createGraphics().

The code below does not work:

var img;
var mk;

function setup() {
    createCanvas(400, 400);

    img = createGraphics(200, 200);
    img.ellipse(100, 100, 100, 100);

    mk = createGraphics(200, 200);
    mk.rect(0, 0, 100, 100);

    img.mask(mk);
}

function draw() {
    background(200);
    image(img, 0, 0);
}

Then, is there a way to convert p5.Graphics to p5.Image object so that mask() method can be used?

Or, I wonder if there's other ways to apply the mask.

Tagged:

Answers

Sign In or Register to comment.