it needs to be mentioned that we can do a 3D grid within a 1D array easily - so there is no connection between 3D grid (what you display) and the 3D / 1D array (the internal data structure).
Because also in a 1D array yoiu can store 3D data.
// grid in 3D
final int max1=30;
Cell [][][] grid = new Cell[max1][max1][max1];
float angle1=0.0;
void setup() {
size(740, 740, P3D);
for (int x=0; x<max1; x++) {
for (int y=0; y<max1; y++) {
for (int z=0; z<max1; z++) {
color color1 = color(random(256), random(256), random(256));
float threshold = (map(z, 0, max1, 60, 99.9));
boolean exist = random(101) > threshold;
grid[x][y][z] = new Cell (7*x-(7*30/2), 7*y-(7*30/2), 7*z-(7*30/2),
color1,
exist);
}
}
}
noStroke();
background(0);
}
void draw() {
background(0);
lights();
camera(0, -69, 266,
0, 0, 0,
0, 1, 0);
rotateY (angle1);
angle1+=0.01;
for (int x=0; x<max1; x++) {
for (int y=0; y<max1; y++) {
for (int z=0; z<max1; z++) {
grid[x][y][z].display();
}
}
}
}
// =========================================================
class Cell {
// Attributes
float x;
float y;
float z;
float diameter = 5;
color cellColor=0;
boolean exist;
// constructor
Cell(float theX, float theY, float theZ,
color theColor,
boolean theExist) {
x = theX;
y = theY;
z = theZ;
cellColor=theColor;
exist=theExist;
} // constructor
void display() {
if (exist) {
fill(cellColor);
// noStroke();
// stroke(111);
pushMatrix();
translate(x, y, z);
box(diameter);
popMatrix();
}
}// method
//
}//class
//
Answers
PVector [][] mapPVectors = new PVector[100][100];
Thanks :) @Chrisir
https://forum.Processing.org/two/discussions/tagged/2darray
there is a tutorial on 2D arrays
https://www.processing.org/tutorials/2darray/
Thanks a lot ! Again :) @Chrisir
replacing PVector with your own class Cell to store a color etc. in addition to the position inside the class
and 3D grid:
it needs to be mentioned that we can do a 3D grid within a 1D array easily - so there is no connection between 3D grid (what you display) and the 3D / 1D array (the internal data structure).
Because also in a 1D array yoiu can store 3D data.