Hi, I’m trying to get a better understanding of arrays at a basic level before I advance to using them with functions & classes, but I am struggling a little.
I wrote this:
let r;
let g;
let b;
let x;
let y;
let w;
let h;
let max = 60;
let colourB;
let colourC;
let rgb;
let s;
function setup() {
frameRate(60);
createCanvas(windowWidth, windowHeight);
r = floor(random(40, 100));
g = floor(random(40, 255));
b = floor(random(40, 255));
x = mouseX;
y = mouseY;
s = random(15, 25);
}
let history = [];
let points = [];
function draw() {
r = floor(random(40, 100));
g = floor(random(40, 255));
b = floor(random(40, 255));
background(150, 150, 150);
fill(r, g, b);
stroke(0);
max = 10;
x = mouseX;
y = mouseY;
s = random(15, 25);
for (let i = 0; i < max; i++) {
points.push(i);
if (mouseIsPressed) {
[i] = circle(x, y, s);
}
}
}
This only creates one circle, before giving the error Uncaught TypeError: undefined is not a function in Line 50 / Column 11
Why does this loop break?
Can you give me any tips for writing loops with arrays, or maybe some rules of thumb when writing loops with arrays? I’m trying to get my loops to work before incorporating them into functions and classes.
Thank you.