# Screen limits with random points

**URL:** <https://discourse.processing.org/t/screen-limits-with-random-points/40711>\
**Category:** Coding Questions\
**Created:** [January 25, 2023, 8:56pm UTC](https://discourse.processing.org/t/screen-limits-with-random-points/40711 "2023-01-25T20:56:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)\
**Post date:** [January 25, 2023, 8:56pm UTC](https://discourse.processing.org/t/screen-limits-with-random-points/40711/1 "2023-01-25T20:56:38Z")

</div>

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

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 25, 2023, 9:05pm UTC](https://discourse.processing.org/t/screen-limits-with-random-points/40711/2 "2023-01-25T21:05:33Z")

</div>

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**

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

```

could be

```auto
  drawMoreRandomQuad(random(100,width-100), random(200,height-200), 200,400);

```
