function twolineintersect(x1,y1,x2,y2,x3,y3,x4,y4){if((x1==x2&&y1==y2)||(x3==x4&&y3==y4)){return false}denominator=((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1));if(denominator==0){return false}let ua=((x4-x3)*(y1-y3)-(y4-y3)*(x1-x3))/denominator;let ub=((x2-x1)*(y1-y3)-(y2-y1)*(x1-x3))/denominator;if(ua<0||ua>1||ub<0||ub>1){return false}let x=x1+ua*(x2-x1);let y=y1+ua*(y2-y1);return [x,y]}
lines.push([Math.random()*400, Math.random()*400, Math.random()*400, Math.random()*400])
ghosts[0] = [mouseX, mouseY]
Math.cos(noise(frameCount/600)*Math.PI*2)*250*noise(frameCount/300 + 20)+150,
Math.sin(noise(frameCount/600)*Math.PI*2)*250*noise(frameCount/300 + 20)+250
Math.cos(noise(300 + frameCount/600)*Math.PI*2)*250*noise(300 + frameCount/300 + 20)+150,
Math.sin(noise(300 + frameCount/600)*Math.PI*2)*250*noise(300 + frameCount/300 + 20)+150
Math.cos(noise(600 + frameCount/600)*Math.PI*2)*250*noise(600 + frameCount/300 + 20)+250,
Math.sin(noise(600 + frameCount/600)*Math.PI*2)*250*noise(600 + frameCount/300 + 20)+200
for(let j=0;j<ghosts.length;j++){
for(let i=0;i<lines.length;i++){
ghosts[j][2].push([lines[i][0], lines[i][1]])
ghosts[j][2].push([lines[i][2], lines[i][3]])
ghosts[j][2].push([ghosts[i][0], ghosts[i][1]])
ghosts[i][2].push([ghosts[j][0], ghosts[j][1]])
stroke(0);strokeWeight(2)
for(let i=0;i<lines.length;i++){
for(let j=0;j<ghosts.length;j++){
for(let k=0;k<ghosts[j][2].length;k++){
if(ghosts[j][2][k][0] == lines[i][0] && ghosts[j][2][k][1] == lines[i][1]) continue
if(ghosts[j][2][k][0] == lines[i][2] && ghosts[j][2][k][1] == lines[i][3]) continue
if(ghosts[j][2][k]) if(twolineintersect(...lines[i], ghosts[j][0], ghosts[j][1], ...ghosts[j][2][k]))ghosts[j][2][k] = false
for(let i=0;i<ghosts.length;i++){
for(let j=0;j<ghosts[i][2].length;j++) if(ghosts[i][2][j]) line(ghosts[i][0], ghosts[i][1], ...ghosts[i][2][j])
circle(ghosts[i][0], ghosts[i][1], 5)