Best Python code snippet using ATX
viz.py
Source:viz.py
...10 self.min = np.zeros(3)11 def _update_limits(self, x):12 self.max = np.max([self.max, x], axis=0)13 self.min = np.min([self.min, x], axis=0)14 def _draw_lines(self, starts, ends, color):15 for s, e in zip(starts, ends):16 self._update_limits(s)17 self._update_limits(e)18 self.ax.plot([s[0], e[0]], [s[1], e[1]], [s[2], e[2]], color=color)19 def draw_axes(self, pose, length=DEFAULT_AXIS_LENGTH):20 o_0 = length * np.array([0, 0, 0])21 x_0 = length * np.array([1, 0, 0])22 y_0 = length * np.array([0, 1, 0])23 z_0 = length * np.array([0, 0, 1])24 o = pose * o_025 x = pose * x_026 y = pose * y_027 z = pose * z_028 self._draw_lines([o], [x], color="r")29 self._draw_lines([o], [y], color="g")30 self._draw_lines([o], [z], color="b")31 def draw_camera(self, pose, size, color="grey", axes=True):32 # Draw a pyramid representing a camera33 b0_0 = size * np.array([0.5, 0.5, 0])34 b1_0 = size * np.array([0.5, -0.5, 0])35 b2_0 = size * np.array([-0.5, -0.5, 0])36 b3_0 = size * np.array([-0.5, 0.5, 0])37 t_0 = size * np.array([0, 0, -1])38 b0 = pose * b0_039 b1 = pose * b1_040 b2 = pose * b2_041 b3 = pose * b3_042 t = pose * t_043 starts = [b0, b1, b2, b3, b0, b1, b2, b3]44 ends = [b1, b2, b3, b0, t, t, t, t]45 self._draw_lines(starts, ends, color)46 # Draw camera axes47 if axes:48 self.draw_axes(pose, length=size / 2.0)49 def draw_marker(self, pose, id, length, color="k", show_id=False):50 # Draw marker outline51 c0_0 = 0.5 * length * np.array([1, 1, 0])52 c1_0 = 0.5 * length * np.array([-1, 1, 0])53 c2_0 = 0.5 * length * np.array([-1, -1, 0])54 c3_0 = 0.5 * length * np.array([1, -1, 0])55 c0 = pose * c0_056 c1 = pose * c1_057 c2 = pose * c2_058 c3 = pose * c3_059 starts = [c0, c1, c2, c3]60 ends = [c1, c2, c3, c0]61 self._draw_lines(starts, ends, color)62 # Draw marker ID63 if show_id:64 pos = pose.translation()65 self.ax.text(pos[0], pos[1], pos[2], id, color="b")66 def show(self):67 # Set limits68 mid = (self.max + self.min) / 2.069 r = max(np.max(self.max - mid), np.max(mid - self.min))70 self.ax.set_xlim(mid[0] - r, mid[0] + r)71 self.ax.set_ylim(mid[1] - r, mid[1] + r)72 self.ax.set_zlim(mid[2] - r, mid[2] + r)73 # Show...
menus.py
Source:menus.py
...26 if (self.current_line_index > 0):27 self.current_line_index -= 128 def draw(self):29 if (self.has_changed()):30 self._draw_lines()31 def has_changed(self):32 if (self.current_line_index != self.last_line_index):33 self.last_line_index = self.current_line_index34 return True35 return False36 def _draw_lines(self):37 for i, line in enumerate(self.lines):38 if (i == self.current_line_index):39 print(f"{line} <---")40 else:41 print(line)42 def _clear_screen(self):43 os.system("cls")44 def _title_bar(self):45 print("Flash Tracker v1.0")46 print("==================\n")47# the first menu that user will be prompted to interact with upon entering48class MainMenu(Menu):49 def __init__(self):50 super().__init__()51 self.identifier = "main_menu"52 self.lines = [53 "Create a new lobby ",54 "Join an existing lobby",55 "Settings "56 ]57 self._clear_screen()58 self._title_bar()59 self._draw_lines()60 def draw(self):61 if (self.has_changed()):62 self._clear_screen()63 self._title_bar()64 self._draw_lines()65class CreateLobbyMenu(Menu):66 def __init__(self):67 super().__init__()68 self.identifier = "create_lobby_menu"69 self.lobby_name = ""70 def draw(self):71 self._clear_screen()72 self._title_bar()73 print("Name of the lobby:")...
animation.py
Source:animation.py
...3def _draw_coordinate_cross(screen, width, height):4 cross_color = pygame.Color(44,33,120)5 pygame.draw.line(screen, cross_color, (0, height/2), (width, height/2), 2)6 pygame.draw.line(screen, cross_color, (width/2, 0), (width/2, height), 2)7def _draw_lines(screen, vals, rgb, width, height):8 r, g, b = rgb9 line_color = pygame.Color(r, g, b)10 last_spot = None11 vtup = zip(list(range(width)), vals[:width])12 for _xy in vtup:13 xy = (_xy[0], _xy[1] * (1/(2*POS_MAX/height)) * 0.8 + height/2) # scale amplitude to graph-size14 if last_spot is not None:15 pygame.draw.line(screen, line_color, last_spot, xy, 2)16 print('({}:{} -> {}:{})'.format(last_spot[0], last_spot[1], xy[0], xy[1]))17 last_spot = xy18def controls_display():19 pygame.font.init()20 controls_font = pygame.font.SysFont('dejavusans', 24)21 return controls_font.render('frequency', True, (55,200,200))22def play_wave(audio):23 pygame.mixer.init()24 print(pygame.mixer.get_init())25 print(pygame.mixer.get_num_channels())26 snd = pygame.sndarray.make_sound(audio)27 print(snd.get_length())28 while True:29 snd.play()30def draw_wave(f1, f2):31 pygame.init()32 width = 102433 height = 76834 screen = pygame.display.set_mode((width, height))35 pygame.display.set_caption('Monkey Fever')36 pygame.mouse.set_visible(1)37 background = pygame.Surface(screen.get_size())38 background = background.convert()39 background.fill((20, 20, 20))40 screen.blit(background, (0, 0))41 _draw_coordinate_cross(screen, width, height)42 _draw_lines(screen, f1, [55, 155, 55], width, height)43 _draw_lines(screen, f2, [166, 66, 66], width, height)44 controls = controls_display()45 screen.blit(controls, (800, 20))46 pygame.display.flip()47 while True:48 event = pygame.event.wait()49 if (event.type == pygame.QUIT or50 (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)):51 break...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!