Need my triangle to point to my mouse

Hi, I’m using the google translator …
I need the tip of my triangle to point to the coordinates of my mouse, here I leave what I could find out and do about it

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

void draw(){
  PVector v1 = new PVector(width/2, height/2);
  PVector v2 = new PVector(mouseX, mouseY); 
  float r = PVector.angleBetween(v1, v2);
  background(255);
  pushMatrix();
  translate(width/2, height/2);
  rotate(-degrees(r));
  triangle(0,0,50,100,-50,100);
  popMatrix();
}
1 Like
void setup(){
  size(500, 500);
}

void draw(){
  background(255);
  pushMatrix();
  translate(width/2, height/2);
  rotate(atan2(height/2-mouseY, width/2-mouseX)-HALF_PI);
  triangle(0,0,50,100,-50,100);
  popMatrix();
}

This is a more direct computation of the same angle.

2 Likes

Wow, it’s works :slight_smile:
Thanks you!

1 Like