Bug 1185 : Alpha() strange behaviour on very low numbers
Last modified: 2009-03-03 06:20




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

 

Reporter:
mathias
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-03-02 14:27
In this code:

float opa = 0.8;

void setup(){
size(500,500);
smooth();
background(0);
}

void draw(){
noStroke();
fill(0, opa);
rect(0,0,width,height);
float n1 = mouseY-pmouseY;
float n2 = mouseX-pmouseX;
float b1 = norm(n1, -50, 50);
float b2 = norm(n2, -50, 50);

stroke(random(220,255), random(100,255));
float y1 = (random(-n1,n1))*6;
float y2 = (random(-n2,n2))*6;
rect(mouseX+y2,mouseY+y1,5+b1,5+b2);

//mkusk.com
}

there is no blending going on. However if you set it like this, alpha value equal 1, something
very different happen.

float opa = 1;

void setup(){
size(500,500);
smooth();
background(0);
}

void draw(){
noStroke();
fill(0, opa);
rect(0,0,width,height);
float n1 = mouseY-pmouseY;
float n2 = mouseX-pmouseX;
float b1 = norm(n1, -50, 50);
float b2 = norm(n2, -50, 50);

stroke(random(220,255), random(100,255));
float y1 = (random(-n1,n1))*6;
float y2 = (random(-n2,n2))*6;
rect(mouseX+y2,mouseY+y1,5+b1,5+b2);

//mkusk
}

I dunno what it is, but now you know that its there.
Additional Comment #1 From mathias 2009-03-02 14:29
Sorry Fry.

Processing ver 1.0.1

Osx 10.5.6

Java 1.5
Additional Comment #2 From fry 2009-03-03 06:20
That's not a bug, that's math :)

Colors are stored as values between 0 and 255. If you have a value of 0.8,
that doesn't meet the threshold of 1.0, so when binned to 0 and 255, you
get 0. To fix this we'd have to use more than 8 bits of color per pixel,
storing the entire image as higher resolution than what's on the screen,
and then downsample it before drawing.