Testing for overlap of circles
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             Hi Everyone,
            
            
Suppose I have the code shown at the bottom, which draws many circles at random on the screen (thank you drum whore for you effort in getting me that far). My question is:
            
How do I ensure that the image actually displayed does not have overlapping circles? (I am thinking, a trial and error process, but still, that needs to control for the position of each circle, right?)
            
PrintWriter positions;
int cycles = 100; //number of circles
            
            
void setup() {
size(600, 600);
smooth();
background(0);
noStroke();
fill(226);
  
            
positions = createWriter("positions.txt");
noLoop();
}
            
void draw() {
for (int i = 0; i < cycles; i++) {
int xLength = int(random(25,25));
int yHeight = int(random(25,25));
int xPos = int(random(0 + xLength, width - xLength));
int yPos = int(random(0 + yHeight, width - yHeight));
ellipse(xPos, yPos, xLength, yHeight);
positions.println(xLength + " " + yHeight + " " + xPos + " " + yPos);
}
positions.flush();
positions.close();
}
 
           
 
            
           Suppose I have the code shown at the bottom, which draws many circles at random on the screen (thank you drum whore for you effort in getting me that far). My question is:
How do I ensure that the image actually displayed does not have overlapping circles? (I am thinking, a trial and error process, but still, that needs to control for the position of each circle, right?)
PrintWriter positions;
int cycles = 100; //number of circles
void setup() {
size(600, 600);
smooth();
background(0);
noStroke();
fill(226);
positions = createWriter("positions.txt");
noLoop();
}
void draw() {
for (int i = 0; i < cycles; i++) {
int xLength = int(random(25,25));
int yHeight = int(random(25,25));
int xPos = int(random(0 + xLength, width - xLength));
int yPos = int(random(0 + yHeight, width - yHeight));
ellipse(xPos, yPos, xLength, yHeight);
positions.println(xLength + " " + yHeight + " " + xPos + " " + yPos);
}
positions.flush();
positions.close();
}
 
              
              1  
            
 
            