xxxxxxxxxx
//Note: you only need to read and edit the function drawLinesBetweenPins
function setup() {
createCanvas(600, 600);
noLoop();
}
function draw() {
background("#050505");
//Returns an array of objects, each with an x and y property.
const pins = createPins(20);
drawPins(pins);
drawLinesBetweenPins(pins);
}
function drawLinesBetweenPins(pins) {
let palette = [
'#D64933',
'#FA8334',
'#EA9010',
'#2D854A',
'#14591D',
'#3587A4',
'#23B5D3',
'#70587C',
'#573280',
'#832232',
'#DA4167',
'#E87461',
];
//TODO: Implement this function properly
//Draw a line from each pin to EVERY other pin.
// You should end up with a web of crossing lines.
// The following draws a line, but it's in the wrong place!
// and we need more of them!
//replace this code!
strokeWeight(2);
for (let i = 0; i < pins.length; i++) {
for (let j = i + 1; j < pins.length; j++) {
stroke(random(palette));
line(pins[i].x, pins[i].y, pins[j].x, pins[j].y);
}
}
}
//Note: you don't need to change this function
function drawPins(pins) {
fill('#fffbe6');
//Done for you: draw a small yellow circle at the position of each pin
for (let pin of pins) {
circle(pin.x, pin.y, 8);
}
}
function mouseClicked() {
draw();
}