You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An [array](http://www.processing.org/reference/Array.html) keeps track of multiple pieces of information in linear order, a one-dimensional list. However, the data associated with certain systems (a digital image, a board game, etc.) lives in two dimensions. To visualize this data, we need a multi-dimensional data structure, that is, a multi-dimensional array. A two-dimensional array is really nothing more than an array of arrays (a three-dimensional array is an array of arrays of arrays). Think of your dinner. You could have a one-dimensional list of everything you eat:
16
+
An [array](http://www.processing.org/reference/Array.html) keeps track of multiple pieces of information in linear order, a one-dimensional list. However, the data associated with certain systems (a digital image, a board game, etc.) lives in two dimensions. To visualize this data, we need a multi-dimensional data structure, that is, a multi-dimensional array. A two-dimensional array is really nothing more than an array of arrays (a three-dimensional array is an array of arrays of arrays). Think of your dinner. You could have a one-dimensional list of everything you eat:
To walk through every element of a one-dimensional array, we use a for loop, that is:
60
+
To walk through every element of a one-dimensional array, we use a for loop, that is:
60
61
61
62
```
62
63
int[] myArray = new int[10];
@@ -72,7 +73,7 @@ int cols = 10;
72
73
int rows = 10;
73
74
int[][] myArray = new int[cols][rows];
74
75
75
-
// Two nested loops allow us to visit every spot in a 2D array.
76
+
// Two nested loops allow us to visit every spot in a 2D array.
76
77
// For every column I, visit every row J.
77
78
for (int i = 0; i < cols; i++) {
78
79
for (int j = 0; j < rows; j++) {
@@ -113,7 +114,7 @@ for (int i = 0; i < cols; i++) {
113
114
}
114
115
```
115
116
116
-
A two-dimensional array can also be used to store objects, which is especially convenient for programming sketches that involve some sort of "grid" or "board." The following example displays a grid of Cell objects stored in a two-dimensional array. Each cell is a rectangle whose brightness oscillates from 0-255 with a sine function.
117
+
A two-dimensional array can also be used to store objects, which is especially convenient for programming sketches that involve some sort of "grid" or "board." The following example displays a grid of Cell objects stored in a two-dimensional array. Each cell is a rectangle whose brightness oscillates from 0-255 with a sine function.
117
118
118
119
<FixedImagesidewidth={200} >
119
120
@@ -142,8 +143,8 @@ void setup() {
142
143
143
144
void draw() {
144
145
background(0);
145
-
// The counter variables i and j are also the column and row numbers and
146
-
// are used as arguments to the constructor for each object in the grid.
146
+
// The counter variables i and j are also the column and row numbers and
147
+
// are used as arguments to the constructor for each object in the grid.
147
148
for (int i = 0; i < cols; i++) {
148
149
for (int j = 0; j < rows; j++) {
149
150
// Oscillate and display each object
@@ -155,7 +156,7 @@ void draw() {
155
156
156
157
// A Cell object
157
158
class Cell {
158
-
// A cell object knows about its location in the grid
159
+
// A cell object knows about its location in the grid
Copy file name to clipboardExpand all lines: content/tutorials/text/pshape/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ coverImage: pshape.jpg
9
9
10
10
<Note>
11
11
12
-
If you see any errors in this tutorial or have comments, [please let us know](https://github.com/processing/processing-docs/issues?q=is%3Aopen). This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-nc-sa/4.0/).
12
+
If you see any errors in this tutorial or have comments, [please let us know](https://github.com/processing/processing-website/issues?q=is%3Aopen). This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-nc-sa/4.0/).
0 commit comments