Create random array once in draw()
in
Programming Questions
•
1 year ago
Hi,
I'm trying to create a random array of ellipses. But I want to save athe coordinates of each in an array. I want this array only to be generated once within draw() and then to be able to use that array again with in draw.
Below is my attempt,
Any help would be greatly appreciated.
Thanks,
Shane
I'm trying to create a random array of ellipses. But I want to save athe coordinates of each in an array. I want this array only to be generated once within draw() and then to be able to use that array again with in draw.
Below is my attempt,
- int cols = 10;
int rows = 10;
int[]ArrayX = new int[rows];
int[]ArrayY = new int[rows];
void setup() {
size (600, 300);
}
void draw() {
background (127);
noStroke();
fill(0);
if (frameCount==1) {
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
int x = (int) random(-10, 10);
int y = (int) random(-10, 10);
ArrayX[i] = x + 10*i;
ArrayY[j] = y + 10*j;
}
}
}
ellipse(ArrayX[i], ArrayY[j], 3, 3);
}
Thanks,
Shane
1