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_position

Get/set the anchor's (x, y) offset from position.

anchor_x

Get/set the X coordinate of the anchor point.

anchor_y

Get/set the Y coordinate of the anchor point.

batch

Get/set the Batch for this shape.

blend_mode

The current blend mode applied to this shape.

color

Get/set the shape's color.

coordinates

Get the coordinate system used for the text.

group

Get/set the shape's Group.

height

Get/set the height of the rectangle.

opacity

Get/set the blend opacity of the shape.

position

Get the position of the text in pixels.

program

The current shader program.

rotation

Get/set the shape's clockwise rotation in degrees.

visible

Get/set whether the shape will be drawn at all.

width

Get/set width of the rectangle.

x

Get/set the X coordinate of the shape's position.

y

Get/set the Y coordinate of the shape's position.

z

Get/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).

property coordinates: Unit#

Get the coordinate system used for the text.

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 Batch and call its draw() method.

property height: float#

Get/set the height of the rectangle.

The bottom and top of the rectangle will be positioned relative to its anchor_y value.

property position: Tuple[float, float]#

Get the position of the text in pixels.

property width: float#

Get/set width of the rectangle.

The new left and right of the rectangle will be set relative to its anchor_x value.