setup()
setup() runs once when the sketch starts. It's the perfect place to initialize your canvas, create objects, and set up variables that won't change during the animation.
function setup(){createCanvas(windowWidth,windowHeight);makeBg();for(let i=0;i<120;i++)drops.push(new Drop());}
๐ง Subcomponents:
createCanvas(windowWidth,windowHeight)
Creates a canvas that fills the entire browser window
makeBg()
Generates the gradient night sky background once
for(let i=0;i<120;i++)drops.push(new Drop())
Creates 120 raindrop objects and adds them to the drops array
Line by Line:
createCanvas(windowWidth,windowHeight)- Creates a canvas that matches the full window size, allowing the rain to fill the entire screen
makeBg()- Calls the function that creates the gradient night sky background and stores it in the bg variable
for(let i=0;i<120;i++)drops.push(new Drop())- Loops 120 times, creating a new Drop object each time and adding it to the drops array. This populates the scene with raindrops