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 › reading an image; drawing a cross
Page Index Toggle Pages: 1
reading an image; drawing a cross (Read 718 times)
reading an image; drawing a cross
Oct 27th, 2007, 8:23am
 
ok...
so i really have no idea how to do any scripting but have a uni assignment due on it so i desperately need help!!!

at this stage i am looking to initially begin with a grid of crosses ...
the cross hopefully will look like this;
size (600,600);
background (255);
noFill ();
stroke (222,45,45);


line (50, 275, 200, 275);
line (200,275,200,325);
line (200,325,50,325);
line (50,325,50,275);

line (275,50,325,50);
line (325,50,325,200);
line (325,200,275,200);
line (275,200,275,50);

line (550,275,550,325);
line (400,275,400,325);
line (550,275,400,275);
line (550,325,400,325);

line (275,550,275,400);
line (325,550,325,400);
line (275,550,325,550);
line (275,400,325,400);
...
but this shape will hopefully be in a grid of say one cross the size of 10 pixels every 30 pixels apart...
i have this code for kind of this i think;
void setup() {

 size(400, 400);
 background(255);

 for (int x = 15; x < width; x+= 30) {
   for (int y = 15; y < height; y+= 30) {
drawCross(x, y);
   }
 }

}

// draw a cross at (x, y) :
void drawCross(int x, int y) {
 line(x-5, y, x+5, y);
 line(x, y-5, x, y+5);
}

but then i want it to be placed against an image that is posterized to two colours (black and white) and if the pixel or pixels are read against the black then they are to be deleted...
i have a code at the moment in which I THINK it is reading the image and when the pixel it is white it draws an ecclipse;
PImage polarfleece;
void setup (){
size (600,600);
polarfleece =loadImage("polarfleece.JPG");
image(polarfleece, 0, 0);
filter(GRAY);
filter(POSTERIZE, 2);


}  
 
void draw ()
{  
   polarfleece.loadPixels ();  
   for (int x = 0; x< polarfleece.width; x++)  
   {  
  for (int y=0; y< polarfleece.height; y++)  
  {  
 int i = (y * polarfleece.width + x);  
 if (polarfleece.pixels [i] == color(255) ) {  
ellipse (x,y,40,40) ;  
 }  
 else if (polarfleece.pixels [i] == color(0) ) {  
 }  
  }  
   }  
}
...
in saying that it doesnt seem to draw an ecclipse on every white pixel .. any enlightenment on this could be helpful as well...

SORRY THIS IS SO LONG. i am just terribly confused.
any help at all would be greatly appreciated
thanks
Re: reading an image; drawing a cross
Reply #1 - Oct 27th, 2007, 9:02am
 
hi. please tell me if this is what you want to do :

- display a black & white image
- draw crosses over it : if the pixels (of the image) are black, draw a white cross, else if the pixels are white, draw a black cross.

if not, could you be more precise, or show us an image of the result you expect?

by the way, I think looking at the reference could help :
http://processing.org/reference/get_.html and
http://processing.org/reference/set_.html
Re: reading an image; drawing a cross
Reply #2 - Oct 27th, 2007, 9:04am
 
kind of like that but more-so if the pixels are white display a black cross and if the pixels are black display no cross...
Page Index Toggle Pages: 1