Bug 382 : color(0, 0, 0, 0) produces black
Last modified: 2006-11-05 14:40




Status:
RESOLVED
Resolution:
LATER -
Priority:
P2
Severity:
normal

 

Reporter:
Björn Roche
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2006-07-26 16:36
Alpha 0 should be transparent, 255 should be opaque, but in the code below 1 is transparent,
255 is opaque and 0 is also opaque.

void setup()
{
size( 100, 100 );
background( 255 );
fill( color( 0, 0, 0, 0 ) );
textFont( loadFont( "Georgia-48.vlw" ), 24 );
fill( color( 0, 0, 0, 0 ) );
text( "0", 0, 0, 50, 50 );
fill( color( 0, 0, 0, 1 ) );
text( "1", 0, 50, 50, 50 );
fill( color( 0, 0, 0, 64 ) );
text( "64", 50, 0, 50, 50 );
fill( color( 0, 0, 0, 127 ) );
text( "127", 50, 50, 50, 50 );
}
Additional Comment #1 From fry 2006-07-27 13:39
verified.. not sure what's up. use fill(0, 0, 0, 0) in the meantime, since
that seems to work correctly.
Additional Comment #2 From fry 2006-11-05 14:40
the reason this doesn't work is that color(0, 0, 0, 0) creates an int that
is simply '0'. so with fill(0), that evaluates to 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.

there are multiple workarounds:

1) use fill(0, 0, 0, 0)
2) fill(c, 0) where c = color(0, 0, 0);
3) color almostTransparent = color(0, 0, 0, 1);
4) color almostBlack = color(1, 1, 1, 0);

one of these workarounds should work for most any situation.

the root cause is the same problem behind bug #432.