Logical operators with rgb color numbers
in
Programming Questions
•
1 years ago
Hi,
I am trying to compare colors of a picture pixels.
I want to write a script where I could compare different pixel colors.
Everything is working except this part:
Processing is drawing only the last shape of the script on every pixel and don't compare pixel colors.
As a result, I would like to ask how to compare different pixel colors correctly.
According to this script I want to get black rectangle if a pixel is white, another shape if (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) and another shape if if ( (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) )
int[] datax = new int[64];
for( int x = 0; x < datax.length; x++ ){
datax[x] = 10 * x;
}
int[] datay = new int[48];
for( int y = 0; y < datay.length; y++ ){
datay[y] = 10 * y;
}
for (int x= 0; x < datax.length; x++) {
for (int y=0; y <datay.length; y++) {
color cp1 = get(datax[x], datay[y]);
fill(cp1);
if ( (cp1 == color(255, 255, 255)) || (cp1 == color(255, 255, 255)) ){
noStroke();
fill(0,0,0) ;
rect(datax[x], datay[y], 10, 10);
rect( datax[x],datay[y], 1, 1);
}
noStroke() ;
fill(0,0,0) ;
if ( (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) ){
rect(datax[x], datay[y], 10, 10);
strokeWeight(1);
stroke(cp1);
beginShape();
vertex (datax[x]+1, datay[y]+9);
vertex (datax[x]+5, datay[y]+1);
vertex (datax[x]+9, datay[y]+9);
endShape();
beginShape();
vertex (datax[x]+3, datay[y]+5);
vertex (datax[x]+7, datay[y]+5);
endShape();
}
noStroke() ;
fill(0,0,0) ;
if ( (cp1 < color(255, 255, 255)) || (cp1 > color(100, 100, 100)) ){
rect(datax[x], datay[y], 10, 10);
strokeWeight(1);
stroke(cp1);
beginShape();
vertex (datax[x]+1, datay[y]+9);
vertex (datax[x]+5, datay[y]+1);
vertex (datax[x]+9, datay[y]+9);
endShape();
}
}
Thank you in advance.
I am trying to compare colors of a picture pixels.
I want to write a script where I could compare different pixel colors.
Everything is working except this part:
Processing is drawing only the last shape of the script on every pixel and don't compare pixel colors.
As a result, I would like to ask how to compare different pixel colors correctly.
According to this script I want to get black rectangle if a pixel is white, another shape if (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) and another shape if if ( (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) )
int[] datax = new int[64];
for( int x = 0; x < datax.length; x++ ){
datax[x] = 10 * x;
}
int[] datay = new int[48];
for( int y = 0; y < datay.length; y++ ){
datay[y] = 10 * y;
}
for (int x= 0; x < datax.length; x++) {
for (int y=0; y <datay.length; y++) {
color cp1 = get(datax[x], datay[y]);
fill(cp1);
if ( (cp1 == color(255, 255, 255)) || (cp1 == color(255, 255, 255)) ){
noStroke();
fill(0,0,0) ;
rect(datax[x], datay[y], 10, 10);
rect( datax[x],datay[y], 1, 1);
}
noStroke() ;
fill(0,0,0) ;
if ( (cp1 > color(0, 0, 0)) || (cp1 < color(100, 100, 100)) ){
rect(datax[x], datay[y], 10, 10);
strokeWeight(1);
stroke(cp1);
beginShape();
vertex (datax[x]+1, datay[y]+9);
vertex (datax[x]+5, datay[y]+1);
vertex (datax[x]+9, datay[y]+9);
endShape();
beginShape();
vertex (datax[x]+3, datay[y]+5);
vertex (datax[x]+7, datay[y]+5);
endShape();
}
noStroke() ;
fill(0,0,0) ;
if ( (cp1 < color(255, 255, 255)) || (cp1 > color(100, 100, 100)) ){
rect(datax[x], datay[y], 10, 10);
strokeWeight(1);
stroke(cp1);
beginShape();
vertex (datax[x]+1, datay[y]+9);
vertex (datax[x]+5, datay[y]+1);
vertex (datax[x]+9, datay[y]+9);
endShape();
}
}
Thank you in advance.
1