I'm hoping this is a very straight forward question but I haven't been able to get to the bottom of it. I'm using a react-P5-wrapper to create my P5 canvas in react (https://github.com/slin12/react-p5-wrapper) and I want to apply a filter to an image, which I normally would do in P5 like image.filter(GRAY), however I can't get it to work when P5 is an instance in React.
My sketch function looks like
function sketch(p5) {
let hair;
p5.setup = () => {
p5.createCanvas(600, 600);
hair = p5.loadImage(~/localpath/hairURL);
}
p5.draw = () => {
p5.image(hair, 0, 0);
};
}
I would have thought I could do something as easy as p5.image(hair,0,0).filter(p5.GRAY); in my draw function, but that doesn't work. Gives me Uncaught TypeError: Cannot read properties of undefined (reading 'filter')
I could just use p5.filter(p5.GRAY); as a separate line in draw() - which works - however that applies the filter over the whole canvas, whereas I want to just apply it over one of the images. I will have multiple images and want to apply different filters to each one.
p5.image(hair,0 ,0).p5.filter(p5.GRAY) doesn't work either (thought I would try even if it didn't make much sense)
Any help is appreciated! Thanks