Draw

Functions for drawing shape objects


Circle

circle(
    circle: Circle,
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 36
) None

Draw a circle to the renderer.

Args

  • circle : The circle to draw.
  • color : The color of the circle.
  • thickness : The line thickness. If <= 0 or >= radius, draws filled circle. Defaults to 0 (filled).
  • num_segments : Number of segments to approximate the circle. Higher values yield smoother circles. Defaults to 36.

Circles

circles(
    circles: Sequence[Circle],
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 36
) None

Draw an array of circles in bulk to the renderer.

Args

  • circles : The circles to draw in bulk.
  • color : The color of the circles.
  • thickness : The line thickness. If <= 0 or >= radius, draws filled circle. Defaults to 0 (filled).
  • num_segments : Number of segments to approximate each circle. Higher values yield smoother circles. Defaults to 36.

Ellipse

ellipse(
    bounds: Rect,
    color: Color,
    filled: bool = False
) None

Draw an ellipse to the renderer.

Args

  • bounds : The bounding box of the ellipse.
  • color : The color of the ellipse.
  • filled : Whether to draw a filled ellipse or just the outline. Defaults to False (outline).

Geometry

geometry(
    texture: Texture | None,
    vertices: Sequence[Vertex],
    indices: Any = None
) None

Draw arbitrary geometry using vertices and optional indices.

Args

  • texture : The texture to apply to the geometry. Can be None.
  • vertices : A list of Vertex objects.
  • indices : A list of indices defining the primitives. If None or empty, vertices are drawn sequentially.

Line

line(
    line: Line,
    color: Color,
    thickness: SupportsInt = 1
) None

Draw a line to the renderer.

Args

  • line : The line to draw.
  • color : The color of the line.
  • thickness : The line thickness in pixels. Defaults to 1.

Point

point(point: Vec2, color: Color) None

Draw a single point to the renderer.

Args

  • point : The position of the point.
  • color : The color of the point.

Raises

  • RuntimeError : If point rendering fails.

Points

points(points: Sequence[Vec2], color: Color) None

Batch draw an array of points to the renderer.

Args

  • points : The points to batch draw.
  • color : The color of the points.

Raises

  • RuntimeError : If point rendering fails.

Points From Ndarray

points_from_ndarray(
    points: Annotated[numpy.ArrayLike, numpy.float64],
    color: Color
) None

Batch draw points from a NumPy array.

This fast path accepts a contiguous NumPy array of shape (N,2) (dtype float64) and reads coordinates directly with minimal overhead. Use this to measure the best-case zero-copy/buffer-backed path.

Args

  • points : Array with shape (N,2) containing x,y coordinates.
  • color : The color of the points.

Raises

  • ValueError : If the array shape is not (N,2).
  • RuntimeError : If point rendering fails.

Polygon

polygon(
    polygon: Polygon,
    color: Color,
    filled: bool = True
) None

Draw a polygon to the renderer.

Args

  • polygon : The polygon to draw.
  • color : The color of the polygon.
  • filled : Whether to draw a filled polygon or just the outline. Defaults to False (outline). Works with both convex and concave polygons.

Polygons

polygons(
    polygons: Sequence[Polygon],
    color: Color,
    filled: bool = True
) None

Draw an array of polygons in bulk to the renderer.

Args

  • polygons : The polygons to draw in bulk.
  • color : The color of the polygons.
  • filled : Whether to draw filled polygons or just the outlines. Defaults to True (filled). Works with both convex and concave polygons.

Rect

rect(
    rect: Rect,
    color: Color,
    thickness: SupportsInt = 0
) None

Draw a rectangle to the renderer.

Args

  • rect : The rectangle to draw.
  • color : The color of the rectangle.
  • thickness : The border thickness. If 0 or >= half width/height, draws filled rectangle. Defaults to 0 (filled).

Rects

rects(
    rects: Sequence[Rect],
    color: Color,
    thickness: SupportsInt = 0
) None

Batch draw an array of rectangles to the renderer.

Args

  • rects : The rectangles to batch draw.
  • color : The color of the rectangles.
  • thickness : The border thickness of the rectangles. If 0 or >= half width/height, draws filled rectangles. Defaults to 0 (filled).