Hi there!
I’m just playing around with arrays, learning how to work with them, but there’s one problem happening and I can’t figure it out why
The program is written as follows:
float[] bar = new float[100];
void setup() {
size(1080, 1080);
for (int i = 0; i < bar.length; i++) {
bar[i] = random(200,height-200);
}
}
void draw() {
float x = 0;
background(0);
fill(255);
stroke(255);
for (int i = 0; i < bar.length; i++) {
float spacing = width / bar.length;
rect(x, 0, spacing, bar[i]);
x = x + spacing;
}
}
void mousePressed() {
for (int i = 0; i < bar.length; i++) {
bar[i] = random(200,height-200);
}
}
it should draw these white bars all around the canvas size, but it is not working well when I set widths and heights higher than 1000 (if it’s 1080, it only works as planned if I change the array’s index to a maximum of 45 elements).
Thats the result with the missing part: