Using. img.get to retrieve color values

I am using the following code

let c = img.get(xPos,yPos);

to sample a color from a pixel of an image and it works brilliantly as I can then fill or stroke with the variable (c)

My question is how do I then make (c) use the transparency value, too? As it stands I think it samples the RGB values … but i would like to add the 4th transparency value and be able to make it random

Any suggestions would be greatly appreciated

Glen

Hello,

Start here and follow the trail of breadcrumbs (links):

https://p5js.org/reference/#/p5/set

:)

1 Like

Perfect, thank you … after trundling through the rabbit hole I eventually came up with the following solution

let c = img.get(xPos,yPos);
transcolor = color(c);
noStroke();
transcolor.setAlpha(50);
fill(transcolor);

Thank you for saving a heap of time

2 Likes