xxxxxxxxxx
51
lineArray = []
function setup() {
createCanvas(600, 600);
for (var i = 0; i < 10; i++) {
lineArray.push(new Line);
}
}
class Line {
constructor() {
this.x1 = width * random(1, 9) / 10.0;
this.x2 = width * random(1, 9) / 10.0;
this.y1 = width * random(1, 9) / 10.0;
this.y2 = width * random(1, 9) / 10.0;
var xDist = this.x1 - this.x2;
var yDist = this.y1 - this.y2;
this.length = ((xDist * xDist) + (yDist * yDist))^0.5;
}
display() {
line(this.x1, this.y1, this.x2, this.y2);
}
}
function draw() {
var longestLength = 0;
var longestIndex = 0;
strokeWeight(3);
background(120,210,170);
for (var i = 0; i < lineArray.length; i++) {
if (lineArray[i].length >= longestLength) {
longestIndex = i;
longestLength = lineArray[i].length;
}
}
for (var j = 0; j < lineArray.length; j++) {
if (j == longestIndex) {
stroke("red");
lineArray[j].display();
} else {
stroke(230)
lineArray[j].display();
}
}
}