[SOLVED] Simple Circle and rectangle code doubt

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.

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;
    
}

I changed these lines, is this what you want?

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);

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

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.

1 Like