This will slowly increase the from black to white . The image goes from (
0,0,0,0xff)
to (
1,1,1,0xff)
and eventually to (
0xff,0xff,0xff,0xff)
.
I have not been able to find a suitable way to slowly decrease the color from white to black. The SUBTRACT blend mode does not seem to work the way I'd expect. Any way I do it, it seems to clobber the alpha on the image, or go completely to black all at once. The method I have below is to filter(INVERT) the image, then draw white, then filter(INVERT) again. It works exactly as I'd like, but it's slow because the PGraphics has to be finalized twice.
Below I have a full and complete working example using this double invert method. I'd like to emulate this kind of result, but without all the inversion. I wonder if anyone has found a way to do this using a blendMode. Any help is appreciated.
/**
* Implement Additive and Subtractive blending
* by John Colosi
*
* Unfortunately, subtractive blending is unintuitive.
The results of drawing shapes with alpha are not entirely what I would expect. Say I draw white boxes over a black background as below:
White box (alpha = 50)
over
White box (alpha = 50)
over
Black background
I would expect one box to have a color of 50, and the next box to have a color of 100. That is, the alpha's are additive and if I layer 5 white boxes at alpha=50, then I would have the color 250. This isn't what I'm seeing. See the code and results below. You can see that the first box is close to my expectation at 49. But it trails off from there, and after 21 layers, it tops out at 245. It never actually gets to full white.
I've done some reading about Alpha blending, and I don't think this is a bug as such, but it doesn't meet my expectations. Is there a way to mimic my simpler additive blending approach? Is there a way to change the blending mode of the renderer? My way would certainly save some compute cycles :) Seems ashame for the renderer to be doing all these computations that really just make it more difficult to create things the way I'd like them.