We are about to switch to a new forum software. Until then we have removed the registration on this forum.
heya,
I have a number of visualisations being drawn by my sketch and want a way to grab the pixels that are being drawn and add noise / assign a random value for the alpha channel but maintain the same colour. I have tried using getPixels() but I can't keep the original color no matter what I try.
Any suggestions would be great!
loadPixels();
for ( int i=0; i<pixels.length; i+=1) {
if (pixels[i] > color( 1 )) {
pixels[i] = color(random(360));
}
}
updatePixels();
Answers
it might be easier to add the noise before you draw, not as an after thought
when you stick with the after thought ; maybe noSmooth() helps you since it kills the anti-alias which might bug your pixels colorwise
Look at this line:
pixels[i] = color(random(360));
You're assigning a random gray value between 0 and 360 (which doesn't even make sense, since it should only go to 255).
Instead, you need to use the
color()
function with 2 arguments: a gray and an alpha. Something like this:pixels[i] = color(pixels[i], random(255));
Although, I'm not exactly sure what you hope to achieve by changing the alpha value of a grayscale pixel.
More info available in the reference: https://www.processing.org/reference/color_.html
You can also use
colorMode()
to alter the range of the colors.Perhaps you need
lerpColor()
.Didn't explain myself quite right, the image i have looks like the first and continually changes, I want to break up the pattern to look noisy, so it also needs to change, but maintaining the original colour.
There are a number of HSB colours selected from an array so it has to read the colour values from the pixels. I was expecting
pixels[i] = color(pixels[i], random(255));
to work but it just produces a white image...+- this: