def mouse_routine(): mouse = Mouse(sleep=1) mouse.get_position() mouse.move(10, 10) mouse.double_click() mouse.set_position(200, 400) mouse.click()
def __init__(self, screen_length, screen_width): self.things = {} self.thing_index = 0 self.screen_length = screen_length self.screen_width = screen_width self.background_color = (0, 0, 0) self.mouse = Mouse()
def voice(): #mouse = Controller() mouse = Mouse() r = sr.Recognizer() while True: debug_print("1") with sr.Microphone() as source: # use the default microphone as the audio source debug_print("2") r.adjust_for_ambient_noise(source) # to reduce noise debug_print("3") audio = r.listen(source) # listen for the first phrase and extract it into audio data debug_print("4") try: print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition if (r.recognize(audio) == 'hey iclicker left click' or r.recognize(audio) == 'left click'): mouse.left_click() elif (r.recognize(audio) == 'hey iclicker right click' or r.recognize(audio) == 'right click'): mouse.right_click() except LookupError: # speech is unintelligible print("Could not understand audio") print("left clicking...") debug_print("5") debug_print("6")
def randomSpawn(self): #Spawner musene for i in range(170): if self.MouseNumber < 150: x = random.randrange(1, 19) y = random.randrange(1, 19) currentMouseSlot = self.grid[x][y] if currentMouseSlot.num_mice < 2: currentMouseSlot.addAnimal("mouse") self.MouseNumber += 1 self.allMices.append(Mouse(x, y, 'x')) #Spawner uglerne for i in range(50): if self.numOwels < 2: x = random.randrange(1,19) y = random.randrange(1,19) currentOwlSlot = self.grid[x][y] if currentOwlSlot.num_owels == 0: currentOwlSlot.addAnimal("owl") self.numOwels += 1 #Placere stenene for i in range(50): if self.rocks < 10: x = random.randrange(1,19) y = random.randrange(1,19) currentRockSpot = self.grid[x][y] if currentRockSpot.has_rock == False: currentRockSpot.has_rock = True self.rocks += 1 self.currentStoneSlots.append(currentRockSpot)
def setUp(self, data): self.mice = [] self.totalTime = 0 for mouse in data.keys(): newMouse = Mouse(mouse) newMouse.setUp(data[mouse]) self.mice.append(newMouse)
def __init__(self, data, cellID): self.id = cellID self.mouseData = Mouse() # To be filled later manually by user self.pipette = Pipette() # To be filled later manually by user self.stims = data['Stims'].keys() # TODO: document self.recordings = self._parseRec(data) self.__attributize()
def __init__(self): self.viewer = None self.low = np.array([self.XMIN, self.YMIN, self.ANGLE_MIN, 0]) self.high = np.array([self.XMAX, self.YMAX, self.ANGLE_MAX, 100]) self.action_space = spaces.Box(np.array([-self.TURN_ANGLE]), np.array([self.TURN_ANGLE])) self.observation_space = spaces.Box(self.low, self.high) self._reference_trajectory = [ (np.cos(deg) * 150 + 300, np.sin(deg) * 150 + 300) for deg in [np.pi * i / 30.0 for i in range(61)] ] shape_fn = lambda x, y: abs((x - 300)**2 + (y - 300)**2 - 150**2) < 2000 self._mouse = Mouse(down=True) self._cloth = ShapeCloth(shape_fn, self._mouse, width=30, height=30, dx=16, dy=16) self.cloth_experiment = Simulation(self._cloth, render=0, init=50) self._seed() self.reset()
def register_and_populate(self): """ this method can be run on a Group given that group.name and group.experiment have been assigned """ experiment = self.experiment experiment.group_named[ self. name] = self # register it with its parent experiment indexed by name experiment.group_numbered[ self.number] = self # register it as indexed by group.number experiment.groups.append(self) # register it in the list of groups # self.color = experiment.groupname_to_color_dictionary[self.name] # self.marker = experiment.groupname_to_marker_dictionary[self.name] self.individual_numbered = { } # the individuals of the group indexed by their number self.mouse_numbered = { } # the individuals of the group indexed by mouseNumber self.individuals = [] # the list of all the individuals in the group for individualNumber, mouseNumber in enumerate( experiment.group_name_to_mouse_number_list_dictionary[ self.name]): M = Mouse() M.mouseNumber = mouseNumber # the true name of a mouse M.group = self # point to its parent M.individualNumber = individualNumber # legacy stuff M.add_days_and_register_with_group() # add mousedays
def single_gbfs(filename): maze, start, goals = file_read(filename) graph = state_representation(maze) mouse = Mouse(start) visited = set() path_dict = {} pqueue = queue.PriorityQueue(maxsize=1000000) pqueue.put((0, start)) count = 0 goal = goals[0] while pqueue: element = pqueue.get() vertex = element[1] visited.add(vertex) if vertex == goal: position = vertex path = [vertex] while position != start: position = path_dict[position] path.append(position) break for neighbor in set(graph.neighbors(vertex)) - visited: count += 1 visited.add(neighbor) path_dict[neighbor] = vertex pqueue.put((m_heuristic(neighbor, goal), neighbor)) mouse = transition_function(mouse, path[::-1], goals) solution(maze, path[::-1], count) return mouse
def single_bfs(filename): maze, start, goals = file_read(filename) graph = state_representation(maze) mouse = Mouse(start) visited, queue = [], [start] path_dict = {} count = 0 while queue: vertex = queue.pop(0) visited.append(vertex) neighborhood = graph.neighbors(vertex) for neighbor in neighborhood: count += 1 if neighbor not in visited and neighbor not in queue: path_dict[neighbor] = vertex queue.append(neighbor) if neighbor in goals: position = neighbor path = [neighbor] while position != start: position = path_dict[position] path.append(position) mouse = transition_function(mouse, path[::-1], goals) solution(maze, path[::-1], count) return mouse
def single_dfs(filename): maze, start, goals = file_read(filename) graph = state_representation(maze) mouse = Mouse(start) visited, stack = set(), [start] path = [] path_dict = {} count = 0 while stack: vertex = stack.pop() if vertex in goals: position = vertex path.append(vertex) while position != start: position = path_dict[position] path.append(position) count += 1 if vertex in visited: continue visited.add(vertex) neighborhood = graph.neighbors(vertex) for neighbor in neighborhood: if neighbor not in visited: path_dict[neighbor] = vertex stack.append(neighbor) mouse = transition_function(mouse, path[::-1], goals) solution(maze, path[::-1], count) return mouse
def __init__(self): self.ir = ImageRecognition() self.tr = TextRecognition() self.db = Database() self.mouse = Mouse() self.clear_minigame() self.button_map_init()
def track_motion(self): """starts tracking the motion of a mouse. (moution?)""" with Mouse() as mouse: while True: try: self.update(mouse) except KeyboardInterrupt: break
def main(): ca = Cat('猫咪') # ca.eat() mou = Mouse('老鼠') # mou.eat() per = Person() per.feedcat(ca) per.feedmouse(mou)
def _create_mouse(self, mouse_number, row_number): """Create a mouse and put it in the row""" mouse = Mouse(self) mouse_width, mouse_height = mouse.rect.size mouse.x = mouse_width + 2 * mouse_width * mouse_number mouse.rect.x = mouse.x mouse.rect.y = mouse.rect.height + 2 * mouse.rect.height * row_number self.mice.add(mouse)
def __init__(self, screen_width, mode, depth, ai_modes, omni): # Variable Initiation self.screen_size = int(screen_width / 2) self.screen = pygame.display.set_mode( (self.screen_size, self.screen_size)) # Where the game is shown self.gamestate = GameState(mode, self.screen_size / 8, depth, ai_modes, omni) self.mouse = Mouse(self.gamestate) self.run = True
def create(cls, name): if name == 'Mouse': return Mouse() elif name == 'Dragon': return Dragon() elif name == 'Snake': return Snake() else: return None
def read_mouse(filename='/dev/input/mice'): # http://wiki.osdev.org/Mouse_Input#Mouse_Packet_Info with Mouse() as mouse: while True: try: status, dx, dy = mouse.update() print('status: {}, dx: {}, dy: {}'.format(status, dx, dy)) except KeyboardInterrupt: break
def __init__(self, ratio=1): self.RUN = True self.TOGGLE = False self.vision = Vision(ratio=ratio) self.keyboard = Keyboard(sleep=1) self.KEYCODES = {1: 18, 2: 19, 3: 20, 4: 21, 5: 23} self.potions_box = {"top": 850, "left": 1920, "width": 500, "height": 200} self.menu_box = {"top": 300, "left": 1920 + 680, "width": 320, "height": 260} self.mouse = Mouse()
def main(): sio = serial.Serial('COM10', baudrate=9600) kb = Keyboard(sio) m = Mouse(sio) while True: m.click() m.release() kb.press(KEY_RETURN) kb.release(KEY_RETURN) kb.press(KEY_RETURN) kb.release(KEY_RETURN) time.sleep(0.8)
def main(): CAT_START = [20, 10] MOUSE_START = [10, 10] NUM_STEPS = 200 puss = Cat(*CAT_START) muss = Mouse(*MOUSE_START) chase = Chase(puss, muss) chase.pursue(NUM_STEPS) chase.animate()
def single_astar(filename): maze, start, goals = file_read(filename) graph = state_representation(maze) mouse = Mouse(start) goal = goals[0] open_list = [(start, 0, m_heuristic(start, goal))] closed_list = [] came_from = {start: None} count = 0 while open_list: myList = [] for i in open_list: myList.append((i[0], i[1] + i[2])) position = min(myList, key=lambda t: t[1])[0] if position in goals: path = [position] while position != start: prev_loc = position position = came_from[prev_loc] path.append(position) break for i in open_list: if i[0] == position: position_cost = i[1] open_list = [(node, g, h) for (node, g, h) in open_list if node != position] closed_list.append(position) for i in graph.neighbors(position): count += 1 if i in closed_list: continue if i in open_list: new_g = position_cost + 1 if new_g < i[1]: i[1] = new_g came_from[i] = position else: g_val = position_cost + 1 h_val = m_heuristic(i, goal) came_from[i] = position open_list.append((i, g_val, h_val)) mouse = transition_function(mouse, path[::-1], goals) solution(maze, path[::-1], count) return mouse
def __init__(self): self.autos = [] self.events = [] self.generation = 0 self.dt = 0 self.top_auto = None self.slow_car_removed = False self.learning_rate = LEARNING_RATE self.viewer = TargetViewer(self) self.mouse = Mouse(self) self.track = RaceTrack(self) self.text = Text("Generation : 0") self.start_time = pygame.time.get_ticks() self.addNewAutos(num_car)
def __init__(self, x, y, title="New Location"): self.title = title self.mouse = Mouse() self.keyboard = Keyboard() try: self.x = int(x) self.y = int(y) self._is_mouse_down = False logger.debug( 'New Location with name "{name}" created ({x}, {y})'.format( name=self.title, x=self.x, y=self.y)) except: raise FailExit('Incorect Location class constructor call:' '\n\tx = {x}\n\ty = {y}\n\ttitle= %{title}'.format( x=x, y=y, title=title))
def __init__(self, maze, window): """Set up the game""" pygame.key.set_repeat(50) window.fill((0, 0, 0)) self._solving = False self._solution = [] self.window = window self.maze = maze self.maze.generate_maze() self.mouse = Mouse(maze) self.mouse_image = pygame.transform.scale( pygame.image.load("mouse.png"), (20, 20)) self.cheese_image = pygame.transform.scale( pygame.image.load("cheese.png"), (20, 20)) self.victory = False self.score_box = MazeDisplay.ScoreBox(pygame.font.Font(None, 30)) self.make_board()
def setup_level(self): self.current_level = self.levels[self.level_num] start_state = self.current_level["start_state"] #Add the game actors actors = {} actors["cat"] = Cat("cat", start_state['player'][0], start_state['player'][1]) for i in range(len(start_state["mice"])): m = start_state["mice"][i] name = "mouse %d" % i actors[name] = Mouse(name, m[0], m[1]) self.level_map = SimpleMap(self.current_level["map_object"], actors, self.assets) self.level_map.draw_map() self.state = STATE.RUN_LEVEL
def __init__(self): self.statespace_limits = np.array( [[self.XMIN, self.XMAX], [self.YMIN, self.YMAX], [self.ANGLE_MIN, self.ANGLE_MAX], [0, 100]]) self.reference_trajectory = [(np.cos(deg) * 150 + 300, np.sin(deg) * 150 + 300) for deg in [ np.pi * i / 30.0 for i in range(61)]] shape_fn = lambda x, y: abs((x - 300) **2 + (y - 300) ** 2 - 150 **2) < 2000 self._mouse = Mouse(down=True) self._cloth = ShapeCloth(shape_fn, self._mouse, width=30, height=30, dx=16, dy=16) self.cloth_experiment = Simulation(self._cloth, render=0, init=50) self.return_to_goal = False self.episodeCap = 60 logging.getLogger().setLevel(logging.DEBUG) super(ClothCutter, self).__init__()
def _create_pack(self): """Create a pack of mice""" #Create a mouse and find the number of mice in a row #Spacing between each mouse is equal to one mouse width mouse = Mouse(self) mouse_width, mouse_height = mouse.rect.size available_space_x = self.settings.screen_width - (2 * mouse_width) number_mice_x = available_space_x // (2 * mouse_width) # Determine the number of mice that can fit on the screen cat_height = self.cat.rect.height available_space_y = (self.settings.screen_height - (3 * mouse_height) - cat_height) number_rows = available_space_y // (4 * mouse_height) # Create the full pack of mice for row_number in range(number_rows): for mouse_number in range(number_mice_x): self._create_mouse(mouse_number, row_number)
def __init__(self): self.thread = None self.reload = False # Time variables self.time_cycle = 80 self.ideal_cycle = 80 self.iteration_counter = 0 self.real_time_factor = 0 self.frequency_message = {'brain': '', 'gui': '', 'rtf': ''} self.server = None self.client = None self.host = sys.argv[1] # Initialize the GUI, HAL and Console behind the scenes self.hal = HAL() self.mouse = Mouse() self.gui = GUI(self.host, self.hal, self.mouse)
def display_welcome(self): self.loading = True start_text = pygame.font.Font(None, 18).render( "Begin!", False, (0, 0, 0)) maze_demo = Maze((9, 9)) mouse_demo = Mouse(maze_demo) mouse_image = pygame.transform.scale( pygame.image.load("mouse.png"), (20, 20)) board_demo = pygame.Surface((180, 180)) pygame.draw.rect(board_demo, (150, 150, 150), pygame.Rect(20, 20, 140, 140)) for x in range(1, 8): for y in range(1, 8): maze_demo.change_cell((x, y)) while self.loading: #demo maze blitting, updating self.window.blit(pygame.transform.scale(board_demo, self.window.get_size()), (0, 0)) board_demo.fill((0, 0, 0)) pygame.draw.rect(board_demo, (150, 150, 150), pygame.Rect(20, 20, 140, 140)) board_demo.blit( pygame.transform.rotate(mouse_image, 90 * mouse_demo.facing), (20 * mouse_demo.pos[0], 20 * mouse_demo.pos[1])) mouse_demo.demo_move() #start button pygame.draw.rect(board_demo, (0, 200, 0), pygame.Rect(70, 80, 40, 20)) self.start_mask = pygame.mask.from_threshold( board_demo, (0, 200, 0), (10, 10, 10, 255)).scale(( self.window.get_width(), self.window.get_height())) pygame.draw.rect(board_demo, (0, 0, 0), pygame.Rect(70, 80, 40, 20), 1) board_demo.blit(start_text, ( 90 - start_text.get_width() / 2, 90 - start_text.get_height() / 2)) #events and flip self.check_events() pygame.display.flip()