Skip to content

Pygame Renderer

lerax.render.PygameRenderer

Bases: Abstract2DRenderer

PyGame renderer implementation.

Attributes:

Name Type Description
transform Transform

Transform from world coordinates to screen pixels.

width int

The width of the rendering window in pixels.

height int

The height of the rendering window in pixels.

screen Any

The PyGame surface representing the rendering window.

background_color Color

The background color of the rendering window.

Parameters:

Name Type Description Default
width int

The width of the rendering window in pixels.

required
height int

The height of the rendering window in pixels.

required
background_color Color

The background color of the rendering window.

WHITE
transform Transform | None

Transform from world coordinates to screen pixels.

None

transform instance-attribute

transform: Transform

width instance-attribute

width: int = width

height instance-attribute

height: int = height

screen instance-attribute

screen: Any = pg.display.set_mode((self.width, self.height))

background_color instance-attribute

background_color: Color = background_color

__init__

__init__(
    width: int,
    height: int,
    background_color: Color = WHITE,
    transform: Transform | None = None,
) -> None

open

open()

close

close()

draw

draw()

clear

clear()

_pg_color staticmethod

_pg_color(c: Color) -> Any

_to_px

_to_px(point: Float[ArrayLike, '2']) -> tuple[int, int]

_scale_x

_scale_x(length: Float[ArrayLike, '']) -> int

draw_circle

draw_circle(
    center: Float[ArrayLike, "2"],
    radius: Float[ArrayLike, ""],
    color: Color,
)

draw_line

draw_line(
    start: Float[ArrayLike, "2"],
    end: Float[ArrayLike, "2"],
    color: Color,
    width: Float[ArrayLike, ""] = 1,
)

draw_rect

draw_rect(
    center: Float[ArrayLike, "2"],
    w: Float[ArrayLike, ""],
    h: Float[ArrayLike, ""],
    color: Color,
)

draw_polygon

draw_polygon(
    points: Float[ArrayLike, "num 2"], color: Color
)

draw_text

draw_text(
    center: Float[ArrayLike, "2"],
    text: str,
    color: Color,
    size: Float[ArrayLike, ""] = 12,
)

draw_polyline

draw_polyline(
    points: Float[ArrayLike, "num 2"], color: Color
)

draw_ellipse

draw_ellipse(
    center: Float[ArrayLike, "2"],
    w: Float[ArrayLike, ""],
    h: Float[ArrayLike, ""],
    color: Color,
)

as_array

as_array() -> Float[ArrayLike, 'height width 3']