setup()
setup() runs once when the sketch starts. Here it's used to precompute the resting angle of every vertex so draw() doesn't have to recalculate it every frame - a common performance pattern in creative coding.
function setup(){
createCanvas(windowWidth,windowHeight);
noStroke();
cx=width/2;cy=height/2;
for(let i=0;i<n;i++){ang[i]=TWO_PI*i/n;offX[i]=offY[i]=vX[i]=vY[i]=0;}
}
Line-by-line explanation (4 lines)
🔧 Subcomponents:
for(let i=0;i<n;i++){ang[i]=TWO_PI*i/n;offX[i]=offY[i]=vX[i]=vY[i]=0;}
Fills the ang[] array with evenly spaced angles around a circle and zeroes out every vertex's offset/velocity so the blob starts as a perfect resting circle
createCanvas(windowWidth,windowHeight);- Makes the canvas fill the entire browser window.
noStroke();- Turns off outlines so all shapes drawn later (blob, eyes) are filled with no border.
cx=width/2;cy=height/2;- Places the blob's center at the middle of the screen to start.
for(let i=0;i<n;i++){ang[i]=TWO_PI*i/n;offX[i]=offY[i]=vX[i]=vY[i]=0;}- Loops through all 24 vertices, giving each one an angle evenly spaced around a full circle (TWO_PI radians), and setting its squish offset and velocity to zero so it starts perfectly round.