Skip to content

Instantly share code, notes, and snippets.

@jaycody
Created March 11, 2014 18:00
Show Gist options
  • Save jaycody/9491392 to your computer and use it in GitHub Desktop.
Save jaycody/9491392 to your computer and use it in GitHub Desktop.
arcTangentToDetermineAngle
// Determine THETA between 2 points with arcTangent atan2() function
int x, y;
void setup() {
size(500, 500);
x = width/2;
y = height/2;
textSize(20);
textAlign(CENTER, CENTER);
noStroke();
smooth();
}
void draw() {
background(255);
float angle = atan2(mouseY-y, mouseX-x);
translate(x, y);
fill(0);
ellipse(0, 0, 100, 100);
fill(255);
text(int(degrees(angle)), 0, 0);
rotate(angle);
fill(0, 0, 255);
ellipse(50, 0, 30, 30);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment