Week 9

Week 9. Array, PImage

Download example code in class

ARRAY : A variable is a named pointer to a location in memory where data is stored. In other words, variables allow programs to keep track of information over a period of time. An array is exactly the same, only instead of pointing to one singular piece of information, an array points to multiple pieces.

A list(Array) is useful for two important reasons.

1.  the list keeps track of the elements in the list themselves.

2. the list keeps track of  the order of those elements (which element is the first in the list, the second, the third, etc.).

Array Class Note 

#1. Declaring and Creating an Array

We know that all variables must have a name and a data type. Arrays are no different. The declaration statement, however, does look different.  We denote the use of an array by placing empty square brackets ( “ [] ” ) after the type declaration.

#2. Initializing the elements of an array

2-1.  Initializing the elements of an array one at a time   : One way to fill an array is to hard-code the values stored in each spot of the array.

    arrayName[INDEX]

   int[] stuff      =      new int[3];

   stuff   [0]         =      8;  // The first element of the array equals 8

   stuff   [1]         =      3;  // The second element of the array equals 3

   stuff   [2]         =      1;  // The third element of the array equals 1

In here, we refer to each element of the array individually by specifying an index, starting at 0. 

2 -2. Initializing the elements of an array all at once  : manually type out a list of values enclosed in curly braces and separated by commas.

int[] arrayOfInts      =       { 1, 5, 8, 9, 4, 5 };

float[] floatArray      =     { 1.2, 3.5, 2.0, 3.4123, 9.9 };    

PImage sequence Demo files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s