xxxxxxxxxx
29
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
let n = 5; // n is the number of circles that we want
// we want a loop that loops 5 times
// we replaced 5 by n
for(let i = 0 ; i < n ; i = i + 1){
for(let j = 0 ; j < n ; j = j + 1){
// i takes the values 0,1,2,3 then 4, and stops
let x = i * (width / (n - 1)); // we replaced 4 by (n - 1)
let y = j * (height / (n - 1));
let d = 40;
fill(255 - (i*50)); // variable color fill on x-axis
stroke(255 - (j*50)); // variable color stroke on y-axis
circle(x,y,d); // drawsx circle at x = 50, y = 50, d = 40
}
}
noLoop();
}