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 › conditionals question!
Page Index Toggle Pages: 1
conditionals question! (Read 435 times)
conditionals question!
May 30th, 2009, 6:32am
 
so what i want to do is make random circles apear in my canvas and depending on their position change color! i know how to do it in simple and regular shapes, but imagine i want it to form a logo? Code:
void setup(){
size(400,400);
}
void draw(){
float xpos = random(width);
float ypos = random(height);
if(xpos < 100 || xpos >300 || ypos < 100 || ypos >300 ){
fill (200,0,0);
}else{
fill(0,0,200);
}
ellipse(xpos,ypos, 10, 10);
}
something like this! is it possible to import a SVG logo and program something like, "if a collision exists change fill? or if its over that shape change fill? or do i have to list all single existing position on my logo and write in in if(xpos<100 ) and so on?
Re: conditionals question!
Reply #1 - May 30th, 2009, 8:15am
 
You can look at the color of the pixel at the draw coordinates (using get() for example) and depending on its color (or brightness, etc.), choose a fill color.
If you don't want to draw the initial shape, you can load it in a PImage and do the get() (or, here, the pixels[] method would be more efficient) from there.
Re: conditionals question!
Reply #2 - May 30th, 2009, 8:23am
 
well i didn't understand a bit but you gave me something to look for! thanks!
Page Index Toggle Pages: 1