xxxxxxxxxx
41
var x1, x2, y1, y1;
function setup() {
createCanvas(600, 600);
x1 = random(width);
x2 = random(width);
y1 = random(height);
y2 = random(height);
}
function draw() {
background(220);
ellipse(x1,y1,10);
ellipse(x2, y2, 10);
line(x1, y1, mouseX, mouseY);
line(x2,y2,mouseX,mouseY);
let v3 = createVector(mouseX-x1, mouseY-y1);
let v4 = createVector(mouseX-x2, mouseY-y2);
let dotp = v3.dot(v4);
let dist1 = v3.mag();
let dist2 = v4.mag();
let angle = acos(dotp/(dist1*dist2));
let textangle = round(degrees(angle),2)
textSize(20);
text(textangle + " degrees", width/2, height/2);
}
function mousePressed() {
x1 = random(5, width-5);
x2 = random(5, width-5);
y1 = random(5, width-5);
y2 = random(5, width-5);
}