Tuesday, January 20, 2009

Easiest Syntax?

Just wondering if I should show the syntax for declaring arrays as:

float[][] myArray;
myArray = new float[200][200];

or as:

float[][] myArray = new float[200][200];

I wonder what new students would find easier? Perhaps both?

Sunday, January 11, 2009

Incomplete sketchy attempt...

OK, here's a sketchy attempt at my little bit of writing. By no means is this complete.. nowhere NEAR 2500 words! But at least its a start...


We saw on page xx the various uses of one-dimensional (1D) arrays. Now we are going to take this concept further and show how two-dimensional (2D) arrays can be used for computer graphics.

Firstly, let us describe what a 2D array is. Where a 1D array is basically a list of items of a similar type, a 2D array is best described as a table of items of a similar type. In terms of geometry, a 2D array can be thought of as a flat plane with an X and Y axis.

The uses of this in computing are quite wide and varied. Employing 2D arrays in computer graphics can be quite useful as a table can be useful for storing values and data relating to pixels on screen. The use of programming constructs such as loops allows for each element of the array to be processed individually as seen previously for 1D arrays on page xx. The difference for a 2D array is that access to the elements needs to move in both directions, i.e. horizontally as well as vertically. The way that this is done is described later.

Now we will look at the syntax for declaring arrays. We know that a 1D array is declared as follows:

int[] myArray = new int[size];

Similarly, a 2D array is declared as follows:

int[][] myArray = new int[sizeX][sizeY];

The difference here is that the 2D array has two subscripts, i.e. one to control the X coordinate and one to control the Y coordinate.


More to follow... I'll hopefully be able to post some code soon too.