So, I have changed a little code because I found a little failure, but it still gives me the same Failure. I’m also adding two Pictures from my Cube, and two from the Website, so that you could see the scarmbled and standard Version. (tho, since I’m a “new User” I can only post 1 Image and only 2 Links per Post, I’m going to put them on my Website for you, on http://baipyrus.bplaced.net/images/)
Cube cube;
void setup() {
size(600, 450);
cube = new Cube();
//cube.randomize();
}
void draw() {
background(0);
stroke(0);
for (int i = 0; i < cube.sides.length; i++) {
for (int j = 0; j < cube.sides[i].tiles.length; j++) {
color temp = check(cube.sides[i].tiles[j].col);
fill(temp);
rect(cube.sides[i].tiles[j].self.x*50, cube.sides[i].tiles[j].self.y*50, 50, 50);
}
}
}
color check(String c) {
color col = color(0);
switch (c) {
case "orange":
col = color(244, 182, 66);
break;
case "white":
col = color(255);
break;
case "green":
col = color(0, 255, 0);
break;
case "yellow":
col = color(251, 255, 63);
break;
case "red":
col = color(255, 0, 0);
break;
case "blue":
col = color(0, 0, 255);
break;
}
return col;
}
void keyPressed() {
if (key == 'q') {
cube.turnMiddleRight(0,3);
} else if (key == 'w') {
cube.turnMiddleRight(3,6);
} else if (key == 'e') {
cube.turnMiddleRight(6,9);
} else if (key == 'a') {
cube.turnMiddleLeft(0,3);
} else if (key == 's') {
cube.turnMiddleLeft(3,6);
} else if (key == 'd') {
cube.turnMiddleLeft(6,9);
} else if (key == 't') {
cube.turnTopDown(0,7);
} else if (key == 'z') {
cube.turnTopDown(1,8);
} else if (key == 'u') {
cube.turnTopDown(2,9);
} else if (key == 'g') {
cube.turnTopUp(0,7);
} else if (key == 'h') {
cube.turnTopUp(1,8);
} else if (key == 'j') {
cube.turnTopUp(2,9);
}
}
class Cube {
Side[] sides = new Side[6];
Cube() {
for (int i = 0; i < 6; i++) {
PVector input = new PVector(0, 0);
String temp = "";
switch (i) {
case 0:
temp = "green";
input = new PVector(0, 3);
break;
case 1:
temp = "yellow";
input = new PVector(3, 0);
break;
case 2:
temp = "orange";
input = new PVector(3, 3);
break;
case 3:
temp = "white";
input = new PVector(3, 6);
break;
case 4:
temp = "blue";
input = new PVector(6, 3);
break;
case 5:
temp = "red";
input = new PVector(9, 3);
break;
}
sides[i] = new Side(temp, input);
}
}
void turnMiddleLeft(int start, int end) {
for (int i = start; i < end; i++) {
String tempCol1 = sides[5].tiles[i].col;
sides[5].tiles[i].col = sides[0].tiles[i].col;
String tempCol2 = sides[4].tiles[i].col;
sides[4].tiles[i].col = tempCol1;
tempCol1 = sides[2].tiles[i].col;
sides[2].tiles[i].col = tempCol2;
sides[0].tiles[i].col = tempCol1;
}
if (start == 0) {
//Turn Upper Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[1].tiles[i].col;
}
sides[1].tiles[2].col = tiles[0];
sides[1].tiles[5].col = tiles[1];
sides[1].tiles[8].col = tiles[2];
sides[1].tiles[1].col = tiles[3];
sides[1].tiles[7].col = tiles[5];
sides[1].tiles[0].col = tiles[6];
sides[1].tiles[3].col = tiles[7];
sides[1].tiles[6].col = tiles[8];
} else if (start == 6) {
//Turn Lower Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[3].tiles[i].col;
}
sides[3].tiles[6].col = tiles[0];
sides[3].tiles[3].col = tiles[1];
sides[3].tiles[0].col = tiles[2];
sides[3].tiles[7].col = tiles[3];
sides[3].tiles[8].col = tiles[6];
sides[3].tiles[5].col = tiles[7];
sides[3].tiles[2].col = tiles[8];
sides[3].tiles[1].col = tiles[5];
}
}
void turnMiddleRight(int start, int end) {
for (int i = start; i < end; i++) {
String tempCol1 = sides[0].tiles[i].col;
sides[0].tiles[i].col = sides[5].tiles[i].col;
String tempCol2 = sides[2].tiles[i].col;
sides[2].tiles[i].col = tempCol1;
tempCol1 = sides[4].tiles[i].col;
sides[4].tiles[i].col = tempCol2;
sides[5].tiles[i].col = tempCol1;
}
if (start == 0) {
//Turn Upper Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[1].tiles[i].col;
}
sides[1].tiles[6].col = tiles[0];
sides[1].tiles[3].col = tiles[1];
sides[1].tiles[0].col = tiles[2];
sides[1].tiles[7].col = tiles[3];
sides[1].tiles[8].col = tiles[6];
sides[1].tiles[5].col = tiles[7];
sides[1].tiles[2].col = tiles[8];
sides[1].tiles[1].col = tiles[5];
} else if (start == 6) {
//Turn Lower Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[3].tiles[i].col;
}
sides[3].tiles[2].col = tiles[0];
sides[3].tiles[5].col = tiles[1];
sides[3].tiles[8].col = tiles[2];
sides[3].tiles[1].col = tiles[3];
sides[3].tiles[7].col = tiles[5];
sides[3].tiles[0].col = tiles[6];
sides[3].tiles[3].col = tiles[7];
sides[3].tiles[6].col = tiles[8];
}
}
void turnTopUp(int start, int end) {
for (int i = start; i < end; i+=3) {
String tempCol1 = "";
if (start == 0) {
tempCol1 = sides[5].tiles[i+2].col;
sides[5].tiles[i+2].col = sides[1].tiles[i].col;
} else if (start == 2) {
tempCol1 = sides[5].tiles[i-2].col;
sides[5].tiles[i-2].col = sides[1].tiles[i].col;
} else {
tempCol1 = sides[5].tiles[i].col;
sides[5].tiles[i].col = sides[1].tiles[i].col;
}
String tempCol2 = sides[3].tiles[i].col;
sides[3].tiles[i].col = tempCol1;
tempCol1 = sides[2].tiles[i].col;
sides[2].tiles[i].col = tempCol2;
sides[1].tiles[i].col = tempCol1;
}
if (start == 0) {
//Turn Left Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[0].tiles[i].col;
}
sides[0].tiles[6].col = tiles[0];
sides[0].tiles[3].col = tiles[1];
sides[0].tiles[0].col = tiles[2];
sides[0].tiles[7].col = tiles[3];
sides[0].tiles[1].col = tiles[5];
sides[0].tiles[8].col = tiles[6];
sides[0].tiles[5].col = tiles[7];
sides[0].tiles[2].col = tiles[8];
} else if (start == 2) {
//Turn Right Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[4].tiles[i].col;
}
sides[4].tiles[2].col = tiles[0];
sides[4].tiles[5].col = tiles[1];
sides[4].tiles[8].col = tiles[2];
sides[4].tiles[1].col = tiles[3];
sides[4].tiles[7].col = tiles[5];
sides[4].tiles[0].col = tiles[6];
sides[4].tiles[3].col = tiles[7];
sides[4].tiles[6].col = tiles[8];
}
}
void turnTopDown(int start, int end) {
for (int i = start; i < end; i+=3) {
String tempCol1 = sides[1].tiles[i].col;
if (start == 0) {
sides[1].tiles[i].col = sides[5].tiles[i+2].col;
} else if (start == 2) {
sides[1].tiles[i].col = sides[5].tiles[i-2].col;
} else {
sides[1].tiles[i].col = sides[5].tiles[i].col;
}
String tempCol2 = sides[2].tiles[i].col;
sides[2].tiles[i].col = tempCol1;
tempCol1 = sides[3].tiles[i].col;
sides[3].tiles[i].col = tempCol2;
if (start == 0) {
sides[5].tiles[i+2].col = tempCol1;
} else if (start == 2) {
sides[5].tiles[i-2].col = tempCol1;
} else {
sides[5].tiles[i].col = tempCol1;
}
}
if (start == 0) {
//Turn Left Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[0].tiles[i].col;
}
sides[0].tiles[2].col = tiles[0];
sides[0].tiles[5].col = tiles[1];
sides[0].tiles[8].col = tiles[2];
sides[0].tiles[1].col = tiles[3];
sides[0].tiles[7].col = tiles[5];
sides[0].tiles[0].col = tiles[6];
sides[0].tiles[3].col = tiles[7];
sides[0].tiles[6].col = tiles[8];
} else if (start == 2) {
//Turn Right Part
String[] tiles = new String[9];
for (int i = 0; i < tiles.length; i++) {
tiles[i] = sides[4].tiles[i].col;
}
sides[4].tiles[6].col = tiles[0];
sides[4].tiles[3].col = tiles[1];
sides[4].tiles[0].col = tiles[2];
sides[4].tiles[7].col = tiles[3];
sides[4].tiles[1].col = tiles[5];
sides[4].tiles[8].col = tiles[6];
sides[4].tiles[5].col = tiles[7];
sides[4].tiles[2].col = tiles[8];
}
}
void L() {
turnTopDown(0, 7);
}
void L1() {
turnTopUp(0, 7);
}
void U() {
turnMiddleLeft(0, 3);
}
void U1() {
turnMiddleRight(0, 3);
}
void D() {
turnMiddleRight(6, 9);
}
void D1() {
turnMiddleLeft(6, 9);
}
void R() {
turnTopDown(2, 9);
}
void R1() {
turnTopUp(2, 9);
}
void randomize() {
//turnMiddleRight(0, 3); // Turns Middle Top Row to the Right
//turnMiddleRight(3, 6); // Turns Middle Middle Row to the Right
//turnMiddleLeft(3,6); // Turns Middle Middle Row to the Left
//turnMiddleLeft(6,9); // Turns Middle Bottom Row to the Left
//turnTopUp(0, 7); // Turns Top Left Row Upwards
//turnTopDown(1, 8); // Turns Top Middle Row Downwards
//turnTopUp(1, 8); // Turns Top Middle Row Upwards
//turnTopUp(2, 9); // Turns Top Right Row Upwards
int times = round(random(20, 40));
for (int i = 0; i < times; i++) {
int dec = round(random(1, 2));
if (dec == 1) {
dec = round(random(1, 2));
if (dec == 1) {
//Left
dec = round(random(0, 2));
int c = 0;
switch (dec) {
case 1:
c = 3;
break;
case 2:
c = 6;
break;
}
turnMiddleLeft(c, c+3);
} else {
//Right
dec = round(random(0, 2));
int c = 0;
switch (dec) {
case 1:
c = 3;
break;
case 2:
c = 6;
break;
}
turnMiddleRight(c, c+3);
}
} else {
dec = round(random(1, 2));
if (dec == 1) {
dec = round(random(0, 2));
turnTopDown(dec, dec+7);
} else {
dec = round(random(0, 2));
turnTopUp(dec, dec+7);
}
}
}
}
}
class Side {
Tile[] tiles = new Tile[9];
PVector self;
Side(String col, PVector input) {
self = input;
int y = 0;
for (int i = 0; i < tiles.length; i++) {
PVector s = new PVector(input.x+(i%3), input.y+y);
tiles[i] = new Tile(col, s);
if (i%3 == 2) {
y++;
}
}
}
}
class Tile {
String col;
PVector self;
Tile(String c, PVector s) {
col = c;
self = new PVector(0,0);
self = s;
}
}