Initial commit

This commit is contained in:
2026-01-09 15:08:46 +01:00
commit 1faf742c6a
11 changed files with 547 additions and 0 deletions

4
README.md Normal file
View File

@@ -0,0 +1,4 @@
# Rubiks
rubiks en processing

262
Rubiks.pde Normal file
View File

@@ -0,0 +1,262 @@
Rgb Red = new Rgb(255, 0, 0);
Rgb White = new Rgb(255, 255, 255);
Rgb Blue = new Rgb(0, 0, 255);
Rgb Green = new Rgb(0, 255, 0);
Rgb Orange = new Rgb(255, 127, 0);
Rgb Yellow = new Rgb(255, 255, 0);
Rgb Black = new Rgb(0, 0, 0);
int VUP = 0;
int VDOWN = 1;
int VLEFT = 2;
int VRIGHT = 3;
int VFRONT = 4;
int VBACK = 5;
class Rubiks {
Cube fmd, fbl, fbr, fmr, f, fml, ftl, fmt, ftr, rm, br, dm, bl, lm, tl, tm, tr, bmd, bbl, bbr, bmr, b, bml, btl, bmt, btr;
void swap_color(Cube a, int facea, Cube b, int faceb) {
Rgb tmp;
tmp = a.getColorFace(facea);
println("R: " + tmp.r + ", G: " + tmp.g + ", B: " + tmp.b);
a.setColorFace(b.getColorFace(faceb), facea);
b.setColorFace(tmp, faceb);
}
void u() {
// Edges
swap_color(ftr, VFRONT, btr, VRIGHT);
swap_color(ftr, VUP, btr, VUP);
swap_color(ftr, VRIGHT, btr, VBACK);
swap_color(btr, VUP, btl, VUP);
swap_color(btr, VRIGHT, btl, VBACK);
swap_color(btr, VBACK, btl, VLEFT);
swap_color(btl, VUP, ftl, VUP);
swap_color(btl, VBACK, ftl, VLEFT);
swap_color(btl, VLEFT, ftl, VFRONT);
// Center
swap_color(fmt, VFRONT, tr, VRIGHT);
swap_color(fmt, VUP, tr, VUP);
swap_color(tr, VRIGHT, bmt, VBACK);
swap_color(tr, VUP, bmt, VUP);
swap_color(bmt, VBACK, tl, VLEFT);
swap_color(bmt, VUP, tl, VUP);
}
void dp() {
// Edges
swap_color(fbr, VFRONT, bbr, VRIGHT);
swap_color(fbr, VDOWN, bbr, VDOWN);
swap_color(fbr, VRIGHT, bbr, VBACK);
swap_color(bbr, VDOWN, bbl, VDOWN);
swap_color(bbr, VRIGHT, bbl, VBACK);
swap_color(bbr, VBACK, bbl, VLEFT);
swap_color(bbl, VDOWN, fbl, VDOWN);
swap_color(bbl, VBACK, fbl, VLEFT);
swap_color(bbl, VLEFT, fbl, VFRONT);
// Center
swap_color(fmd, VFRONT, br, VRIGHT);
swap_color(fmd, VDOWN, br, VDOWN);
swap_color(br, VRIGHT, bmd, VBACK);
swap_color(br, VDOWN, bmd, VDOWN);
swap_color(bmd, VBACK, bl, VLEFT);
swap_color(bmd, VDOWN, bl, VDOWN);
}
void bp() {
// Edges
swap_color(btr, VUP, bbr, VRIGHT);
swap_color(btr, VBACK, bbr, VBACK);
swap_color(btr, VRIGHT, bbr, VDOWN);
swap_color(bbr, VRIGHT, bbl, VDOWN);
swap_color(bbr, VBACK, bbl, VBACK);
swap_color(bbr, VDOWN, bbl, VLEFT);
swap_color(bbl, VDOWN, btl, VLEFT); // THis one
swap_color(bbl, VBACK, btl, VBACK);
swap_color(bbl, VLEFT, btl, VUP);
// Center
swap_color(bmt, VBACK, bmr, VBACK);
swap_color(bmt, VUP, bmr, VRIGHT);
swap_color(bmr, VBACK, bmd, VBACK);
swap_color(bmr, VRIGHT, bmd, VDOWN);
swap_color(bmd, VBACK, bml, VBACK);
swap_color(bmd, VDOWN, bml, VLEFT);
}
void b() {
this.bp();
this.bp();
this.bp();
}
void fp() {
// Edges
swap_color(ftr, VUP, fbr, VRIGHT);
swap_color(ftr, VFRONT, fbr, VFRONT);
swap_color(ftr, VRIGHT, fbr, VDOWN);
swap_color(fbr, VRIGHT, fbl, VDOWN);
swap_color(fbr, VFRONT, fbl, VFRONT);
swap_color(fbr, VDOWN, fbl, VLEFT);
swap_color(fbl, VDOWN, ftl, VLEFT); // THis one
swap_color(fbl, VFRONT, ftl, VFRONT);
swap_color(fbl, VLEFT, ftl, VUP);
// Center
swap_color(fmt, VFRONT, fmr, VFRONT);
swap_color(fmt, VUP, fmr, VRIGHT);
swap_color(fmr, VFRONT, fmd, VFRONT);
swap_color(fmr, VRIGHT, fmd, VDOWN);
swap_color(fmd, VFRONT, fml, VFRONT);
swap_color(fmd, VDOWN, fml, VLEFT);
}
void f() {
this.fp();
this.fp();
this.fp();
}
void d() {
this.dp();
this.dp();
this.dp();
}
void up() {
this.u();
this.u();
this.u();
}
void r() {
// Edges
swap_color(btr, VUP, ftr, VFRONT);
swap_color(btr, VBACK, ftr, VUP);
swap_color(btr, VRIGHT, ftr, VRIGHT);
swap_color(ftr, VUP, fbr, VFRONT);
swap_color(ftr, VFRONT, fbr, VDOWN);
swap_color(ftr, VRIGHT, fbr, VRIGHT);
swap_color(fbr, VFRONT, bbr, VDOWN);
swap_color(fbr, VDOWN, bbr, VBACK);
swap_color(fbr, VRIGHT, bbr, VRIGHT);
// Center
swap_color(fmr, VFRONT, tr, VUP);
swap_color(fmr, VRIGHT, tr, VRIGHT);
swap_color(fmr, VFRONT, br, VDOWN);
swap_color(fmr, VRIGHT, br, VRIGHT);
swap_color(br, VDOWN, bmr, VBACK);
swap_color(br, VRIGHT, bmr, VRIGHT);
}
void lp() {
// Edges
swap_color(btl, VUP, ftl, VFRONT);
swap_color(btl, VBACK, ftl, VUP);
swap_color(btl, VRIGHT, ftl, VRIGHT);
swap_color(ftl, VUP, fbl, VFRONT);
swap_color(ftl, VFRONT, fbl, VDOWN);
swap_color(ftl, VRIGHT, fbl, VRIGHT);
swap_color(fbl, VFRONT, bbl, VDOWN);
swap_color(fbl, VDOWN, bbl, VBACK);
swap_color(fbl, VRIGHT, bbl, VRIGHT);
// Center
swap_color(fml, VFRONT, tl, VUP);
swap_color(fml, VRIGHT, tl, VRIGHT);
swap_color(fml, VFRONT, bl, VDOWN);
swap_color(fml, VRIGHT, bl, VRIGHT);
swap_color(bl, VDOWN, bml, VBACK);
swap_color(bl, VRIGHT, bml, VRIGHT);
}
void l() {
this.lp();
this.lp();
this.lp();
}
void rp() {
this.r();
this.r();
this.r();
}
void draw() {
// front face
fmd.draw();
fbl.draw();
fbr.draw();
fmr.draw();
f.draw();
fml.draw();
ftl.draw();
fmt.draw();
ftr.draw();
// second raw
rm.draw();
br.draw();
dm.draw();
bl.draw();
lm.draw();
tl.draw();
tm.draw();
tr.draw();
// backface
bmd.draw();
bbl.draw();
bbr.draw();
bmr.draw();
b.draw();
bml.draw();
btl.draw();
bmt.draw();
btr.draw();
}
Rubiks() {
fmd = new Cube(new Pos(0, 100, 100), Black, Yellow, Black, Black, Red, Black);
fbl = new Cube(new Pos(100, 0, 0), Black, Yellow, Green, Black, Red, Black);
fbr = new Cube(new Pos(-200, 0, 0), Black, Yellow, Black, Blue, Red, Black);
fmr = new Cube(new Pos(0, 0, -100), Black, Black, Black, Blue, Red, Black);
f = new Cube(new Pos(100, 0, 0), Black, Black, Black, Black, Red, Black);
fml = new Cube(new Pos(100, 0, 0), Black, Black, Green, Black, Red, Black);
ftl = new Cube(new Pos(0, 0, -100), White, Black, Green, Black, Red, Black);
fmt = new Cube(new Pos(-100, 0, 0), White, Black, Black, Black, Red, Black);
ftr = new Cube(new Pos(-100, 0, 0), White, Black, Black, Blue, Red, Black);
// middle row
rm = new Cube(new Pos(0, -100, 100), Black, Black, Black, Blue, Black, Black);
br = new Cube(new Pos(0, 0, 100), Black, Yellow, Black, Blue, Black, Black);
dm = new Cube(new Pos(100, 0, 0), Black, Yellow, Black, Black, Red, Black);
bl = new Cube(new Pos(100, 0, 0), Black, Yellow, Green, Black, Black, Black);
lm = new Cube(new Pos(0, 0, -100), Black, Black, Green, Black, Black, Black);
tl = new Cube(new Pos(0, 0, -100), White, Black, Green, Black, Black, Black);
tm = new Cube(new Pos(-100, 0, 0), White, Black, Black, Black, Black, Black);
tr = new Cube(new Pos(-100, 0, 0), White, Black, Black, Blue, Red, Black);
// back face
bmd = new Cube(new Pos(100, -100, 200), Black, Yellow, Black, Black, Black, Orange);
bbl = new Cube(new Pos(100, 0, 0), Black, Yellow, Green, Black, Black, Orange);
bbr = new Cube(new Pos(-200, 0, 0), Black, Yellow, Black, Blue, Black, Orange);
bmr = new Cube(new Pos(0, 0, -100), Black, Black, Black, Blue, Black, Orange);
b = new Cube(new Pos(100, 0, 0), Black, Black, Black, Black, Black, Orange);
bml = new Cube(new Pos(100, 0, 0), Black, Black, Green, Black, Black, Orange);
btl = new Cube(new Pos(0, 0, -100), White, Black, Green, Black, Black, Orange);
bmt = new Cube(new Pos(-100, 0, 0), White, Black, Black, Black, Black, Orange);
btr = new Cube(new Pos(-100, 0, 0), White, Black, Black, Blue, Black, Orange);
}
}

