HI, im trying to translate this processing sketch into P5, P5 is currently unable to give me an error that I can understand.
below I posted the original processing sketch, and my wild guess on p5.
P5:
class CubeClass {
constructor (x, y, z, on, col1, col2, col3) {
this.x = xpos;
this.y = ypos;
this.z = zpos;
this.col1 = colOne;
this.col2 = colTwo;
this.col3 = colTre;
}
update() {
if(oN){
push();
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();
pop();
}}}
var cube = new CubeClass(8)(8)(8);
var d = 12;
let c1 = color(255,255,0);
let c2 = color(0,255,255);
let c3 = color(255,0,255)
var rot1 = false;
var rot2 = false;
colors = [c1,c2,c3];
var iy = (0.6155185);
var ix = (-QUARTER_PI);
var iz = (PI/2);
function setup(){
createCanvas(400, 400, WEBGL);
genesi();
noStroke();
smooth(100);
//noSmooth();
}
function genesi(){
for (var x = 0; x < 8; x=x+1){
for (var y = 0; y < 8; y=y+1){
for (var z = 0; z < 8; z=z+1){
//parseBoolean(var(random(0,1.4)))
cube[x][y][z] = new CubeClass(x*24,y*24,z*24, parseBoolean((random(0,1.4))), round(random(0,2) ) ,round(random(0,2)) ,round(random(0,2)) );
}}}
}
function draw(){
background(100);
if(rot1){
ix = ix + 0.01;
if(ix/PI >= 0.25){
rot1=false;
ix=QUARTER_PI;
}
}
if(rot2){
ix = ix - 0.01;
if(ix/PI <= -0.25){
rot2=false;
ix=-QUARTER_PI;
}
}
ortho(-width/2, width/2, -height/2, height/2); // Same as ortho()
translate(width/2, height/2);
rotateZ(iz);
rotateY(iy);
rotateX(ix);
translate(-3.5*24, -3.5*24, -3.5*24);
for (var x = 0; x < 8; x=x+1){
for (var y = 0; y < 8; y=y+1){
for (var z = 0; z < 8; z=z+1){
cube[x][y][z].update();
}}}
}
function keyPressed(){
if (key == '1'){
rot1=true;
}
if (key == '2'){
rot2=true;
}
if (key == 'r'){
genesi();
}
}
PROCESSING WORKING SOURCE
CubeClass[][][] cube = new CubeClass[8][8][8];
float d = 12;
color c1 = color(255,255,0) ;
color c2 = color(0,255,255) ;
color c3 = color(255,0,255) ;
boolean rot1 = false;
boolean rot2 = false;
color[] colors = {c1, c2, c3};
float iy = (0.6155185);
float ix = (-QUARTER_PI);
float iz = (PI/2);
void setup(){
size(400, 400, P3D);
frameRate(60);
pixelDensity(displayDensity());
genesi();
noStroke();
smooth(100);
//noSmooth();
}
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){
//parseBoolean(int(random(0,1.4)))
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);
if(rot1){
ix = ix + 0.01;
if(ix/PI >= 0.25){
rot1=false;
ix=QUARTER_PI;
}
}
if(rot2){
ix = ix - 0.01;
if(ix/PI <= -0.25){
rot2=false;
ix=-QUARTER_PI;
}
}
ortho(-width/2, width/2, -height/2, height/2); // Same as ortho()
translate(width/2, height/2);
rotateZ(iz);
rotateY(iy);
rotateX(ix);
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 == '1'){
rot1=true;
}
if (key == '2'){
rot2=true;
}
if (key == 'r'){
genesi();
}