Initial commit
This commit is contained in:
158
sketch_220520a.pde
Normal file
158
sketch_220520a.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user