xxxxxxxxxx
37
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
let x0 = 100;
let y0 = 120;
let x1 = mouseX;
let y1 = mouseY;
strokeWeight(2);
stroke(100);
line(x0, y0, x1, y1);
strokeWeight(6);
stroke(250, 60, 80);
point(x0, y0);
stroke(60, 80, 250);
point(x1, y1);
noStroke();
textAlign(CENTER, CENTER);
text("P0", x0, y0 - 12);
text("P1", x1, y1 + 12);
let a = x1 - x0;
let b = y1 - y0;
let c = sqrt(a * a + b * b);
//let distance = dist(x0, y0, x1, y1);
let distance = c;
textAlign(LEFT, TOP);
text(distance, 4, 4);
}