Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Processing `fill()` with alpha never completely fill?

Tags:

processing

Let's say we have the following code:

void setup() {
    background(0);
    size(200, 200);
    fill(255);        
    rect(75, 75, 50, 50);
}  

void draw() {
    fill(0, 2);
    rect(0, 0, width, height);
}

Even after waiting 'forever,' the white 50x50 rectangle is still visible, albeit faded. Why doesn't the fill(0, 2) eventually cover this up?

I suppose this question is twofold:

  • Why doesn't it eventually fade to black, as in why does drawing another dark rectangle on top of the white one not erase it eventually (I'm thinking along the lines of putting tinted windows over each other; eventually even the brightest light won't shine through), and
  • Why doesn't it eventually fade to black, as in why is this the behavior intended by the Processing community?
like image 774
j6m8 Avatar asked Mar 11 '14 06:03

j6m8


People also ask

How does fill work in processing?

fill() Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color depending on the current colorMode() (the default color space is RGB, with each value in the range from 0 to 255).

What is Alpha in processing?

What is Alpha Processing and what types are there? Alpha processing was the world's first technical formula for reproducing 16-bit data in 20-bit quality. The ALPHA processor interpolates the data recorded on the original CD so that the waveform is more natural.

How do you color a shape in processing?

By adding the stroke() and fill() functions before something is drawn, we can set the color of any given shape. There is also the function background(), which sets a background color for the window. Here's an example. Stroke or fill can be eliminated with the functions: noStroke() and noFill().


1 Answers

Here's a post explaining what's going on: http://processing.org/discourse/beta/num_1138703939.html

Basically, the problem is that Processing stores colors as ints, but takes float arguments. When combining colors, Processing rounds the floats to ints. In your case, your color is getting stuck at a value of 63, 63, 63 because at that point the blending is too slight to make a difference that is detectable after rounding.

The solution is to do the fading from the source, not by overlaying an alpha color over top.

like image 118
Kevin Workman Avatar answered Oct 06 '22 01:10

Kevin Workman