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 › New Programmer. Fill Circular area with shapes.
Page Index Toggle Pages: 1
New Programmer. Fill Circular area with shapes. (Read 449 times)
New Programmer. Fill Circular area with shapes.
May 1st, 2009, 3:02pm
 
Hi, I've just started to learn processing, so my question is very, very simple.

I'm ramdomly filling an area with ellipses

Code:
  for(int i=1; i<200; i++){
   
   int pX = int(random(width));
   int pY = int(random(height));
   int escala = int(random (20));
   int rR = int(random(255));
   int rG = int(random(255));
   int rB = int(random(255));
   fill(rR, rG, rB);
   ellipse(pX, pY, escala, escala);
 }


but I want to restict this area to a circular area. Something similar to the image found here: universodeltarot.com/imagenesuniverso/constelacion.jpg

Thank for help!
Re: New Programmer. Fill Circular area with shapes.
Reply #1 - May 1st, 2009, 4:25pm
 
void setup()
{
 size(500,500);
}

void draw()
{
 int x = 0, y = 0;
 while(!insideCircle(x,y,width/2,height/2,width/3)){
   x = (int)random(width);
   y = (int)random(height);
 }
 int s = (int)random(10,45);
 noStroke();
 fill(random(255),random(255),random(255));
 ellipse(x,y,s,s);
}

boolean insideCircle(int x, int y, int cx, int cy, float cr)
{
 float d = sqrt(sq(x-cx)+sq(y-cy));
 return ( d < cr && d >= 0 )?true:false;
}
Page Index Toggle Pages: 1