def apply_random_pattern(self): pattern = LittleHelpers.get_random_pattern() if self.verbose: print(f'Applying random pattern: {pattern}') moves = LittleHelpers.expand_notations(pattern.split(' ')) for move in moves: self.all_moves.append(move) face_rotations = LittleHelpers.translate_moves_to_face_rotations(moves) self.append_face_rotations(face_rotations)
def scramble_cube(self, moves): format_type = type(moves) if format_type == list: pass elif format_type == str: moves = moves.split(' ') else: print(f'Error in the scramble_cube function. moves format is {format_type} not list (prefered) or str.') return 1 moves = LittleHelpers.expand_notations(moves) face_rotations = LittleHelpers.translate_moves_to_face_rotations(moves) self.cube.scramble(face_rotations)
def create_textures(self, image_files): for name, filename in image_files.items(): success, image_size, image_data = LittleHelpers.load_image(filename) if self.verbose: print(f'Loaded image: {filename} {image_size} {success}') if success: texture_id = self.create_opengl_texture(image_size, image_data) self.textures[name] = texture_id if self.verbose: for name, id in self.textures.items(): print(f'Created texture: {name} with id {id}')
def init_colors(self): self.colors = self.settings.cube_default_colors group_name = self.settings.cube_color_group group = self.color_manager.get_color_group(group_name) if group != None: self.colors.update(group) self.colors.update(self.settings.cube_colors) if self.verbose: print('Color palette:', self.colors) default_color = Constants.FALLBACK_COLOR for key, value in self.colors.items(): self.colors[key] = LittleHelpers.convert_hex_color_to_floats(value, default_color)
def map_cube_colors(self, color_mapping): if color_mapping: self.color_mapping = color_mapping default_color = Constants.FALLBACK_COLOR colors = self.colors front_color = LittleHelpers.get_mapped_color(Face.FRONT, color_mapping, colors, default_color) back_color = LittleHelpers.get_mapped_color(Face.BACK, color_mapping, colors, default_color) left_color = LittleHelpers.get_mapped_color(Face.LEFT, color_mapping, colors, default_color) right_color = LittleHelpers.get_mapped_color(Face.RIGHT, color_mapping, colors, default_color) up_color = LittleHelpers.get_mapped_color(Face.UP, color_mapping, colors, default_color) down_color = LittleHelpers.get_mapped_color(Face.DOWN, color_mapping, colors, default_color) self.cube.map_colors(front_color, back_color, left_color, right_color, up_color, down_color)
def load_colors(self, group_name): colors = {} colors.update(self.colors) self.colors = {} group = self.color_manager.get_color_group(group_name) if group != None: self.colors.update(group) else: return self.colors.update(self.settings.cube_colors) if self.verbose: print(f'Color palette: {self.colors}') default_color = Constants.FALLBACK_COLOR for key, value in self.colors.items(): self.colors[key] = LittleHelpers.convert_hex_color_to_floats(value, default_color) self.update_cube_color_mapping()
def init_opengl(self): glutInit() glutInitWindowPosition(self.settings.window_position[0], self.settings.window_position[1]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(self.settings.window_size[0], self.settings.window_size[1]) glutCreateWindow(self.settings.window_caption) glutReshapeFunc(self.on_reshape_window) glutKeyboardFunc(self.on_keyboard_input) glutMouseFunc(self.on_mouse_input) glutMotionFunc(self.on_mouse_move) glutSpecialFunc(self.on_special_input) glutVisibilityFunc(self.on_visibility_change) glutIdleFunc(self.on_update) glutDisplayFunc(self.on_display) try: if sys.platform == 'linux' or sys.platform == 'linux2': glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS) except Exception as e: print(f'Something went wrong while setting platform specific code. You can just ignore this, but if you want the error it is: {e}') background_color = LittleHelpers.convert_hex_color_to_floats(self.settings.window_background_color, (0.1, 0.1, 0.1)) glClearColor(background_color[0], background_color[1], background_color[2], 1) glClearDepth(1) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LESS) glShadeModel(GL_SMOOTH) glDisable(GL_LIGHTING) if self.settings.texture_mapping_enabled: glEnable(GL_TEXTURE_2D) else: glDisable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
def handle_add_padding_command(self, params): if params: value = LittleHelpers.convert_str_to_float(params) if value != None: self.cube.geometry.add_padding(value)
def handle_map_colors_command(self, params): color_mapping = LittleHelpers.make_color_mapping_from_string(params) self.map_cube_colors(color_mapping)
def handle_rotate_face_command(self, params): if params: moves = LittleHelpers.expand_notations(params.upper().split(' ')) if len(moves): self.add_moves(moves)
def handle_add_scale_command(self, params): if params: value = LittleHelpers.convert_str_to_float(params) if value != None: self.cube.add_scale(value * self.delta_time.elapsed())
def set_background_color(self, hex_color): color = LittleHelpers.convert_hex_color_to_floats(hex_color) if color: glClearColor(color[0], color[1], color[2], 1)
def add_moves(self, moves): face_rotations = LittleHelpers.translate_moves_to_face_rotations(moves) if face_rotations: self.append_face_rotations(face_rotations) for move in moves: self.all_moves.append(move)
def __init__(self, settings, face_rotation_ease_type, sticker_texture_id, size=3): default_color = (0, 0, 0) self.padding = settings.cube_padding self.draw_cubies = settings.cube_draw_cubies self.draw_sphere = settings.cube_draw_sphere self.draw_lines = settings.cube_draw_lines self.line_width = settings.cube_line_width self.inner_color = LittleHelpers.convert_hex_color_to_floats( settings.cube_inner_color, default_color) self.sphere_color = LittleHelpers.convert_hex_color_to_floats( settings.cube_sphere_color, default_color) self.angular_drag = settings.cube_angular_drag self.scale_drag = settings.cube_scale_drag self.min_scale = settings.cube_min_scale / size self.max_scale = settings.cube_max_scale self.size = size self.rot_x = 0 self.rot_y = 0 self.accum = (1, 0, 0, 0) self.scale = 1 / (self.size / 3) self.scale_speed = 0 self.sphere_radius = 3 self.sphere_slices = 16 self.sphere_stacks = 16 self.face_rotation_tween_time = settings.cube_face_rotation_tween_time self.face_rotation_ease_type = face_rotation_ease_type self.texture_mapping_enabled = settings.texture_mapping_enabled self.sticker_texture_id = sticker_texture_id self.geometry = Geometry(self.size) self.face_colors = ( (0, 154 / 255, 74 / 255), # Front: Green (1, 86 / 255, 35 / 255), # Left: Orange (0, 75 / 255, 171 / 255), # Back: Blue (190 / 255, 15 / 255, 56 / 255), # Right: Red (1, 1, 1), # Up: White (1, 210 / 255, 44 / 255), # Down: Yellow ) self.reset() rx = settings.cube_initial_rotation_x * Mathf.DEG_TO_RAD ry = settings.cube_initial_rotation_y * Mathf.DEG_TO_RAD self.apply_rotation(rx, ry, settings.rotate_y_before_x_initially) # auto-rotation repeat = True repetion_count = -1 if settings.cube_auto_rot_x_enabled: begin = settings.cube_auto_rot_x_begin end = settings.cube_auto_rot_x_end jump_start = settings.cube_auto_rot_x_jump_start ease = Tween.get_ease_type_by_name( settings.cube_auto_rot_x_ease_type) self.auto_rot_x = Tween() self.auto_rot_x.tween(begin, end, time, ease, repeat, repetition_count, jump_start) else: self.auto_rot_x = False if settings.cube_auto_rot_y_enabled: begin = settings.cube_auto_rot_y_begin end = settings.cube_auto_rot_y_end time = settings.cube_auto_rot_y_time jump_start = settings.cube_auto_rot_y_jump_start ease = Tween.get_ease_type_by_name( settings.cube_auto_rot_y_ease_type) self.auto_rot_y = Tween() self.auto_rot_y.tween(begin, end, time, ease, repeat, repetition_count, jump_start) else: self.auto_rot_y = False