For the past few days have been trying to better understand grids and arrays.
After reading D Shiffman tutorial on 2D grid arrays I am now trying to play with that code a bit.
- I would like the grid(s) to appear twice, one above the other.
- I have placed alpha in the fill so to be able to see thru to the grid below.
- However, I see only one instance of the grid.
- Why do I not see both grids?
Cell[][] grid;
// Number of columns and rows in the grid
int cols = 10;
int rows = 8;
void setup() {
size(600, 600);
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
grid[i][j] = new Cell(i*(width/5), j*(height/8), width/5, height/8); // why does this grid not appear?
grid[i][j] = new Cell(i*(width/10), j*(height/8), width/10, height/8);
}
}
}
void draw() {
background(255);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
grid[i][j].display();
grid[i][j].display();
}
}
fill (125, 30);
rect (50, 50, 150, 150); ///// this is a test rectangle with gray fill and 30 alpha tranparency
}
// A Cell object
class Cell {
float x, y; // x,y location
float w, h; // width and height
// Cell Constructor
Cell (float tempX, float tempY, float tempW, float tempH) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void display() {
stroke(0);
fill(125, 30); // gray with 30 alpha for transparency
rect(x, y, w, h);
}
}