Hello! I followed TheCodingTrain’s youtube video for the Rubik’s cube, and am now adding some functionality which I need help with. I am using java mode. I created a simple solver (brute force), and now I want to create a visualizer that shows how the solver searches the tree of possible solutions. I need some help to get me started with the drawing code.
what I have is something like this:
class Cube{ methods for turning cube}
class Solver {
takes Cube → constructs tree → searches tree for solution
// i want to add a drawTree() function that draws each step of creating and searching the tree, the
// algorithm for drawing I can try and figure out
}
I don’t know how to make it draw() interact with solver.drawTree();. I made so that when I press button to start solving (creating the tree), i then call drawTree(); manually from inside the solver and it enters the drawTree function, but it isnt drawing anything from there and the cube stays on the screen. Other thing I tried is when I press button → set solving = true, then start solving. But the draw() never checks the boolean while the solving is in progress, so it doesnt call drawTree. Any suggestions?
Sorry if this is vague, ask clarifying questions and I’ll try to answer!
Update: I can make the void draw() call the drawTree() function, but it doesn’t actually draw anything on the screen. I am trying to just draw some lines at first. drawTree looks like this:
void drawTree(){
println(“drawTree”);
for(int i = 0; i < 50000; i++){
line(50,50,200,200,i,i+100);
}
}
I am using P3D so I figure I need to give 3D coordinates. Anyone know what I am doing wrong?
Oh, for me they don’t show, originally it showed just the Cube and didnt do anything, but with your version it actually stopped drawing the cube (like I wanted), but I couldnt see the lines. They might have been somewhere out of the camera for me.
@glv@jafal (and Chrisir)
Thank you guys, I got it to draw the lines now. I can start working on my solution from here. Thank you so much for helping me so quickly!