Basic 2D array help
in
Programming Questions
•
1 year ago
So basically this is my question;
Generate a square grid. The greyscale of each cell is randomly set. A new grid is
displayed whenever any key is pressed. In the following screenshots, there are
10*10 cells and 100*100 cells respectively.
Define a two-dimensional array of integers. Each array element stores a
randomly generated integer between 0 and 255 (inclusive)
I think it wants me to create a 2d array with random values, and then use those values as a reference as to the greyscale of each individual square. Im struggling already and im not even up to the bit about generating a new grid when any key is pressed. This is what i have so far (i know its really wrong but any help would be appreciated):
int cols = 10;
int rows = 10;
float[] [] grid = new float[cols] [rows];
void setup() {
size(200,200);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
grid[i] [j] = random(0,255);
println(grid[i] [j]);
stroke(0);
fill(random(i));
rect(0,0,100,100);
}
}
}
1