home/ atoms/ processing-two-d-arrays

Two-dimensional arrays in Processing store grid data as arrays of arrays

A 2D array is an array whose elements are themselves arrays — effectively a table or grid. Declared as int[][] grid = new int[rows][cols], individual cells are accessed with grid[row][col]. The outer dimension is the row index, the inner is the column. Nested for loops iterate over all cells: for (int r=0; r<rows; r++) { for (int c=0; c<cols; c++) { … } }. Common uses include storing pixel data, cellular automata states, and tile maps.

Examples

int[][] grid = new int[5][5]; for (int r = 0; r < 5; r++) for (int c = 0; c < 5; c++) grid[r][c] = r * c;

Assessment

Implement a 10x10 grid of squares where each cell’s fill brightness is determined by its row*column index stored in a 2D array.

“A 2D array is essentially a list of 1D arrays. It must be declared, then created, and then the values can be assigned just as in a 1D array.”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 66