Random rectangle

Hey guys. Im trying to make rectangles be inside a quad shape I’ve created. How do we do this. I would want them not to touch as well (like not overlap). I’ve though of using a Boolean or and array but I cant figure it out. Is there a way?

void setup(){
  //Space size
  size(800,800);
  background(255);
    stroke(0);
   strokeWeight(3);
  //no loop for draw
  //noLoop();
  
  //QUAD shape boundary
  
    quad(400,50,650,500,400,700,150,500);
  
}
 // Shape to build around/inside
 
 void draw(){

//for(int i=0; i<numLOOPS; i++){
  
 stroke(0);
 // A.position
 
 int x=round(random(0,width));
 int y=round(random(0,width));
 
 // B.random H/L size
 float rectH= random(20,150);
 float rectL= random(20,150);
 
 //C.Random Angle
 float rectAgl = random(PI/3);
 
   rotate(rectAgl);
   rect(x,y,rectH,rectL);
   

 

}


Here you can see how to do a boundary check with Polygons. If all 4 points of the rectangle lie either inside or outside, then it‘s not overlapping.

1 Like