Item should not go out of the canvas

I made a dart board but it has some problems.

Firstly it is not moving with the mouse and is following the mouse but I dont want that.

Secondly I do not want my dart board to go out of the canvas

Thirdly the size should be half of original size when mouse is at the top of canvas, original size when mouse is in the middle and double the original size when mouse is at the bottom of the screen.(Cannot use IF, ELSE)

Here is the code:

int sizectr=50;
int xctr = 250;
int yctr = 250;

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

void draw() {
  background(255, 200, 200);
  controlItem();
  drawItem();
}

void drawItem () {
  fill(127, 0, 0);
  ellipse(xctr, yctr, 2*sizectr, 2*sizectr);
  fill(255);
  ellipse(xctr, yctr, 1.5*sizectr, 1.5*sizectr);
  fill(127, 0, 0);
  ellipse(xctr, yctr, sizectr, sizectr);
  fill(255);
  ellipse(xctr, yctr, .5*sizectr, .5*sizectr);
  fill(127, 0, 0);
  ellipse(xctr, yctr, sizectr/4, sizectr/4);
  fill(255);
  ellipse(xctr, yctr, sizectr*.09, sizectr*.09);

  //ellipse(xctr,yctr,sizectr*.09,sizectr*.09);

  stroke(0, 255, 0);
  line(xctr, yctr, xctr+(sizectr/4), yctr+sizectr/4);
  fill(0, 255, 0);
  triangle(xctr, yctr, xctr+sizectr/6, yctr, xctr, yctr+sizectr/6);
  stroke(0);
} 

void controlItem () { 
  sizectr=10+(100*mouseY/500);
  xctr=sizectr+(mouseX-2*sizectr);
  yctr=sizectr+(mouseY-2*sizectr);
  float n = 20;
  float xC = (xctr)/n;
  float yC = (yctr)/n;
}

Please help me with the problem.

Hi @deesha_nayar :relaxed:

I’m not sure to get what you mean. What’s the difference between moving with the mouse and following the mouse ?

Did you try using constrain() ?

posX=constrain(posX, 0, width);
posY=constrain(posY, 0, height);

Why not ? It seems to be the easiest way :

if (mouseY<width*0.66) scale=x;
else scale=x*2;