setup()
setup() runs once when the sketch starts. Use it to initialize your canvas, set colors, and prepare any variables you need. Everything in setup() happens before the draw loop begins.
🔬 These lines set up the circle's appearance. What happens if you add stroke(0); before noStroke() to give the circle a black border? Or what if you remove the noStroke() line entirely?
fill(100, 150, 255);
// Remove the border stroke for a cleaner look
noStroke();
function setup() {
createCanvas(windowWidth, windowHeight);
// Tip: Use windowWidth/windowHeight for responsive canvas
// Set the fill color for the circle (e.g., light blue)
fill(100, 150, 255);
// Remove the border stroke for a cleaner look
noStroke();
}
Line-by-line explanation (3 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a fullscreen canvas that fills the entire browser window
fill(100, 150, 255);
Sets the fill color to light blue using RGB values (red=100, green=150, blue=255)
createCanvas(windowWidth, windowHeight);- Creates a canvas as wide and tall as the browser window. windowWidth and windowHeight are built-in p5.js variables that contain the current window dimensions
fill(100, 150, 255);- Sets the fill color for all shapes drawn after this line. The three numbers are RGB values: red (0-255), green (0-255), blue (0-255). This creates light blue
noStroke();- Removes the border (stroke) around shapes. Without this, the circle would have a black outline