1
algos/checkerboard Normal file
View File

@@ -0,0 +1 @@
L2R2F2B2U2D2

1
algos/flowers Normal file
View File

@@ -0,0 +1 @@
L'RUDFB'RL'M2E2S2

1
algos/superflip Normal file
View File

@@ -0,0 +1 @@
UR2FBRB2RU2LB2RU'D'R2FR'LB2U2F2

View File

@@ -0,0 +1 @@
FB2R'D2BRUD'RL'D'F'R2DF2B'

11
color.pde Normal file
View File

@@ -0,0 +1,11 @@
class Rgb{
int r;
int b;
int g;
Rgb(int r, int g, int b) {
this.r = r;
this.g = g;
this.b = b;
}
}

96
cube.pde Normal file
View File

@@ -0,0 +1,96 @@
class Cube {
Pos pos;
Rgb up;
Rgb down;
Rgb left;
Rgb right;
Rgb front;
Rgb back;
Cube(Pos pos, Rgb up, Rgb down, Rgb left, Rgb right, Rgb front, Rgb back) {
this.pos = pos;
this.up = up;
this.down = down;
this.left = left;
this.right = right;
this.front = front;
this.back = back;
}
void setColorFace(Rgb col, int face) {
switch(face) {
case (0):
up = col;
break ;
case (1):
down = col;
break ;
case (2):
left = col;
break ;
case (3):
right = col;
break ;
case (4):
front = col;
break ;
case (5):
back = col;
break ;
}
}
Rgb getColorFace(int face) {
switch(face) {
case (0):
return up;
case (1):
return down;
case (2):
return left;
case (3):
return right;
case (4):
return front;
case (5):
return back;
}
return up;
}
void drawbox(Rgb up, Rgb down, Rgb left, Rgb right, Rgb front, Rgb back) {
fill(up.r, up.g, up.b);
rect(0, 0, 100, 100);
fill(back.r, back.g, back.b);
rotateX(PI/2);
rect(0, 0, 100, 100);
fill(right.r, right.g, right.b);
rotateY(PI/2);
rect(0, 0, 100, 100);
fill(left.r, left.g, left.b);
translate(0, 0, 100);
rect(0, 0, 100, 100);
fill(down.r, down.g, down.b);
translate(0,100,-100);
rotateX(PI/2);
rect(0, 0, 100, 100);
rotateY(PI/2);
translate(-100, 0, 100);
fill(front.r, front.g, front.b);
rect(0, 0, 100, 100);
rotateX(PI/2);
rotateY(PI/2);
translate(0, -100, 0);
}
void draw() {
translate(pos.x, pos.y, pos.z);
this.drawbox(this.up, this.down, this.left, this.right, this.front, this.back);
}
}

