def init(): """Create global objects and show plot. """ global c, ic c = Cube(3) ic = c.draw_interactive() plt.show(block=False)
# These are displayed on the LED strip. strip_face_colors = ['#ffffff', '#ffff00', '#0000ff', '#00cf00', '#50002f', '#ff0000'] # Cube dimension. N = 3 try: # Establish an Arduino connection first. print 'Connecting to Arduino...' stream = serial.Serial(serial_device, 115200) time.sleep(2) # Start LED controller. print 'Starting controller' controller = CubeLedStripContoller(stream, led_to_sticker_mapping, strip_face_colors, debug=0) # Bring up the cube visualization. Add a call back that sends # the cube state to the Arduino. c = Cube(N, face_colors=display_face_colors + ['gray', 'none']) # Unclear what those last two colors are used for. c.draw_interactive(callback=controller.send_cube_state) plt.show() # Visualization was exited, shut down LED strip and serial port. controller.turn_off() except (IOError, OSError): # Error or CTRL-C was pressed, shut down LED strip and serial port. controller.turn_off() sys.exit(141)
def capture_face(self): if len(self.faces) < 6: face = [] for row in self.current_face: face.append([]) for cell in row: face[-1].append(cell) next_face = self.POSSIBLE_FACES[len(self.faces)] if next_face == "B": # DONE!!!!! #face = face[::-1] # Hacer espejo vertical, no horizontal for i in xrange(len(face)): face[i] = face[i][::-1] elif next_face == "R": face = face[::-1] face = zip(*face[::-1]) # Girar 90 grados # face = face[::-1] # girar 90 grados, hacer espejo horizontal elif next_face == "L": # DONE!!!! for i in xrange(len(face)): face[i] = face[i][::-1] face = zip(*face[::-1]) elif next_face == "F": # DONE!!!!! face = face[::-1] elif next_face == "U": face = face[::-1] face = zip(*face[::-1]) pass # Girar 270 grados elif next_face == "D": face = face[::-1] face = zip(*face[::-1]) pass # Espejo y 90 grados self.faces[next_face] = face print face if len(self.faces) == 6: colors = [] colors.append(self.map_face( self.faces["B"] )) colors.append(self.map_face( self.faces["F"] )) colors.append(self.map_face( self.faces["R"] )) colors.append(self.map_face( self.faces["L"] )) colors.append(self.map_face( self.faces["D"] )) colors.append(self.map_face( self.faces["U"] )) # colors = [[0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4]] colors_rgb = {} colors_rgb["B"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["B"], 3))) colors_rgb["F"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["F"], 3))) colors_rgb["R"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["R"], 3))) colors_rgb["L"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["L"], 3))) colors_rgb["U"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["D"], 1))) colors_rgb["D"] = self.map_face_RGB( self.flip_matrix( self.rotate_matrix(self.faces["U"], 3))) rubik = Rubik(colors_rgb) rubik.describe() c = Cube(self.dimensions, None, None, colors) c.draw_interactive() plt.show() solve(Rubik(colors_rgb))
def capture_face(self): if len(self.faces) < 6: face = [] for row in self.current_face: face.append([]) for cell in row: face[-1].append(cell) next_face = self.POSSIBLE_FACES[len(self.faces)] if next_face == "B": # DONE!!!!! #face = face[::-1] # Hacer espejo vertical, no horizontal for i in xrange(len(face)): face[i] = face[i][::-1] elif next_face == "R": face = face[::-1] face = zip(*face[::-1]) # Girar 90 grados # face = face[::-1] # girar 90 grados, hacer espejo horizontal elif next_face == "L": # DONE!!!! for i in xrange(len(face)): face[i] = face[i][::-1] face = zip(*face[::-1]) elif next_face == "F": # DONE!!!!! face = face[::-1] elif next_face == "U": face = face[::-1] face = zip(*face[::-1]) pass # Girar 270 grados elif next_face == "D": face = face[::-1] face = zip(*face[::-1]) pass # Espejo y 90 grados self.faces[next_face] = face print face if len(self.faces) == 6: colors = [] colors.append(self.map_face(self.faces["B"])) colors.append(self.map_face(self.faces["F"])) colors.append(self.map_face(self.faces["R"])) colors.append(self.map_face(self.faces["L"])) colors.append(self.map_face(self.faces["D"])) colors.append(self.map_face(self.faces["U"])) # colors = [[0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4], [0,1,2,3,4,5,3,2,4]] colors_rgb = {} colors_rgb["B"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["B"], 3))) colors_rgb["F"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["F"], 3))) colors_rgb["R"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["R"], 3))) colors_rgb["L"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["L"], 3))) colors_rgb["U"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["D"], 1))) colors_rgb["D"] = self.map_face_RGB( self.flip_matrix(self.rotate_matrix(self.faces["U"], 3))) rubik = Rubik(colors_rgb) rubik.describe() c = Cube(self.dimensions, None, None, colors) c.draw_interactive() plt.show() solve(Rubik(colors_rgb))
import sys sys.path.append("lib/MagicCube/code") from matplotlib.pyplot import show from cube_interactive import Cube as UICube # pylint: disable=import-error ### Load UI c = UICube(N=3) c.draw_interactive() show()