xxxxxxxxxx
59
let twod = [];
let twodEnd = [];
let distances = [];
let x1 = 0;
let y1 = 0;
let start = false;
let count = 0;
function setup() {
createCanvas(600, 600);
}
function draw() {
background(220);
if (twod.length>0 && (twod.length == twodEnd.length)){
let largestD = 0;
let nums = 0;
for (i=0; i<distances.length; i++) {
if (distances[i] > largestD) {
largestD = distances[i];
nums = i;
}
}
for (i=0; i<twod.length; i++) {
if (i==nums) {
stroke("red");
} else {
stroke(0);
}
strokeWeight(5);
line(twod[i][0], twod[i][1], twodEnd[i][0], twodEnd[i][1]);
}
}
}
function mousePressed() {
twod.push([mouseX, mouseY]);
return false;
}
function mouseReleased() {
twodEnd.push([mouseX,mouseY]);
let x1 = twod[twod.length-1][0];
let y1 = twod[twod.length-1][1];
let x2 = twodEnd[twod.length-1][0];
let y2 = twodEnd[twod.length-1][1];
let distance1 = ((x2-x1)**2 + (y2-y1)**2)**0.5
distances.push(distance1);
}