# \[SOLVED\] Simple Circle and rectangle code doubt

**URL:** <https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111>\
**Category:** Coding Questions\
**Created:** [October 4, 2018, 5:51am UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111 "2018-10-04T05:51:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerdboybi](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nerdboybi](https://discourse.processing.org/u/nerdboybi)\
**Post date:** [October 4, 2018, 5:51am UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111/1 "2018-10-04T05:51:44Z")

</div>

Hello, I want to write a program where as I move the mouse, the shapes moves and increase and decrease size at the same time depending on the mouseX location. I have done this for the rectangle but for a circle the only problem I am having the the position of it and it does not seem to work. I would like it to be at the specified position to matter what the size of the rectangle is. (always on the right edge of the rectangle and 40 pixels less that the bottom right edge. Please help me fix this.

```auto
int xPos;
int yPos;
int rectSize;
final int ORIGINAL_SIZE=300;

void setup()
{
  size(500,500);
}

void draw()
{
  background(0);
 
 moveSquare();
   drawSquare();
   
   

}

void drawSquare()
{
  
   final int RECT_WIDTH=300;
  final int RECT_HEIGHT=200;
  final int RECT_POS_X=xPos-RECT_WIDTH*rectSize/ORIGINAL_SIZE/2;
  final int RECT_POS_Y=yPos-RECT_HEIGHT*rectSize/ORIGINAL_SIZE/2;
  final int ELLIPSE_POS_X=RECT_POS_X+RECT_WIDTH;
  final int ELLIPSE_POS_Y=(RECT_POS_Y+RECT_HEIGHT)-40;
  final int ELLIPSE_SIZE=50;
  
  rect(RECT_POS_X,RECT_POS_Y,RECT_WIDTH*rectSize/ORIGINAL_SIZE,RECT_HEIGHT*rectSize/ORIGINAL_SIZE);
  ellipse(ELLIPSE_POS_X,ELLIPSE_POS_Y,ELLIPSE_SIZE*rectSize/ORIGINAL_SIZE,ELLIPSE_SIZE*rectSize/ORIGINAL_SIZE);
   
}

void moveSquare()

{
  xPos=mouseX;
  yPos=mouseY;
  rectSize=mouseX;
    
}

```

---

<div class="post-metadata">

**Author:** ![carbonne](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@carbonne](https://discourse.processing.org/u/carbonne)\
**Post date:** [October 4, 2018, 8:58am UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111/2 "2018-10-04T08:58:08Z")

</div>

I changed these lines, is this what you want?

```auto
final int ELLIPSE_POS_X=RECT_POS_X + RECT_WIDTH * rectSize/ORIGINAL_SIZE;
final int ELLIPSE_POS_Y=RECT_POS_Y +RECT_HEIGHT * rectSize/ORIGINAL_SIZE-40;

ellipse(ELLIPSE_POS_X ,ELLIPSE_POS_Y,ELLIPSE_SIZE * rectSize/ORIGINAL_SIZE,ELLIPSE_SIZE * rectSize/ORIGINAL_SIZE);

```

---

<div class="post-metadata">

**Author:** ![nerdboybi](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nerdboybi](https://discourse.processing.org/u/nerdboybi)\
**Post date:** [October 4, 2018, 11:52am UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111/3 "2018-10-04T11:52:23Z")

</div>

Not quite, I want the circle to stay fixed on the rectangle, the x centre of it is now fixed but not the y centre

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 4, 2018, 2:07pm UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111/4 "2018-10-04T14:07:16Z")

</div>

Hi nerdboybi,

Even if you have solved your problem it is best to not delete the original post and reply to it with the way you solved it.

The goal of the forum is to help people and maybe your solution can be useful to someone else.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 24, 2019, 6:43pm UTC](https://discourse.processing.org/t/solved-simple-circle-and-rectangle-code-doubt/4111/5 "2019-09-24T18:43:52Z")

</div>


