How to use _update_position method in avocado

Best Python code snippet using avocado_python Github


Full Screen

...121 if self._vertex_list is not None:122 self._vertex_list.delete()123 except:124 pass125 def _update_position(self):126 raise NotImplementedError127 def _update_color(self):128 raise NotImplementedError129 def draw(self):130 """Draw the shape at its current position.131 Using this method is not recommended. Instead, add the132 shape to a `` for efficient rendering.133 """134 self._group.set_state_recursive()135 self._vertex_list.draw(GL_TRIANGLES)136 self._group.unset_state_recursive()137 def delete(self):138 self._vertex_list.delete()139 self._vertex_list = None140 @property141 def x(self):142 """X coordinate of the shape.143 :type: int or float144 """145 return self._x146 @x.setter147 def x(self, value):148 self._x = value149 self._update_position()150 @property151 def y(self):152 """Y coordinate of the shape.153 :type: int or float154 """155 return self._y156 @y.setter157 def y(self, value):158 self._y = value159 self._update_position()160 @property161 def position(self):162 """The (x, y) coordinates of the shape, as a tuple.163 :Parameters:164 `x` : int or float165 X coordinate of the sprite.166 `y` : int or float167 Y coordinate of the sprite.168 """169 return self._x, self._y170 @position.setter171 def position(self, values):172 self._x, self._y = values173 self._update_position()174 @property175 def anchor_x(self):176 """The X coordinate of the anchor point177 :type: int or float178 """179 return self._anchor_x180 @anchor_x.setter181 def anchor_x(self, value):182 self._anchor_x = value183 self._update_position()184 @property185 def anchor_y(self):186 """The Y coordinate of the anchor point187 :type: int or float188 """189 return self._anchor_y190 @anchor_y.setter191 def anchor_y(self, value):192 self._anchor_y = value193 self._update_position()194 @property195 def anchor_position(self):196 """The (x, y) coordinates of the anchor point, as a tuple.197 :Parameters:198 `x` : int or float199 X coordinate of the anchor point.200 `y` : int or float201 Y coordinate of the anchor point.202 """203 return self._anchor_x, self._anchor_y204 @anchor_position.setter205 def anchor_position(self, values):206 self._anchor_x, self._anchor_y = values207 self._update_position()208 @property209 def color(self):210 """The shape color.211 This property sets the color of the shape.212 The color is specified as an RGB tuple of integers '(red, green, blue)'.213 Each color component must be in the range 0 (dark) to 255 (saturated).214 :type: (int, int, int)215 """216 return self._rgb217 @color.setter218 def color(self, values):219 self._rgb = list(map(int, values))220 self._update_color()221 @property222 def opacity(self):223 """Blend opacity.224 This property sets the alpha component of the color of the shape.225 With the default blend mode (see the constructor), this allows the226 shape to be drawn with fractional opacity, blending with the227 background.228 An opacity of 255 (the default) has no effect. An opacity of 128229 will make the shape appear translucent.230 :type: int231 """232 return self._opacity233 @opacity.setter234 def opacity(self, value):235 self._opacity = value236 self._update_color()237 @property238 def visible(self):239 """True if the shape will be drawn.240 :type: bool241 """242 return self._visible243 @visible.setter244 def visible(self, value):245 self._visible = value246 self._update_position()247class Arc(_ShapeBase):248 def __init__(self, x, y, radius, segments=25, angle=math.pi*2, color=(255, 255, 255), batch=None, group=None):249 # TODO: Finish this shape and add docstring.250 self._x = x251 self._y = y252 self._radius = radius253 self._segments = segments254 self._rgb = color255 self._angle = angle256 self._batch = batch or Batch()257 self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)258 self._vertex_list = self._batch.add(self._segments*2, GL_LINES, self._group, 'v2f', 'c4B')259 self._update_position()260 self._update_color()261 def _update_position(self):262 if not self._visible:263 vertices = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)264 else:265 x = self._x + self._anchor_x266 y = self._y + self._anchor_y267 r = self._radius268 tau_segs = self._angle / (self._segments - 1)269 # Calcuate the outer points of the arc:270 points = [(x + (r * math.cos(i * tau_segs)),271 y + (r * math.sin(i * tau_segs))) for i in range(self._segments)]272 # Create a list of doubled-up points from the points:273 vertices = []274 for i, point in enumerate(points):275 line_points = *points[i-1], *point276 vertices.extend(line_points)277 self._vertex_list.vertices[:] = vertices278 def _update_color(self):279 self._vertex_list.colors[:] = [*self._rgb, int(self._opacity)] * self._segments * 2280 def draw(self):281 """Draw the shape at its current position.282 Using this method is not recommended. Instead, add the283 shape to a `` for efficient rendering.284 """285 self._vertex_list.draw(GL_LINES)286class Circle(_ShapeBase):287 def __init__(self, x, y, radius, segments=None, color=(255, 255, 255), batch=None, group=None):288 """Create a circle.289 The circle's anchor point (x, y) defaults to the center of the circle.290 :Parameters:291 `x` : float292 X coordinate of the circle.293 `y` : float294 Y coordinate of the circle.295 `radius` : float296 The desired radius.297 `segments` : int298 You can optionally specifify how many distict triangles299 the circle should be made from. If not specified, it will300 be automatically calculated based on the radius.301 `color` : (int, int, int)302 The RGB color of the circle, specified as a tuple of303 three ints in the range of 0-255.304 `batch` : ``305 Optional batch to add the circle to.306 `group` : ``307 Optional parent group of the circle.308 """309 self._x = x310 self._y = y311 self._radius = radius312 self._segments = segments or int(radius / 1.25)313 self._rgb = color314 self._batch = batch or Batch()315 self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)316 self._vertex_list = self._batch.add(self._segments*3, GL_TRIANGLES, self._group, 'v2f', 'c4B')317 self._update_position()318 self._update_color()319 def _update_position(self):320 if not self._visible:321 vertices = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)322 else:323 x = self._x + self._anchor_x324 y = self._y + self._anchor_y325 r = self._radius326 tau_segs = math.pi * 2 / self._segments327 # Calcuate the outer points of the circle:328 points = [(x + (r * math.cos(i * tau_segs)),329 y + (r * math.sin(i * tau_segs))) for i in range(self._segments)]330 # Create a list of trianges from the points:331 vertices = []332 for i, point in enumerate(points):333 triangle = x, y, *points[i-1], *point334 vertices.extend(triangle)335 self._vertex_list.vertices[:] = vertices336 def _update_color(self):337 self._vertex_list.colors[:] = [*self._rgb, int(self._opacity)] * self._segments * 3338 @property339 def radius(self):340 """The radius of the circle.341 :type: float342 """343 return self._radius344 @radius.setter345 def radius(self, value):346 self._radius = value347 self._update_position()348class Line(_ShapeBase):349 def __init__(self, x, y, x2, y2, width=1, color=(255, 255, 255), batch=None, group=None):350 """Create a line.351 The line's anchor point defaults to the center of the line's352 width on the X axis, and the Y axis.353 :Parameters:354 `x` : float355 The first X coordinate of the line.356 `y` : float357 The first Y coordinate of the line.358 `x2` : float359 The second X coordinate of the line.360 `y2` : float361 The second Y coordinate of the line.362 `width` : float363 The desired width of the line.364 `color` : (int, int, int)365 The RGB color of the line, specified as a tuple of366 three ints in the range of 0-255.367 `batch` : ``368 Optional batch to add the line to.369 `group` : ``370 Optional parent group of the line.371 """372 self._x = x373 self._y = y374 self._x2 = x2375 self._y2 = y2376 self._width = width377 self._rotation = math.degrees(math.atan2(y2 - y, x2 - x))378 self._rgb = color379 self._batch = batch or Batch()380 self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)381 self._vertex_list = self._batch.add(6, GL_TRIANGLES, self._group, 'v2f', 'c4B')382 self._update_position()383 self._update_color()384 def _update_position(self):385 if not self._visible:386 self._vertex_list.vertices[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)387 else:388 x1 = -self._anchor_y389 y1 = self._anchor_x - self._width / 2390 x = self._x391 y = self._y392 x2 = x1 + math.hypot(self._y2 - y, self._x2 - x)393 y2 = y1 + self._width394 r = math.atan2(self._y2 - y, self._x2 - x)395 cr = math.cos(r)396 sr = math.sin(r)397 ax = x1 * cr - y1 * sr + x398 ay = x1 * sr + y1 * cr + y399 bx = x2 * cr - y1 * sr + x400 by = x2 * sr + y1 * cr + y401 cx = x2 * cr - y2 * sr + x402 cy = x2 * sr + y2 * cr + y403 dx = x1 * cr - y2 * sr + x404 dy = x1 * sr + y2 * cr + y405 self._vertex_list.vertices[:] = (ax, ay, bx, by, cx, cy, ax, ay, cx, cy, dx, dy)406 def _update_color(self):407 self._vertex_list.colors[:] = [*self._rgb, int(self._opacity)] * 6408 @property409 def x2(self):410 """Second X coordinate of the shape.411 :type: int or float412 """413 return self._x2414 @x2.setter415 def x2(self, value):416 self._x2 = value417 self._update_position()418 @property419 def y2(self):420 """Second Y coordinate of the shape.421 :type: int or float422 """423 return self._y2424 @y2.setter425 def y2(self, value):426 self._y2 = value427 self._update_position()428 @property429 def position(self):430 """The (x, y, x2, y2) coordinates of the line, as a tuple.431 :Parameters:432 `x` : int or float433 X coordinate of the sprite.434 `y` : int or float435 Y coordinate of the sprite.436 `x2` : int or float437 X2 coordinate of the sprite.438 `y2` : int or float439 Y2 coordinate of the sprite.440 """441 return self._x, self._y, self._x2, self._y2442 @position.setter443 def position(self, values):444 self._x, self._y, self._x2, self._y2 = values445 self._update_position()446class Rectangle(_ShapeBase):447 def __init__(self, x, y, width, height, color=(255, 255, 255), batch=None, group=None):448 """Create a rectangle or square.449 The rectangles's anchor point defaults to the (x, y) coordinates,450 which are at the bottom left.451 :Parameters:452 `x` : float453 The X coordinate of the rectangle.454 `y` : float455 The Y coordinate of the rectangle.456 `width` : float457 The width of the rectangle.458 `height` : float459 The height of the rectangle.460 `color` : (int, int, int)461 The RGB color of the rectangle, specified as462 a tuple of three ints in the range of 0-255.463 `batch` : ``464 Optional batch to add the rectangle to.465 `group` : ``466 Optional parent group of the rectangle.467 """468 self._x = x469 self._y = y470 self._width = width471 self._height = height472 self._rotation = 0473 self._rgb = color474 self._batch = batch or Batch()475 self._group = _ShapeGroup(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, group)476 self._vertex_list = self._batch.add(6, GL_TRIANGLES, self._group, 'v2f', 'c4B')477 self._update_position()478 self._update_color()479 def _update_position(self):480 if not self._visible:481 self._vertex_list.vertices = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)482 elif self._rotation:483 x1 = -self._anchor_x484 y1 = -self._anchor_y485 x2 = x1 + self._width486 y2 = y1 + self._height487 x = self._x488 y = self._y489 r = -math.radians(self._rotation)490 cr = math.cos(r)491 sr = math.sin(r)492 ax = x1 * cr - y1 * sr + x493 ay = x1 * sr + y1 * cr + y494 bx = x2 * cr - y1 * sr + x495 by = x2 * sr + y1 * cr + y496 cx = x2 * cr - y2 * sr + x497 cy = x2 * sr + y2 * cr + y498 dx = x1 * cr - y2 * sr + x499 dy = x1 * sr + y2 * cr + y500 self._vertex_list.vertices = (ax, ay, bx, by, cx, cy, ax, ay, cx, cy, dx, dy)501 else:502 x1 = self._x - self._anchor_x503 y1 = self._y - self._anchor_y504 x2 = x1 + self._width505 y2 = y1 + self._height506 self._vertex_list.vertices = (x1, y1, x2, y1, x2, y2, x1, y1, x2, y2, x1, y2)507 def _update_color(self):508 self._vertex_list.colors[:] = [*self._rgb, int(self._opacity)] * 6509 @property510 def width(self):511 """The width of the rectangle.512 :type: float513 """514 return self._width515 @width.setter516 def width(self, value):517 self._width = value518 self._update_position()519 @property520 def height(self):521 """The height of the rectangle.522 :type: float523 """524 return self._height525 @height.setter526 def height(self, value):527 self._height = value528 self._update_position()529 @property530 def rotation(self):531 """Clockwise rotation of the rectangle, in degrees.532 The Rectangle will be rotated about its (anchor_x, anchor_y)533 position.534 :type: float535 """536 return self._rotation537 @rotation.setter538 def rotation(self, rotation):539 self._rotation = rotation...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?