processing / processing

Source code for the Processing Core and Development Environment (PDE)
http://processing.org
Other
6.48k stars 1.5k forks source link

color(0, 0, 0, 0) should be transparent but isn't #3441

Closed Grahack closed 9 years ago

Grahack commented 9 years ago

Or am I missing something?

Thanks.

REAS commented 9 years ago

We need to know which version of Processing, OS, and renderer. Please provide this information and a short code example to test.

tillnagel commented 9 years ago

Might be related to #2339.

See also https://github.com/processing/processing/wiki/Troubleshooting#color0-0-0-0-is-black

clankill3r commented 9 years ago

may also be related to: https://github.com/processing/processing/issues/3317 which is fixed for next processing

Grahack commented 9 years ago

Sorry for the lack of details. It happens with processing.js 1.4.8 and processing 2.2.1 (on my Debian box processing-java says 0227).

Here is a snippet:

void setup() {
  size(200, 200);
  fill(color(0, 0, 0, 0));
  rect(50, 50, 100, 100);
}

Strangely enough, color(1, 0, 0, 0) is transparent.

See it live here: http://www.openprocessing.org/sketch/204197

scotthmurray commented 9 years ago

processing.js is a separate project that is no longer being developed, and we can't support it here. See: processingjs.org

The open processing link you sent actually looks correct to me: the rect is transparent.

Also, Processing 2.2.1 is not supported at this point; please test with the latest 3.0 alpha. We want to fix things for 3.0.

Why are you using color() to calculate a color value for fill()? I think you're right that this should technically work, but instead of this:

  fill(color(0, 0, 0, 0));

why not use this?

  fill(0, 0, 0, 0);

For example, in the latest 3.0 alpha, this renders as expected (transparent rect):

void setup() {
  size(200, 200);
  fill(0, 0, 0, 0);
  rect(50, 50, 100, 100);
}
aengelke commented 9 years ago

Actually, this is the problem described here: https://github.com/processing/processing/wiki/Troubleshooting#color0-0-0-0-is-black

The reason this doesn't work is that color(0, 0, 0, 0) creates an int that is simply '0'. Which means that fill(color(0, 0, 0, 0)) is the same as fill(0), which is...black. This is a problem of 'color' not being a real type, but just an int, plus the fact that we overload fill() to use both int/color for a color, and also an int for a gray. Since this is unlikely to be fixed anytime soon (if ever) ...

scotthmurray commented 9 years ago

Thanks, @aengelke.

Grahack commented 9 years ago

Thanks all, and sorry for the noise. Happy hacking!

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.