11
pos.pde Normal file
View File

@@ -0,0 +1,11 @@
class Pos{
int x;
int y;
int z;
Pos(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}

1
sketch.properties Normal file
View File

@@ -0,0 +1 @@
main=sketch_220520a.pde

158
sketch_220520a.pde Normal file
View File

@@ -0,0 +1,158 @@
int zoom = 0;
Rubiks rub;
boolean w = false;
boolean a = false;
boolean s = false;
boolean d = false;
boolean c = false;
boolean Camera = false;
float cameraX = 0;
float cameraY = 0;
PVector cameraPos;
void handle_moves(Rubiks rub) {
if (w == true) {
cameraX += 100;
w = false;
}
if (a == true) {
cameraX -= 100;
a = false;
}
if (s == true) {
cameraY += 100;
s = false;
}
if (d == true) {
cameraY -= 100;
d = false;
}
if (c == true) {
Camera = true;
c = false;
}
}
void setup() {
size(900,600, P3D);
translate(450, 300, 0);
rub = new Rubiks();
String[] lines = loadStrings("./algos/flowers");
for (int i = 0; i < lines[0].length(); i++) {
char instruction = '\0';
if (lines[0].charAt(i) != '2' && lines[0].charAt(i) != '\'')
instruction = lines[0].charAt(i);
if (instruction == 'L') {
if (lines[0].charAt(i + 1) == '2') {
rub.l();
rub.l();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.lp();
}
else {
rub.l();
}
} else if (instruction == 'U') {
if (lines[0].charAt(i + 1) == '2') {
rub.u();
rub.u();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.up();
}
else {
rub.u();
}
} else if (instruction == 'R') {
if (lines[0].charAt(i + 1) == '2') {
rub.r();
rub.r();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.rp();
}
else {
rub.r();
}
} else if (instruction == 'F') {
if (i == lines[0].length() - 1)
break ;
if (lines[0].charAt(i + 1) == '2') {
rub.f();
rub.f();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.fp();
}
else {
rub.f();
}
} else if (instruction == 'B') {
if (lines[0].charAt(i + 1) == '2') {
rub.bp();
rub.bp();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.b();
}
else {
rub.bp();
}
} else if (instruction == 'D') {
if (lines[0].charAt(i + 1) == '2') {
rub.d();
rub.d();
} else if (lines[0].charAt(i + 1) == '\'') {
rub.dp();
}
else {
rub.b();
}
}
}
}
void draw () {
if (zoom < -4500)
zoom = -4500;
if (zoom > 100)
zoom = 100;
handle_moves(rub);
translate(cameraX, cameraY, zoom);
background(70);
strokeWeight(10);
stroke(0);
if (!Camera) {
cameraX = map(mouseY, 0, 900, 6, 0);
cameraY = map(mouseX, 0, 600, 0, 4);
}
rotateX(cameraX);
rotateZ(cameraY);
rub.draw();
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
zoom = zoom + int(e) * -100;
}
void keyPressed() {
if (key == 'w') {
w = true;
}
if (key == 'a') {
a = true;
}
if (key == 's') {
s = true;
}
if (key == 'd') {
d = true;
}
if (key == 'c') {
c = true;
}
}