We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › 2 questions regarding color of pixel
Page Index Toggle Pages: 1
2 questions regarding color of pixel? (Read 679 times)
2 questions regarding color of pixel?
Apr 22nd, 2010, 12:20pm
 
Hi all

I am running a project and encountered some problems related to pixels. Can anyone help me?

Question 1: how to remove a color from a pixel?

pixel[1] = noFill();  // remove  its color
updatePixels();

Question 2: how to check if a pixel has no color?

if (pixel[1] is empty){
  // do this...
}

warm regards
P
Re: 2 questions regarding color of pixel?
Reply #1 - Apr 22nd, 2010, 8:43pm
 
Pixels always have a colour...I guess you want to check if the colour is the same as the background....
Re: 2 questions regarding color of pixel?
Reply #2 - Apr 22nd, 2010, 9:55pm
 
I wrote a simple example.... click to draw in white, press a key to change the background colour:

Code:

color backg = color(0, 0, 0);

void setup()
{
size(400,400);
background(backg);
strokeWeight(3);
stroke(255,255,255);
}

void draw()
{

}

void mouseDragged()
{
line(pmouseX, pmouseY, mouseX, mouseY);
}

void keyPressed()
{
color c = color(random(255), random(255), random(255));
loadPixels();
for(int i=0; i<pixels.length; i++)
{
if(pixels[i]==backg) pixels[i]=c;
}
updatePixels();
backg=c;
}
Page Index Toggle Pages: 1