xxxxxxxxxx
54
var myLines = [];
function setup() {
createCanvas(400, 400);
initLines();
}
function initLines() {
for (var i = 0; i < 15; i++) {
myLines.push(new MyLine());
}
}
function draw() {
background(220);
var longest = 0;
for (let j = 0; j < myLines.length; j++) {
if (myLines[j].len() > myLines[longest].len()) {
longest = j;
}
}
for (let i = 0; i < myLines.length; i++) {
if (i == longest) {
stroke('red');
} else {
stroke('black');
}
myLines[i].render();
}
}
function mousePressed() {
myLines = [];
initLines();
}
class MyLine {
constructor() {
this.x1 = random(width);
this.y1 = random(height);
this.x2 = random(width);
this.y2 = random(height);
}
render() {
line(this.x1, this.y1, this.x2, this.y2);
}
len() {
return dist(this.x1, this.y1, this.x2, this.y2);
}
}