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 › determination of pixels and following commands
Page Index Toggle Pages: 1
determination of pixels and following commands (Read 517 times)
determination of pixels and following commands
Sep 13th, 2007, 2:41pm
 
Hi!
hopefully someone can help me with this, i am sure it will be easy ... i am just an amateur.

1. identify a pixel, eg. say pixel number 1
2. identify if this pixel is either black or white etc.
3. if the pixel is black for example, draw an determined drawing originating at that pixel, if white go on to the next programmed pixel

hopefully someone can understand this and help me out a little, anything would be appreciated

THANKS
Re: determination of pixels and following commands
Reply #1 - Sep 13th, 2007, 4:03pm
 
go to the reference:
http://processing.org/reference/index.html

everything under Color -> Creating & Reading is for you.

say you want to load an image (bw-bitmap) and act upon it's pixels:
Code:

PImage myImage;
void setup(){
   size(200,200);
   myImage = loadImage("myImage.gif");
   // drag image into processing text-window then it
   // will be copied to <sketch-path>/data/myImage.jpg
}
void draw()
{
   myImage.loadPixels(); // not sure this is needed
   for ( int x = 0; x< myImage.width; x++ )
   {
       for ( int y = 0; y < myImage.height; y++ )
       {
           int i = y * myImage.width + x;
           
           if ( myImage.pixels[i] == color(0) ) {
               // black
               ellipse(x,y,10,10);
           }
           else
           {
               // white
           }
       }
   }
}


F
Page Index Toggle Pages: 1