What is setup() used for?
It runs once at the beginning and sets up things like the canvas and starting values.
What is a custom function?
A user defined reusable block of code.
fill("red", 10);
rect(0,0,50,50);
fill() doesn’t take two separate argument types for a color name and transparency (text and number)
You need RGBA values or a single color with alpha, like fill(255,0,0,10).
What does a conditional statement let a program do?
Branching paths; take a decision based on a condition.
What does an event like mousePressed() do?
It runs code only when the user clicks. Events let your sketch react to actions.
r = random(255), b = random(255), g = random(255), a = random(255)
What does the background(r, g, b, a) command do?
background(r, g, b, a) fills the whole screen with a color made from those random red, green, blue, and alpha (opacity) values.
Why use a custom function?
To reuse code and reduce repetition.
circle(xPos, yPos);
circle() needs three arguments (xPos, yPos, diameter). Here it only has two
What Boolean result must an if statement receive to run its block?
True
What is the purpose of a parameter?
To pass data into a function.
Why does the draw() function repeat?
It refreshes the screen 60x a second, allowing animation and live updates.
How many parts are in a standard for loop header?
three
function setup() {
createCanvas(400, 400);
let xPos = width / 2; }
function draw() {
background(220);
ellipse(xPos, 200, 50);}
Make the variable global or move it under draw to be local....
If an if condition is false and there is an else, which block runs?
The else block.
Why do we use comments?
To explain our thinking so future-us (or teammates) can understand the code faster.
Why do we use variables in p5?
To store values (like positions, sizes, or colors) that can change as the sketch runs.
What does the middle part of a for loop control?
When the loop stops.
for (let i = 0; i < 5; i--) {
ellipse(50 + i * 60, 100, 30);
}
infinte loop time...
The loop is moving in the wrong direction.
Change i-- to i++.
What is the difference between = and == in a conditional?
= assigns a value, == compares values.
What happens when you forget a closing bracket }?
The code block never ends, so the computer gets confused and throws errors in places that don’t seem connected.
What is the difference between a variable’s name and its value?
A variable’s name is the label you use to refer to it in your program.
A variable’s value is the data currently stored inside it, which can change while the program runs.
In a nested loop, how many times does the inner loop run?
Once per outer loop iteration.
for (let i = 0; i < 5; i++) {
ellipse(20, 20, 50);}
Why is this not doing what a loop usually should?
The loop repeats, but it's drawing the same ellipse in the same spot every time. A loop needs something (like xPos or yPos) that changes each cycle to make multiple shapes.
What must be true for a condition using && to pass?
Both conditions must be true.
Why do programmers test often instead of waiting until the end.
Small errors are easier to spot early. Waiting makes debugging messy because problems stack on top of each other.