How to make a bezier curver not start at top left corner when using mouseX, mouseY as the initial anchor point?

I am new to processing and was assigned in class to create a bezier curve that makes one of the control points mouseX and mouseY along with some other necessary shapes needed for the assignment. Whenever I hit run, however, the control point I set to mouseX and mouseY automatically starts at the top left corner instead of where my mouse currently is on the screen. I have attached an image of the run window and and this is my code:

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

void draw() {
  noFill();
  stroke(175,238,218);
  strokeWeight(5);
  line(300, 300, 50, 400);
  line(350, 450, 400, 400);
  stroke(255, 0, 0);
  bezier(mouseX, mouseY, 50,400,350,450,400,400);  
}

I would like to know how to prevent the curve from starting at the top left corner like it keeps doing.

1 Like

possibly you wanted to use the mouse for play with control point (c2?) , and not for anchor point
check again:
https://processing.org/reference/bezier_.html

// https://processing.org/reference/bezier_.html
// https://discourse.processing.org/t/how-to-make-a-bezier-curver-not-start-at-top-left-corner-when-using-mousex-mousey-as-the-initial-anchor-point/13912/2

// the anchor points define begin and end of the bezier curve
// the control points define the starting angle of the curve at the anchor points

void setup() {
  size(800, 800);
  noFill();
  strokeWeight(5);
}

PVector a1 = new PVector(300,300,0);
PVector c1 = new PVector( 50,400,0);
PVector c2 = new PVector(350,400,0);
PVector a2 = new PVector(350,450,0);

void draw() {
  background(200,200,0);
  c2.set(mouseX,mouseY,0);
  stroke(175, 238, 218);
  line(a1.x,a1.y,c1.x,c1.y);
  line(c2.x,c2.y,a2.x,a2.y);
  stroke(200, 0, 0);
  circle(c2.x,c2.y,5);
  bezier(a1.x,a1.y,c1.x,c1.y,c2.x,c2.y,a2.x,a2.y);
}

1 Like

It’s not so much as choosing an anchor point or control point as the mouseX and mouseY, I just wanted to know if there was a way to prevent the shape from shooting up to the top left corner. Even if I make a control point the mouseX and mouseY instead of an anchor point, the curve starts at an upper left angle. I want the curve to start static, and then move as my mouse touches the window canvas. Does this make sense?

maybe you can change the bezier when touch the screen, something like this:

boolean startMode = true;
float a1,b1,a2,b2,a3,b3,a4,b4;
void setup(){   
 size(500,500);
 background(255);
}

void draw(){
  background(0);
  noFill();
  stroke(175,238,218);
  strokeWeight(5);
  line(300, 300, 50, 400);
  line(350, 450, 400, 400);
  stroke(255, 0, 0);
  if(startMode)
    bezier( 300,300,100, 300,350,450,400,400);
  else
    bezier( 300,300,mouseX, mouseY,350,450,400,400);
}

void mousePressed(){
  startMode = false;
}

Well, adapt it to p5, but think that will works :grinning::grinning:

2 Likes

yes this is what I was looking for!!! thank you so much