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):
You really don't need the programming technique named "class"/oop here (it would come in handy in the long run though).
A few remarks.
You give the array cells a random value. Good. That is the color. Use it as such.
You paint rects. Good. But they're on top of one another and only the last one can be seen.That's because they all start at 0,0. They really should start at a position that's accordingly to it's column and row.
oh i only have one rect there just as a test thing to try to get it to generate as a random colour, but it just keeps coming up as black. once i do get it to be random, then i will try to implement that with a grid layout. thanks for your help though!!
Hey phil, I put a 2d array in a class and when I initiate in my draw I get a problem. like say in my class I have void initLetters(char a) and in my draw i have myGrid.initLetters(); ...I get an error saying its not applicable?