def moveB(direction, existing_cube, cube_coords, cube_colours, t, canvas): for polygon in existing_cube: canvas.delete(polygon) angle_coeff = 1 if direction == "B'" or direction == "S2": angle_coeff = -1 cube2d = convert(cube_coords) upper_layer = [] upper_layer.append( [cube_coords[0][0], cube_coords[0][1], cube_coords[0][2]]) upper_layer.append( [cube_coords[2][2], cube_coords[2][5], cube_coords[2][8]]) upper_layer.append( [cube_coords[5][6], cube_coords[5][7], cube_coords[5][8]]) upper_layer.append( [cube_coords[4][0], cube_coords[4][3], cube_coords[4][6]]) inside_upper = [[[(-1, 1, -1 + 2 / 3), (1, 1, -1 + 2 / 3), (1, -1, -1 + 2 / 3), (-1, -1, -1 + 2 / 3), (-1, 1, -1 + 2 / 3), 'grey']]] upper_layer += inside_upper remaining_layers = [] remaining_layers.append(cube2d[1]) surf = [] for i in [3, 4, 5, 6, 7, 8]: surf.append(cube2d[0][i]) remaining_layers.append(surf) surf = [] for i in [0, 1, 3, 4, 6, 7]: surf.append(cube2d[2][i]) remaining_layers.append(surf) frames = 30 * t full_angle = angle_coeff * math.pi / 2 frame_angle = full_angle / frames # temp_cube_coords = cube_coords cos_angle = math.cos(frame_angle) sin_angle = math.sin(frame_angle) angle_so_far = 0 for i in range(int(frames) + 1): temp_upperlayer = convert(upper_layer) if angle_so_far / angle_coeff < math.pi / 4: upper = draw_part_of_cube( temp_upperlayer[:2] + [temp_upperlayer[4]], canvas) elif angle_coeff == 1: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[4]) temp_upperlayer2.append(temp_upperlayer[1]) temp_upperlayer2.append(temp_upperlayer[2]) upper = draw_part_of_cube(temp_upperlayer2, canvas) else: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[4]) temp_upperlayer2.append(temp_upperlayer[3]) temp_upperlayer2.append(temp_upperlayer[0]) upper = draw_part_of_cube(temp_upperlayer2, canvas) remaining = draw_part_of_cube(remaining_layers, canvas) canvas.update() new_upper_layer = [] for surface in upper_layer: new_surface = [] for box in surface: new_box = [] for k in range(5): x = box[k][0] y = box[k][1] z = box[k][2] X = x * cos_angle - y * sin_angle Y = x * sin_angle + y * cos_angle new_box.append((X, Y, z)) new_box.append(box[5]) new_surface.append(new_box) new_upper_layer.append(new_surface) upper_layer = new_upper_layer angle_so_far += frame_angle time.sleep(0.033) for polygon in upper: canvas.delete(polygon) for polygon in remaining: canvas.delete(polygon) s.single_move(cube_colours, direction) colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)
def moveS(direction, existing_cube, cube_coords, cube_colours, t, canvas): s.single_move(cube_colours, direction) colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)
def moveX(direction, existing_cube, cube_coords, cube_colours, t, canvas): if direction == "x2": s.single_move(cube_colours, "R") s.single_move(cube_colours, "R") s.single_move(cube_colours, "L'") s.single_move(cube_colours, "L'") s.single_move(cube_colours, "M'") s.single_move(cube_colours, "M'") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas) elif direction == "x'": s.single_move(cube_colours, "R'") s.single_move(cube_colours, "L") s.single_move(cube_colours, "M") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas) else: s.single_move(cube_colours, "R") s.single_move(cube_colours, "L'") s.single_move(cube_colours, "M'") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)
def moveY(direction, existing_cube, cube_coords, cube_colours, t, canvas): if direction == "y2": s.single_move(cube_colours, "U") s.single_move(cube_colours, "U") s.single_move(cube_colours, "D") s.single_move(cube_colours, "D") s.single_move(cube_colours, "y2") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas) elif direction == "y'": s.single_move(cube_colours, "U'") s.single_move(cube_colours, "D") s.single_move(cube_colours, "y'") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas) else: s.single_move(cube_colours, "U") s.single_move(cube_colours, "D'") s.single_move(cube_colours, "y") colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)
def moveR(direction, existing_cube, cube_coords, cube_colours, t, canvas): for polygon in existing_cube: canvas.delete(polygon) angle_coeff = 1 if direction == "R" or direction == "M'": angle_coeff = -1 cube2d = convert(cube_coords) upper_layer = [] upper_layer.append(cube_coords[2]) for i in [1, 0, 3, 5]: if i == 3: upper_layer.append( [cube_coords[i][0], cube_coords[i][3], cube_coords[i][6]]) else: upper_layer.append( [cube_coords[i][2], cube_coords[i][5], cube_coords[i][8]]) remaining_layers = [] for i in range(2): surf = [] for j in [0, 1, 3, 4, 6, 7]: surf.append(cube2d[i][j]) remaining_layers.append(surf) inside_remaining3d = [[[(1 - 2 / 3, 1, 1), (1 - 2 / 3, 1, -1), (1 - 2 / 3, -1, -1), (1 - 2 / 3, -1, 1), (1 - 2 / 3, 1, 1), 'grey']]] inside_remaining = convert(inside_remaining3d) remaining_layers += inside_remaining remaining = draw_part_of_cube(remaining_layers, canvas) frames = 30 * t full_angle = angle_coeff * math.pi / 2 frame_angle = full_angle / frames # temp_cube_coords = cube_coords cos_angle = math.cos(frame_angle) sin_angle = math.sin(frame_angle) angle_so_far = 0 for i in range(int(frames) + 1): temp_upperlayer = convert(upper_layer) if angle_so_far / angle_coeff < math.pi / 4: upper = draw_part_of_cube(temp_upperlayer[:3], canvas) elif angle_coeff == 1: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[0]) temp_upperlayer2.append(temp_upperlayer[2]) temp_upperlayer2.append(temp_upperlayer[3]) upper = draw_part_of_cube(temp_upperlayer2, canvas) else: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[0]) temp_upperlayer2.append(temp_upperlayer[4]) temp_upperlayer2.append(temp_upperlayer[1]) upper = draw_part_of_cube(temp_upperlayer2, canvas) canvas.update() new_upper_layer = [] for surface in upper_layer: new_surface = [] for box in surface: new_box = [] for k in range(5): x = box[k][0] y = box[k][1] z = box[k][2] Y = y * cos_angle - z * sin_angle Z = y * sin_angle + z * cos_angle new_box.append((x, Y, Z)) new_box.append(box[5]) new_surface.append(new_box) new_upper_layer.append(new_surface) upper_layer = new_upper_layer angle_so_far += frame_angle time.sleep(0.033) for polygon in upper: canvas.delete(polygon) # time.sleep(5) for polygon in remaining: canvas.delete(polygon) s.single_move(cube_colours, direction) colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)
def moveD(direction, existing_cube, cube_coords, cube_colours, t, canvas): for polygon in existing_cube: canvas.delete(polygon) angle_coeff = 1 if direction == "D'": angle_coeff = -1 cube2d = convert(cube_coords) upper_layer = [] for i in range(1, 5): upper_layer.append(cube_coords[i][6:9]) inside_upper = [[[(-1, -1 + 2 / 3, 1), (1, -1 + 2 / 3, 1), (1, -1 + 2 / 3, -1), (-1, -1 + 2 / 3, -1), (-1, -1 + 2 / 3, 1), 'grey']]] upper_layer += inside_upper remaining_layers = [] for i in range(3): if i == 0: remaining_layers.append(cube2d[i]) else: remaining_layers.append(cube2d[i][:6]) frames = 30 * t full_angle = angle_coeff * math.pi / 2 frame_angle = full_angle / frames # temp_cube_coords = cube_coords cos_angle = math.cos(frame_angle) sin_angle = math.sin(frame_angle) angle_so_far = 0 for i in range(int(frames) + 1): temp_upperlayer = convert(upper_layer) if angle_so_far / angle_coeff < math.pi / 4: upper = draw_part_of_cube( temp_upperlayer[:2] + [temp_upperlayer[4]], canvas) elif angle_coeff == 1: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[4]) temp_upperlayer2.append(temp_upperlayer[3]) temp_upperlayer2.append(temp_upperlayer[0]) upper = draw_part_of_cube(temp_upperlayer2, canvas) else: temp_upperlayer2 = [] temp_upperlayer2.append(temp_upperlayer[4]) temp_upperlayer2.append(temp_upperlayer[1]) temp_upperlayer2.append(temp_upperlayer[2]) upper = draw_part_of_cube(temp_upperlayer2, canvas) remaining = draw_part_of_cube(remaining_layers, canvas) canvas.update() new_upper_layer = [] for surface in upper_layer: new_surface = [] for box in surface: new_box = [] for k in range(5): x = box[k][0] y = box[k][1] z = box[k][2] X = x * cos_angle + z * sin_angle Z = -x * sin_angle + z * cos_angle new_box.append((X, y, Z)) new_box.append(box[5]) new_surface.append(new_box) new_upper_layer.append(new_surface) upper_layer = new_upper_layer angle_so_far += frame_angle time.sleep(0.033) for polygon in upper: canvas.delete(polygon) for polygon in remaining: canvas.delete(polygon) s.single_move(cube_colours, direction) colourCube(cube_coords, cube_colours) cube2d = convert(cube_coords) return draw_part_of_cube(cube2d[:3], canvas)