setup()
setup() runs once when the sketch starts. It initializes the canvas size, disables strokes for smooth shapes, and sets up arrays that store information about each of the 24 vertices that make up the blob. The 'n' variable (24) determines how many vertices the blob has - more vertices create a smoother blob.
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;}
}
๐ง Subcomponents:
createCanvas(windowWidth,windowHeight);
Creates a canvas that fills the entire browser window
for(let i=0;i<n;i++){ang[i]=TWO_PI*i/n;offX[i]=offY[i]=vX[i]=vY[i]=0;}
Sets up 24 vertices evenly spaced in a circle and initializes their physics arrays
Line by Line:
createCanvas(windowWidth,windowHeight);- Creates a canvas that matches the full browser window size, allowing the blob to be responsive
noStroke();- Removes outlines from shapes so the blob has a smooth, filled appearance
cx=width/2;cy=height/2;- Sets the blob's center position to the middle of the canvas (cx and cy are center coordinates)
for(let i=0;i<n;i++){- Loops through all 24 vertices to initialize their properties
ang[i]=TWO_PI*i/n;- Calculates the angle for each vertex (TWO_PI is 360 degrees, so vertices are evenly spaced around a circle)
offX[i]=offY[i]=vX[i]=vY[i]=0;- Initializes offset positions and velocities to zero for each vertex