We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I know how to do this the long way, visit every element of a 3D array, but I am wondering if there is a shortcut and optimized way to do the following:
for (int i = 0; i < CPS; i++) {
for (int j = 0; j < CPS; j++) {
for (int k = 0; k < CPS; k++) {
box[i][j][k].draw(); }}}
I am looking for something like this:
for every element of box[][][] {box[][][].draw;
OR
box[(int i = 0; i < CPS; i++)][(int j = 0; j < CPS; j++)][(int k = 0; k < CPS; k++)].draw();
OR the best yet would be
box[][][].draw;
Any and all suggestion would be appreciated.
Answers
There isn't an automatic out-of-the-box way to do this in Processing.
You might google something like "java flatten arrays" for a ton of results.
But just using the nested
for
loop is probably the easiest option. Maybe put this in a function so it looks like a one-liner to the rest of your code.make a class Cube and say
cube.draw();
https://forum.Processing.org/two/discussions/tagged/3darray
Thank you GoToLoop, let me try this and doo some metrics and see how it goes.