Parallel line that follows the mouse with circle

How can I fix the ellipse in the middle / left outside of the background-window?
Here is my code until now:

void setup(){
  size(100,100);
}
void draw(){
  background(200);
  line(mouseX,0,mouseX,100);
  ellipseMode(CORNER);
  ellipse(0,0,mouseX,mouseX);
}

This is the exercise in words:

Draw a line that is parallel to the y-axis and always follows the mouse. In the area between the line and the left edge, a circle should be drawn in the middle, which exactly hits the left and right.


THX!!! :slight_smile:

to pin it in the middle change its y-position to height / 2 minus its current radius

(when in ellipseMode(CORNER); mode)

1 Like

If U want a Circle in the middle, use CENTER, this means the (h,k) coordinates. (x – h)2 + (y – k)2 = r2 , it’s mean ( h , k ) the center.

void setup(){
   size(100,100);
   ellipseMode(CENTER);
}
void draw(){
   background(200);
   line(mouseX,0,mouseX,height);
   ellipse((mouseX)/2,height/2,mouseX,mouseX);
}

CircleCenter

2 Likes

Thank you so much!!! :laughing:

1 Like