Thanks for precious feedback, i play a little, im trying to enlarge the cluster, and now it match with the value 3.5, i can’t understand why.
It is not proportional, maybe an int rounded…
Also rotate value, currently i find the right degree by hand, step by step with keyPressed, i wonder if the right prospective could be done in a clean way.
CubeClass[][][] cube = new CubeClass[8][8][8];
float d = 12;
float howMany = 0;
color c1 = color(255,255,0) ;
color c2 = color(0,255,255) ;
color c3 = color(255,0,255) ;
color[] colors = {
c1, c2, c3
};
void setup(){
size(400, 400, P3D);
frameRate(60);
pixelDensity(displayDensity());
genesi();
noStroke();
}
void genesi(){
for (int x = 0; x < 8; x=x+1){
for (int y = 0; y < 8; y=y+1){
for (int z = 0; z < 8; z=z+1){
cube[x][y][z] = new CubeClass(x*24,y*24,z*24, parseBoolean(int(random(0,1.4))), int(random(0,3) ) ,int(random(0,3)) ,int(random(0,3)) );
}}}
}
void draw(){
background(100);
//howMany = howMany + 0.01;
float im = (-0.6163185) - howMany;
println(im);
ortho(-width/2, width/2, -height/2, height/2); // Same as ortho()
translate(width/2, height/2);
rotateY(im);
rotateX(-QUARTER_PI);
translate(-3.5*24, -3.5*24, -3.5*24);
for (int x = 0; x < 8; x=x+1){
for (int y = 0; y < 8; y=y+1){
for (int z = 0; z < 8; z=z+1){
cube[x][y][z].update();
}}}
}
class CubeClass {
float ypos, xpos, zpos;
boolean oN;
int colOne;
int colTwo;
int colTre;
CubeClass (float x, float y, float z, boolean on, int col1, int col2, int col3) {
ypos = y;
xpos = x;
zpos = z;
oN = on;
colOne = col1;
colTwo = col2;
colTre = col3;
}
void update() {
if(oN){
pushMatrix();
translate(xpos,ypos,zpos);
beginShape(QUADS);
fill(colors[colOne]);
vertex(-d, -d, d);
vertex( d, -d, d);
vertex( d, d, d);
vertex(-d, d, d);
endShape();
// Back
beginShape(QUADS);
fill(colors[colTwo]);
vertex( d, -d, -d);
vertex(-d, -d, -d);
vertex(-d, d, -d);
vertex( d, d, -d);
endShape();
// Bottom
beginShape(QUADS);
fill(colors[colTre] );
vertex(-d, d, d);
vertex( d, d, d);
vertex( d, d, -d);
vertex(-d, d, -d);
endShape();
// Top
beginShape(QUADS);
fill(colors[colOne] );
vertex(-d, -d, -d);
vertex( d, -d, -d);
vertex( d, -d, d);
vertex(-d, -d, d);
endShape();
// Right
beginShape(QUADS);
fill(colors[colTwo]);
vertex( d, -d, d);
vertex( d, -d, -d);
vertex( d, d, -d);
vertex( d, d, d);
endShape();
// Left
beginShape(QUADS);
fill(colors[colTre]);
vertex(-d, -d, -d);
vertex(-d, -d, d);
vertex(-d, d, d);
vertex(-d, d, -d);
endShape();
popMatrix();
}
} }
void keyPressed(){
if (key == '+'){
howMany = howMany + 0.001;
}
if (key == '-'){
howMany = howMany - 0.001;
}
if (key == 'r'){
genesi();
}
}