letr=300;letpeeps=[];letthresh=50;lett1=0;lett2=0;functionsetup(){cnv=createCanvas(600,600);noStroke();peeps=[];r=min(width,height)/3;n=random(1000,3000);describe("a constellation on a sphere that twists slowly into a torus. lines are light on a dark slate-teal background. the size and density is randomized");thresh=r/10+random(0,r/10);for(leti=0;i<n;i++){a=acos(random(-1,1));b=random(0,2*PI);x=r*Math.sin(a)*Math.cos(b);y=r*Math.sin(a)*Math.sin(b);z=r*Math.cos(a);peeps.push(newPeep(a,b,x,y,z));}for(leti=0;i<peeps.length;i++){cnt=0;cnt2=0;while(cnt<1){int1=int(random(0,peeps.length));dx=peeps[int1].x-peeps[i].x;dy=peeps[int1].y-peeps[i].y;dz=peeps[int1].z-peeps[i].z;dist1=sqrt(dx*dx+dy*dy+dz*dz);if(dist1<thresh){peeps[i].n1=int1;cnt++;}else{cnt2++;}if(cnt2>peeps.length*2){cnt=1;peeps[i].n1=i;}}cnt=0;cnt2=0;while(cnt<1){int1=int(random(0,peeps.length));dx=peeps[int1].x-peeps[i].x;dy=peeps[int1].y-peeps[i].y;dz=peeps[int1].z-peeps[i].z;dist1=sqrt(dx*dx+dy*dy+dz*dz);if(dist1<thresh){peeps[i].n2=int1;cnt++;}else{cnt2++;}if(cnt2>peeps.length*2){cnt=1;peeps[i].n2=i;}}cnt=0;cnt2=0;while(cnt<1){int1=int(random(0,peeps.length));dx=peeps[int1].x-peeps[i].x;dy=peeps[int1].y-peeps[i].y;dz=peeps[int1].z-peeps[i].z;dist1=sqrt(dx*dx+dy*dy+dz*dz);if(dist1<thresh){peeps[i].n3=int1;cnt++;}else{cnt2++;}if(cnt2>peeps.length*2){cnt=1;peeps[i].n3=i;}}cnt=0;cnt2=0;while(cnt<1){int1=int(random(0,peeps.length));dx=peeps[int1].x-peeps[i].x;dy=peeps[int1].y-peeps[i].y;dz=peeps[int1].z-peeps[i].z;dist1=sqrt(dx*dx+dy*dy+dz*dz);if(dist1<thresh){peeps[i].n4=int1;cnt++;}else{cnt2++;}if(cnt2>peeps.length*2){cnt=1;peeps[i].n4=i;}}}}functiondraw(){if(!mouseIsPressed){t1+=0.005;t2+=0.005;}else{t1+=0.01;t2+=0.01;}translate(width/2,height/2);background(20,40,50);for(leti=0;i<peeps.length;i++){peeps[i].play();}for(leti=0;i<peeps.length;i++){push();fill(100,100,200);circle(peeps[i].x,peeps[i].y,2);pop();push();stroke(100-50*(peeps[i].z/r),140-50*(peeps[i].z/r),160-50*(peeps[i].z/r));strokeWeight(0.5+0.4*(peeps[i].z/(2*r)));line(peeps[i].x,peeps[i].y,peeps[peeps[i].n1].x,peeps[peeps[i].n1].y);line(peeps[i].x,peeps[i].y,peeps[peeps[i].n2].x,peeps[peeps[i].n2].y);line(peeps[i].x,peeps[i].y,peeps[peeps[i].n3].x,peeps[peeps[i].n3].y);line(peeps[i].x,peeps[i].y,peeps[peeps[i].n4].x,peeps[peeps[i].n4].y);pop();}}classPeep{constructor(a,b,x,y,z){this.a=a;this.b=b;this.x=x;this.y=y;this.z=z;this.n1=0;this.n2=0;this.n3=0;this.n4=0;}play(){this.x=r*Math.sin(this.a+t2/8)*Math.cos(this.b+t2/2);this.y=r*Math.sin(this.a+t2/4)*Math.sin(this.b+t2);this.z=r*Math.cos(this.a+t2/4);}}functionkeyPressed(){if(keyCode===32){setup();draw();}elseif(keyCode===83){save(cnv,"wcf","png");}else{t1=0;t2=0;}}