def _set_data(self): # assign follower value num_of_follower = 0 if self.main_table.follower is None else len( self.main_table.follower) for i in range(3): for f in range(num_of_follower): header_name = attach_column_type[i] person_name = self.main_table.follower[f].name self.container[attach_column_type[i]].container[f].set_value( self._get_ref_value(header_name, person_name)) # set total formula total_coordinate = coordinate_transfer(self.origin[0] + 1, self.origin[1] + 1 + i) + ':' + \ coordinate_transfer(self.origin[0] + 1 + num_of_follower - 1, self.origin[1] + 1 + i) total_formula = "=SUM(" + total_coordinate + ")" self.container[attach_column_type[i]].container[-1].set_formula( total_formula) # assign if table has owner if self.main_table.owner is not None: self.container[attach_column_type[i]].container.append( Cube(bg_color=bg_color[4])) # add total and owner for Target Volume KL # assign total formula total_coordinate = coordinate_transfer(self.origin[0] + 1, self.origin[1] + 4) + ':' + \ coordinate_transfer(self.origin[0] + num_of_follower, self.origin[1] + 4) total_formula = "=SUM(" + total_coordinate + ")" self.container[attach_column_type[3]].container[-1].set_formula( total_formula) # assign if table has owner if self.main_table.owner is not None: self.container[attach_column_type[3]].container.append( Cube(bg_color=bg_color[3]))
def main(): global width, rows, snake, snack width = Cube.width rows = Cube.rows win = pygame.display.set_mode((width, width)) snake = Snake(SNAKE_COlOR, (10, 10)) snack = Cube(randomSnack(rows, snake), color=SNACK_COLOR) clock = pygame.time.Clock() while True: pygame.time.delay(50) clock.tick(10) snake.move() if snake.body[0].position == snack.position: snake.addCube() snack = Cube(randomSnack(rows, snake), color=SNACK_COLOR) for x in range(len(snake.body)): if snake.body[x].position in list( map(lambda z: z.position, snake.body[x + 1:])): message_box('You Lost!', 'Score: {}. Play again!'.format(len(snake.body))) snake.reset((10, 10)) break redrawWindow(win)
def main(w, rows): global snake, food flag = True window = pygame.display.set_mode((w, w)) snake = Snake((10, 10), (255, 0, 0), rows) clock = pygame.time.Clock() food = Cube(randomFood(rows, snake), color=(0, 255, 0)) while flag: pygame.time.delay(10) clock.tick(10) snake.move() if snake.body[0].pos == food.pos: snake.addCube() food = Cube(randomFood(rows, snake), color=(0, 255, 0)) for x in range(len(snake.body)): if snake.body[x].pos in list( map(lambda z: z.pos, snake.body[x + 1:])): print('Score: ', len(snake.body)) snake.reset((10, 10)) break redrawWindow(window, w // rows)
def _sprites(self): sprites = pygame.sprite.Group() if (self.player.alive): color = (255, 255, 0) else: color = (255, 0, 0) for position in self.player.body: cube = Cube(position, color) sprites.add(cube) sprites.add(Cube(self.snack, (0, 255, 0))) return sprites
def _set_style(self): if self.col_type == column_type[1] and self.col_role == role[ 1] and self.formula_type is None: return Cube(bg_color[3]) elif self.col_type == column_type[1] and self.col_role == role[ 2] and self.formula_type is None: return Cube(bg_color[4]) elif self.col_type == column_type[2] and self.formula_type is None: return Cube(bg_color[2]) elif self.formula_type is not None: return Cube(bg_color[1]) else: return Cube(bg_color[4])
def addCube(self): tail = self.body[-1] dx, dy = tail.xDir, tail.yDir if dx == 1 and dy == 0: self.body.append(Cube((tail.pos[0] - 1, tail.pos[1]))) if dx == -1 and dy == 0: self.body.append(Cube((tail.pos[0] + 1, tail.pos[1]))) if dx == 0 and dy == 1: self.body.append(Cube((tail.pos[0], tail.pos[1] - 1))) if dx == 1 and dy == -1: self.body.append(Cube((tail.pos[0], tail.pos[1] + 1))) self.body[-1].xDir = dx self.body[-1].yDir = dy
def addCube(self): tail = self.body[-1] dx, dy = tail.dirnx, tail.dirny if dx == 1 and dy == 0: self.body.append(Cube((tail.pos[0] - 1, tail.pos[1]))) elif dx == -1 and dy == 0: self.body.append(Cube((tail.pos[0] + 1, tail.pos[1]))) elif dx == 0 and dy == 1: self.body.append(Cube((tail.pos[0], tail.pos[1] - 1))) elif dx == 0 and dy == -1: self.body.append(Cube((tail.pos[0], tail.pos[1] + 1))) self.body[-1].dirnx = dx self.body[-1].dirny = dy
def _render_table_header(self): col_num = sheet_type[self.table_type]['header']['a_column'] self.main_table.write_cube_to_book( self.origin[0], self.origin[1], Cube(value='Name', style=Style(bg_color[4], font=font_style[2], al=alignment[1]))) for i in range(1, col_num): self.main_table.write_cube_to_book( self.origin[0], self.origin[1] + i, Cube(value=attach_column_type[i - 1], style=Style(bg_color[4], font=font_style[2], al=alignment[1])))
def _get_last_row(self): if self.last_row == column_last_row[1]: return Cube(bg_color[4]) elif self.last_row == column_last_row[2]: column_sum_style = Style(bg_color=bg_color[4], border=side_style[3]) return Cube(bg_color[4], value='N/A', style=column_sum_style) elif self.last_row == column_last_row[3]: column_sum_style = Style(bg_color=bg_color[1], border=side_style[3]) return Cube(bg_color[1], formula=formula_type[1], style=column_sum_style) else: pass
def addCube(self): tail = self.body[-1] if tail.moving_right(): newTail = Cube((tail.position[0]-1, tail.position[1]), self.color) elif tail.moving_left(): newTail = Cube((tail.position[0]+1, tail.position[1]), self.color) elif tail.moving_down(): newTail = Cube((tail.position[0], tail.position[1]-1), self.color) elif tail.moving_up(): newTail = Cube((tail.position[0], tail.position[1]+1), self.color) newTail.dirnx = tail.dirnx newTail.dirny = tail.dirny self.body.append(newTail)
def innit_snack(self, is_random=True): ''' Re-innitialize the snack to a new position ''' positions = self.snake.body while True: if is_random: x = random.randrange(1, self.rows-1) y = random.randrange(1, self.rows-1) if len(list(filter(lambda z: z.pos == (x, y), positions))) > 0: continue else: break else: return Cube((15,15), cube_type='snack') return Cube((x, y), cube_type='snack')
def main(): pygame.init() Display = (800, 600) pygame.display.set_mode(Display, DOUBLEBUF | OPENGL) glEnable(GL_DEPTH_TEST) obj = Cube() #glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ) x, y = 0, 0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) rot_x = pyrr.Matrix44.from_x_rotation(x) rot_y = pyrr.Matrix44.from_y_rotation(y) transformLoc = glGetUniformLocation(obj.shader, "transform") glUniformMatrix4fv(transformLoc, 1, GL_FALSE, rot_x * rot_y) DrawTriangle() pygame.display.flip() clock.tick(FPS) x += 0.05 y += 0.05
def runTest(self): """ftl_valide() doit faire son job""" c = Cube() self.assertTrue(ftl_valide(c)) c.rot_F() self.assertFalse(ftl_valide(c))
def f2(): steps = read_input('input.txt') steps = [(type, Cube(min_x, max_x, min_y, max_y, min_z, max_z)) for (type, (min_x, max_x, min_y, max_y, min_z, max_z)) in steps] cubes = [] for (type, cube) in steps: tmp_cubes = [] # switch off all cubes in cube with substraction for c in cubes: tmp_cubes.extend(c.substract(cube)) # if the step is to switch on then switch on by adding cube to the list if type == 1: tmp_cubes.append(cube) cubes = tmp_cubes count = 0 for cube in cubes: count += cube.get_volume() print(len(cubes)) print('[f2]: Result = %d' % (count)) return
def animateNotes(): curFrame = 50 tempo = 2.3 song = getDataFromFile('/Volumes/Users/cmgeorge/documents/csongScale.txt') normalizer = 4 colorScaler = 255 / (max(song) / normalizer) for frameDensity in song: frameDensity = int(frameDensity / normalizer) for pix in range(frameDensity): newFill = rgb(255 - frameDensity * colorScaler, 0, frameDensity * colorScaler) newC = Cube(randint(-10, 10), 0, randint(-10, 10), width=0, height=0, depth=0, fill=newFill) newC.setKeyFrame(curFrame - 1) newC.centerY += 10 newC.setWHD(1, 1, 1) newC.setKeyFrame(curFrame + 5) newC.centerY += 10 newC.centerX += randint(-10, 10) newC.centerZ += randint(-10, 10) newC.setWHD(0, 0, 0) newC.setKeyFrame(curFrame + 10) curFrame += tempo
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_minimum_size(400, 300) glClearColor(0.2, 0.3, 0.2, 1.0) glEnable(GL_DEPTH_TEST) self.cube = Cube()
def _cal_Target_Proceed(self): main_table_body = self.main_table.table_body num_of_follower = 0 if self.main_table.follower is None else len( self.main_table.follower) num_of_row = len( self.main_table.follower[0].target[target_mapper[0]].container) for i in range(num_of_follower): # get base volume coordinate base_coordinate = coordinate_transfer(self.origin[0] + 1 + i, self.origin[1] + 4) first_column = coordinate_transfer(main_table_body[0] + 2, main_table_body[1] + 3 + i * 6 + 4) + \ ':' + coordinate_transfer(main_table_body[0] + 2 + num_of_row - 1, main_table_body[1] + 3 + i * 6 + 4) second_column = coordinate_transfer(main_table_body[0] + 2, main_table_body[1] + 3 + i * 6 + 5) + \ ':' + coordinate_transfer(main_table_body[0] + 2 + num_of_row - 1, main_table_body[1] + 3 + i * 6 + 5) formula = '=' + base_coordinate + '*' + 'SUMPRODUCT(' + first_column + ',' + second_column + ')' self.container[attach_column_type[5]].container[i].set_formula( formula) # assign total formula total_coordinate = coordinate_transfer(self.origin[0] + 1, self.origin[1] + 6) + ':' + \ coordinate_transfer(self.origin[0] + num_of_follower, self.origin[1] + 6) total_formula = "=SUM(" + total_coordinate + ")" self.container[attach_column_type[5]].container[-1].set_formula( total_formula) # assign if table has owner if self.main_table.owner is not None: self.container[attach_column_type[5]].container.append( Cube(bg_color=bg_color[3]))
def extend(self): """ Method, which extends snake by 1 cube :return: """ self.body.insert(1, Cube(self.surface, NEON_YELLOW, self.head.x / 2, self.head.y / 2, 28)) self.head.move(*self.d_vector)
def cube(self): print 'Type in the variable you already know.' try: self.a = float(raw_input('a = ')) except (ValueError): self.a = 0 try: self.V = float(raw_input('V = ')) except (ValueError): self.V = 0 try: self.O = float(raw_input('O = ')) except (ValueError): self.O = 0 variables = {} if self.a != 0: variables['a'] = self.a if self.V != 0: variables['V'] = self.V if self.O != 0: variables['O'] = self.O return Cube(variables)
def testConsecutiveMoves(): cube = Cube(jManager.jsonReading("../json/check/x3cube.json")) state = State(cube) print(state.md5) letters = ["B", "b", "D", "d", "L", "l"] moves = [] for element in letters: for number in range(cube.size): moves.append(element + str(number)) while True: key = 0 print("\nOption's movements: ") print(",".join([item for item in moves])) key = input("Selection:") try: method = getattr(cube, key[0]) method(int(key[1])) state = State(cube) print(state.md5) except: print("ERROR. Not valid movement") jManager.jsonWriting('/testing', state.current) pprint(state.current.faces) print("Results have been saved in testing.json") time.sleep(1)
def main(input_dir=None): # Input the faces of the Cube if input_dir is None: captured_faces, captured_imgs = capture_faces() else: input_imgs = load_imgs_from_dir(input_dir) captured_faces, captured_imgs = capture_faces_from_images(input_imgs) # Get the color classifier clf_yuv = get_classifier() # Predict the face colors from the input images faces = np.array(captured_faces) pred_colors_yuv, pred_proba_yuv = label_images(clf_yuv, [faces]) colors_cube = np.array(pred_colors_yuv).reshape((6, 3, 3)) # Inspect / adjust results if necessary. This step can modify pred_colors_yuv2. check_images(captured_imgs, captured_faces, colors_cube, clf_yuv) plt.show() # Define the cube using the updated colors c = Cube(colors_cube) # Solve and retain moves initial_state = c.export_state() s = Solver(c) s.solve() solve_moves = c.recorded_moves # Display the solution sg = SolutionGallery(initial_state, solve_moves) plt.show()
def __init__(self, pos, color, rows): self.color = color self.head = Cube(pos) self.body.append(self.head) self.dirX = 1 self.dirY = 0 self.rows = rows
def animateNotes(): depthMap = getDataFromFile( '/Volumes/Users/cmgeorge/documents/depthData.txt') imageData = getDataFromFile('/Volumes/Users/cmgeorge/documents/garage.txt') imageRows = len(imageData) imageCols = len(imageData[0]) depthRows = len(depthMap) depthCols = len(depthMap[0]) rowScaling = depthRows / float(imageRows) colScaling = depthCols / float(imageCols) top = imageRows * .25 for r in range(imageRows): for c in range(imageCols): pix = imageData[r][c] col = rgb(pix[0], pix[1], pix[2]) depthRow = int(math.floor(r * rowScaling)) depthCol = int(math.floor(c * colScaling)) z = float(depthMap[depthRow][depthCol]) Cube(c * .25, top - (r * .25), z, width=.25, height=.25, depth=.25, fill=col)
def animateNotes(): curFrame = 50 tempo = 2.227 song = getDataFromFile('Users/cmgeorge/Documents/crush.txt') normalizer = 4.0 colorScaler = 255 / (max(song) / 1.0) blocks = [] ogColor = rgb(255, 255, 255) for i in range(8): newC = Cube(i*2, 0, 0) blocks.append(newC) maxNum = max(song) for i in range(len(song)): curBlock = blocks[i%8] frameDensity = song[i] newFill = rgb(255 - frameDensity*colorScaler, 255 - frameDensity*colorScaler, 255) OldRange = (OldMax - OldMin) NewRange = (NewMax - NewMin) NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin # Change color and deformer curBlock.fill = newFill curBlock.squashDeformer = squashDeformer(lowBound=-10, highBound=1, factor=10, expand=1, maxExpandPos=.01) curBlock.setKeyFrame(curFrame) # Change color and deformer to og set curBlock.fill = ogColor curBlock.squashDeformer = squashDeformer(lowBound=-10, highBound=1, factor=-10, expand=1, maxExpandPos=.01) curBlock.setKeyFrame(curFrame + 16) curFrame += tempo if i == 100: break
def reset(self, pos): self.head = Cube(pos) self.body = [] self.body.append(self.head) self.turns = {} self.dirnx = 0 self.dirny = 1
def game_loop(self): clock = pygame.time.Clock() font = pygame.font.Font('freesansbold.ttf', 32) food = Cube(self.random_food(self.snake), color=(0, 255, 0)) while self.is_running: pygame.time.delay(50) clock.tick(self.clocktick) self.snake.move() if self.check_food(food): food = Cube(self.random_food(self.snake), color=(0, 255, 0)) if self.check_collision(): self.end_menu(self.score) break self.draw_window(self.win, self.snake, food) self.display_score(font) self.display_speed(font) pygame.display.update()
def _render_table_title(self): style = Style(bg_color[4], border=None, font=font_style[3], al=alignment[4]) self.main_table.write_cube_to_book( self.origin[0] - 1, self.origin[1], Cube(bg_color[4], value=self.title, style=style))
def __init__(self, starting_position, color): self.starting_position = starting_position self.head = Cube(starting_position) self.body = [self.head] self.color = color self.xDir = 1 self.yDir = 0 self.turns = {}
def print_cube(self): color_cube = Cube() for i in range(6): for x in range(3): for y in range(3): color = color_cube.int_to_color(self.cube.face[i][x][y]) color_cube.face[i][x][y] = color color_cube.print_cube()
def readCube(self): cube = Cube() for i in range(6): cube.face[i] = self._readFace(i) #cube.face[0] = self._readFace(0) return cube