We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › 2 and 3 dimesional arrays
Page Index Toggle Pages: 1
2 and 3 dimesional arrays (Read 582 times)
2 and 3 dimesional arrays
Aug 24th, 2009, 3:50pm
 
hi.. how do u append and access elements of a 2 or 3 dimensional array? is that the way to capture and store sets of mouse coordinates? Huh
Re: 2 and 3 dimesional arrays
Reply #1 - Aug 24th, 2009, 5:45pm
 
There are many ways; you could also use an Xarray and Yarray to store mouse locations, but if you want a 2D array to combine the two, you'd say:

locationArray[][] = new float[2][numberOfSavePoints];

then any saved point can be recalled as:

(locationArray[0][pointNumber], locationArray[1][pointNumber])

if I've misunderstood and you actually want to reference each pixel in a 2D array (as in pixelArray[width][height]), look into pixels[].  That's a 1-D array, so you reference it as (width*y+x).

If you want an array with flexible length, look into the Java classes Vector or LinkedList.  Otherwise all array contents are accessed by the element's index number/s in brackets.
Re: 2 and 3 dimesional arrays
Reply #2 - Aug 24th, 2009, 11:19pm
 
You can use PVector to handle such coordinate sets.
Page Index Toggle Pages: 1