# Tengo una duda enorme

**URL:** https://discourse.processing.org/t/tengo-una-duda-enorme/18816
**Category:** Español
**Tags:** homework
**Created:** [March 19, 2020, 7:48pm UTC](https://discourse.processing.org/t/tengo-una-duda-enorme/18816 "2020-03-19T19:48:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Vallano](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@Vallano](https://discourse.processing.org/u/Vallano)
#### Post date: [March 19, 2020, 7:48pm UTC](https://discourse.processing.org/t/tengo-una-duda-enorme/18816/1 "2020-03-19T19:48:47Z")

</div>

en su función draw() SOLO dibujará cuadrados si su posición esta dentro de un círculo con posición central de radio 100 pixels:

Dos métodos:

- Generar la posición del cuadrado de forma aleatoria y luego “decidir” si pintarlo o no según la condición arriba indicada.

- Generar la posición de forma aleatoria pero ya dentro del circulo permitido.

Mi duda es ¿como generar la posición aleatoria del cuadrado en el círculo de 100 pixels?

---

<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: [March 19, 2020, 7:56pm UTC](https://discourse.processing.org/t/tengo-una-duda-enorme/18816/2 "2020-03-19T19:56:36Z")

</div>

Hello,

and welcome to the processing forum! Great to have you here.

To find a random position use cos and sin and make a random angle and a random radius for it.

see [https://www.processing.org/tutorials/trig](https://www.processing.org/tutorials/trig)

Chrisir

---

<div class="post-metadata">

### Author: ![Vallano](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@Vallano](https://discourse.processing.org/u/Vallano)
#### Post date: [March 19, 2020, 8:34pm UTC](https://discourse.processing.org/t/tengo-una-duda-enorme/18816/3 "2020-03-19T20:34:57Z")

</div>

![IMG_20200319_213129](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d4f30e93091adac7b2f2a569a79392e2d9d08ec2.jpeg)  
Okay chriseir hoy can write how yo put the ramdom rect un that ellipse

---

<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: [March 19, 2020, 9:11pm UTC](https://discourse.processing.org/t/tengo-una-duda-enorme/18816/4 "2020-03-19T21:11:37Z")

</div>

```auto
  rect(x,y, 
     12,12);

```

calculate x and y with cos and sin like explained in the link

I am sorry, we are not allowed to help with homework. It would be considered cheating you know.

We can help you but show your attempt.

**Remark**

At the moment I speak about : Generar la posición de forma aleatoria pero ya dentro del circulo permitido, not the first way.

For the first way: make a for loop (see reference: [https://www.processing.org/reference/](https://www.processing.org/reference/))  
and generate x,y randomly (see random()). Check the distance to your center with the function dist() (see reference: [https://www.processing.org/reference/](https://www.processing.org/reference/)).  
If the dist is smaller than 100, draw the rect.

Chrisir
