Circle edge on mouse coordinates and increased size the father it gets from canvas center

I’ve just started programming and wanted to get a perfect circle edge to jump to the mouse edge. So the center of the circle would be the center of the canvas, and the closer you get to it, the smaller the circle gets and vice versa, when your mouse enters a given point at the edge of the canvas, the circle size is increased.

I’ve gotten a somewhat reversed effect of this (but not quite):

void setup(){
  size(450,320);
}

void draw(){
  background(255);
  strokeWeight(3);
  arc(225,160,0+(pmouseY+pmouseX),0+(pmouseX+pmouseY),0,TWO_PI);
}

The trick here is to realise that the distance from the mouse position to the sketch centre is the radius of the circle you want to draw. The second thing is that Processing uses the ellipse method to draw a circle.

Replace the arc statement with these 2 lines

  float radius = dist(mouseX, mouseY, width / 2, height / 2);
  ellipse(width/2, height/2, 2 * radius, 2 * radius);
1 Like