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 › Use BW image map as source for creation
Page Index Toggle Pages: 1
Use BW image map as source for creation (Read 529 times)
Use BW image map as source for creation
Dec 6th, 2008, 12:15am
 
Just to explain it really simple:  i want a black and white image to use as source for the creation of objects. Lets say, i have a 300x300 sketch and a 300x300 BW gif in my data folder. Now i want to draw circles exactly at the point where the source map is black.

I couldnt find some good excamples but i know they exist. Alot of people use this to recreat pictures and also color the shapes they draw corresponding to the image...

Thanks for your help!
Re: Use BW image map as source for creation
Reply #1 - Dec 6th, 2008, 1:29pm
 
you loop for all the pixels of the image and when you find a black pixel you draw a circle

ArrayList circlePos;

circlePos = new ArrayList();  // ill keep a list of all the black pixel's position in an array

int jidx = 0;
for( int j=0; j<img.height; j++ )
{
 jidx = j * img.width
 for( int i=0; i<img.width; i++ )
 {
   // if current pixel is black, save position to our array
   if( red(img.pixels[jidx+i]) == 0 )
     circlePos.add( new Vector3( i, j, 0 );
 }
}

now you have an array of points. those points are every black pixel you have in your image. just go thru the array and draw a circle at everypoint.
Re: Use BW image map as source for creation
Reply #2 - Dec 6th, 2008, 3:38pm
 
Thank you!
Re: Use BW image map as source for creation
Reply #3 - Dec 6th, 2008, 7:02pm
 
Two little improvements: you can increase the increment of the loops, to be equal to the diameter of the circles, so spacing them a bit.
And it is enough to test if pixels[n] isn't zero (or alpha value?), might be faster than extracting the red component.
Re: Use BW image map as source for creation
Reply #4 - Dec 6th, 2008, 7:14pm
 
phillo, thanks for ur sharp eye =)
but for a simple static image this would be pre-calc'ed =)
Re: Use BW image map as source for creation
Reply #5 - Dec 6th, 2008, 7:26pm
 
seems to work... thanks again to both of you...

first tests...

http://www.dec32.de/public/p5img1.jpg
http://www.dec32.de/public/p5img2.jpg
Re: Use BW image map as source for creation
Reply #6 - Dec 9th, 2008, 7:20pm
 
Hi!
I dont know if your definition of 3D is like this, but this height map I did (emulating some Scriptographer effect) may help.
http://www.flickr.com/photos/72209952@N00/2218491686/
the script is attached there, but feel free to post back code if you have issues.

jegb
Page Index Toggle Pages: 1