xxxxxxxxxx
29
var angle;
function setup() {
createCanvas(600, 600);
angleMode(DEGREES);
}
function draw() {
background(220);
randomSeed(0);
var x1 = random(width);
var y1 = random(height);
var x2 = random(width);
var y2 = random(height);
line(x1, y1, mouseX, mouseY);
line(x2, y2, mouseX, mouseY);
push();
ellipse(x1, y1, 10, 10);
ellipse(x2, y2, 10, 10);
pop();
var b = dist(x1, y1, mouseX, mouseY);
var c = dist(x2, y2, mouseX, mouseY);
var a = dist(x1, y1, x2, y2);
angle = acos((pow(b, 2) + pow(c, 2) - pow(a, 2))/(2 * b * c));
textSize(20);
textAlign(CENTER);
text("Angle: " + round(angle, 1) + "°", width/2, 500);
}