Screen limits with random points

Hi there! I have this amazing Code as a polygon generator. It is really useful for me in order yo create random shapes. Now I want to draw polygons inside the screen, because ofently they appear out of It, how could I do something like that?

Thanks

void setup() {
  noFill();
  stroke(255);
  strokeWeight(2);
  background(0);
  drawMoreRandomQuad(random(width), random(height), 200,400);
}


void draw() {
  
}


void drawMoreRandomQuad(float x, float y, float minSize, float maxSize) 
{  
  float startAngle = random(HALF_PI); 
  float angle = startAngle;
  
  beginShape();
  for (int i = 0; i < 6; i++) {
    float r = random(minSize, maxSize); 
    float vx = x + r * cos(angle); 
    float vy = y + r * sin(angle);
    vertex(vx, vy);
    
    
    angle += random(0, min(startAngle + TWO_PI - angle, PI));
  }
  endShape(CLOSE);
}

first line in setup() should be size() where you set width and height of the window

since the radius makes the figure bigger than its x,y position

so

  drawMoreRandomQuad(random(width), random(height), 200,400);

could be

  drawMoreRandomQuad(random(100,width-100), random(200,height-200), 200,400);
2 Likes