xxxxxxxxxx
// Add a parameter
// In this sketch we learn how to add a parameter to a function
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
noFill();
}
function draw() {}
function eccentricRings(x, y, numRings, spacing) { // Here we added a new parameter: spacing
for (let i = 0; i < numRings; i++) {
ellipse(x, y, 50 + i * spacing, 50 + i * spacing); // How did we implement it in the code?
}
}
function mousePressed() {
eccentricRings(mouseX, mouseY, 7, 8); // Where is spacing called here?
eccentricRings(mouseX -70, mouseY -150, 4, 20);
eccentricRings(mouseX +180, mouseY +100, 2, 35);
}
// Experiment:
// Try commenting out the mousePressed fuction above (highlight code all code, then press Command + '/'), and uncommenting
// the mousePressed function below. See the difference, then change some of the arguments below.
// function mousePressed() {
// eccentricRings(mouseX, mouseY, random(0, 7), random(5, 20));
// eccentricRings(mouseX + random(-100, 100), mouseY + random(-100, 100), random(0, 7), random(5, 20));
// eccentricRings(mouseX + random(-100, 100), mouseY + random(-100, 100), random(0, 7), random(5, 20));
// }