Reference¶
- class pyglet2d.Shape(vertices, color=(255, 255, 255), velocity=(0, 0), angular_velocity=0, colors=None)[source]¶
Graphical polygon primitive for use with pyglet.
Alternative constructor methods:
Parameters : vertices : array-like or Polygon3.Polygon.
If a Polygon3.Polygon is passed, its points will be used. Otherwise, vertices should be a sequence of [x, y] locations or an array with x and y columns.
color : str or 3-tuple of int, optional
Color, in R, G, B format. Alternatively, a key that refers to an element of colors.
velocity : array-like
Speed and direction of motion, in [dx_dt, dy_dt] format.
angular_velocity : float
Speed of angular motion, in counter-clockwise radians per second.
colors : dict of tuple, optional
Named colors, defined as R, G, B tuples. Useful for easily switching between a set of colors.
Attributes
poly (Polygon3.Polygon) Associated Polygon3.Polygon object. vertices (array) An array of points, with x and y columns. Read-only. center (array) The centroid of the shape. Setting center calls translate. position (array) Alias for center. radius (array) Mean distance from each point to the center. Setting radius calls scale. color (str or tuple of int) The current color, in R, G, B format if colors was not passed. Otherwise, the current color is represented as a key in colors. colors (dict of tuple) Named colors. velocity (array) Speed and direction of linear motion. Angular_velocity (float) Speed of angular motion, in counter-clockwise radians per second. enabled (bool) If False, the shape will not be drawn. - classmethod circle(center, radius, n_vertices=50, **kwargs)[source]¶
Construct a circle.
Parameters : center : array-like
radius : float
n_vertices : int, optional
Number of points to draw. Decrease for performance, increase for appearance.
kwargs
Other keyword arguments are passed to the Shape constructor.
- covers(self, other)[source]¶
Check if the shape completely covers another shape.
Parameters : other : Shape Returns : bool
- distance_to(self, point)[source]¶
Distance from center to arbitrary point.
Parameters : point : array-like Returns : float
- flip(self, angle, center=None)[source]¶
Flip the shape in an arbitrary direction.
Parameters : angle : array-like
The angle, in radians counter-clockwise from the horizontal axis, defining the angle about which to flip the shape (of a line through center).
center : array-like, optional
The point about which to flip. If not passed, the center of the shape will be used.
- flip_x(self, center=None)[source]¶
Flip the shape in the x direction, in-place.
Parameters : center : array-like, optional
Point about which to flip. If not passed, the center of the shape will be used.
- flip_y(self, center=None)[source]¶
Flip the shape in the y direction, in-place.
Parameters : center : array-like, optional
Point about which to flip. If not passed, the center of the shape will be used.
- classmethod from_dict(spec)[source]¶
Create a Shape from a dictionary specification.
Parameters : spec : dict
A dictionary with either the fields 'center' and 'radius' (for a circle), 'center', 'radius', and 'n_vertices' (for a regular polygon), or 'vertices'. If only two vertices are given, they are assumed to be lower left and top right corners of a rectangle. Other fields are interpreted as keyword arguments.
- classmethod rectangle(vertices, **kwargs)[source]¶
Shortcut for creating a rectangle aligned with the screen axes from only two corners.
Parameters : vertices : array-like
An array containing the [x, y] positions of two corners.
kwargs
Other keyword arguments are passed to the Shape constructor.
- classmethod regular_polygon(center, radius, n_vertices, start_angle=0, **kwargs)[source]¶
Construct a regular polygon.
Parameters : center : array-like
radius : float
n_vertices : int
start_angle : float, optional
Where to put the first point, relative to center, in radians counter-clockwise starting from the horizontal axis.
kwargs
Other keyword arguments are passed to the Shape constructor.
- rotate(self, angle, center=None)[source]¶
Rotate the shape, in-place.
Parameters : angle : float
Angle to rotate, in radians counter-clockwise.
center : array-like, optional
Point about which to rotate. If not passed, the center of the shape will be used.
- scale(self, factor, center=None)[source]¶
Resize the shape by a proportion (e.g., 1 is unchanged), in-place.
Parameters : factor : float or array-like
If a scalar, the same factor will be applied in the x and y dimensions.
center : array-like, optional
Point around which to perform the scaling. If not passed, the center of the shape is used.