psychos.visual.Rectangle#
- class psychos.visual.Rectangle(position: Tuple[float, float] = (0, 0), width: float | None = None, height: float | None = None, color: ColorType = None, window: Window | None = None, coordinates: UnitType | Unit | None = None, anchor_x: AnchorHorizontal = 'center', anchor_y: AnchorVertical = 'center', rotation: float = 0, **kwargs)[source]#
Bases:
Rectangle- __init__(position: Tuple[float, float] = (0, 0), width: float | None = None, height: float | None = None, color: ColorType = None, window: Window | None = None, coordinates: UnitType | Unit | None = None, anchor_x: AnchorHorizontal = 'center', anchor_y: AnchorVertical = 'center', rotation: float = 0, **kwargs)[source]#
A rectangle shape that can be drawn on the screen.
- Parameters:
position (Tuple[float, float], default=(0, 0)) – The position of the rectangle in the window.
width (Optional[float], default=None) – The width of the rectangle, in the units of the window or the given coordinates.
height (Optional[float], default=None) – The height of the rectangle, in the units of the window or the given coordinates.
color (Optional[ColorType], default=None) – The color of the rectangle.
window (Optional[Window], default=None) – The window in which the rectangle will be displayed.
coordinates (Optional[Union[UnitType, Unit]], default=None) – The unit system to be used for positioning the rectangle.
anchor_x (AnchorHorizontal, default="center") – The horizontal anchor alignment of the rectangle.
anchor_y (AnchorVertical, default="center") – The vertical anchor alignment of the rectangle.
rotation (float, default=0) – The rotation angle of the rectangle (in degrees 0-360).
kwargs (dict) – Additional keyword arguments to pass to the Pyglet Rectangle.
Methods
__init__([position, width, height, color, ...])A rectangle shape that can be drawn on the screen.
delete()Force immediate removal of the shape from video memory.
draw()Debug method to draw a single shape at its current position.
get_shape_group()Creates and returns a group to be used to render the shap[e.
Attributes
anchor_positionGet/set the anchor's
(x, y)offset fromposition.anchor_xGet/set the X coordinate of the anchor point.
anchor_yGet/set the Y coordinate of the anchor point.
batchGet/set the
Batchfor this shape.blend_modeThe current blend mode applied to this shape.
Get/set the shape's color.
Get the coordinate system used for the text.
groupGet/set the shape's
Group.Get/set the height of the rectangle.
opacityGet/set the blend opacity of the shape.
Get the position of the text in pixels.
programThe current shader program.
rotationGet/set the shape's clockwise rotation in degrees.
visibleGet/set whether the shape will be drawn at all.
Get/set width of the rectangle.
xGet/set the X coordinate of the shape's
position.yGet/set the Y coordinate of the shape's
position.zGet/set the Z coordinate of the shape.
- property color: tuple[int, int, int, int]#
Get/set the shape’s color.
The color may set to:
An RGBA tuple of integers
(red, green, blue, alpha)An RGB tuple of integers
(red, green, blue)
If an RGB color is set, the current alpha will be preserved. Otherwise, the new alpha value will be used for the shape. Each color component must be in the range 0 (dark) to 255 (saturated).
- draw() Rectangle[source]#
Debug method to draw a single shape at its current position.
Warning
Avoid this inefficient method for everyday use!
Regular drawing should add shapes to a
Batchand call itsdraw()method.