Processing should define Array just like it has Vector

A simple example of a function that creates a 2D-array of PVector instances:

final PVector[][] pvArr2d = createPVecArr2d(5, 3); // 5 x 3

void setup() {
  for (final PVector[] pvArr1d : pvArr2d) println(pvArr1d);
  exit();
}

static final PVector[][] createPVecArr2d(final int rows, final int cols) {
  final PVector[][] arr2d = new PVector[rows][cols];

  for (final PVector[] arr1d : arr2d) for (int i = 0; i < arr1d.length; )
    arr1d[i++] = new PVector();

  return arr2d;
}

[ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ]
[ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ]
[ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ]
[ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ]
[ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ] [ 0.0, 0.0, 0.0 ]

3 Likes