We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is something like this even possible?
var m;
var i;
function setup() {
createCanvas(600,600)
m = createGraphics(600,600)
m.ellipse(m.width/2,m.height/2,50,50)
i = loadImage('unnamed.jpg')
}
function draw() {
i.mask(m)
image(i,0,0)
}
I get a
p5.js:14713 Uncaught TypeError: Cannot read property 'width' of undefined
error when I try this.
Answers
https://p5js.org/reference/#/p5/preload
https://forum.Processing.org/two/discussion/21981/p5-js-using-mask-on-creategraphics-object
shouldn't I be able to do something like this with get()
Im only getting errors when trying your suggestion of
( masked = original.get() ).mask(masker);
when using with a mix of a loadImage() and createGraphics()This is the idea, but it throws all sorts of errors :)
Have you actually paid attention to preload() is for?
Have you visited the online sketch mentioned on the other forum thread?
https://ThimbleProjects.org/gotoloop/97931/sketch.js
https://ThimbleProjects.org/gotoloop/97931
yes, I am aware of what preload does. As you can see from my first example, I got mixed up on the second! I've got to say, you should be able to pass the createGraphics() instance with a .get() straight into a mask() on the original image without having to get its pixels too. since loadImage() makes a p5.image and mask is a function on that, and get() returns a p5.image
this is a working code snippet for future reference for anyone.
also, thank you for your help! @GoToLoop