Draw

Functions for drawing shape objects


Bezier

bezier(
    control_points: Sequence[Vec2],
    color: Color,
    thickness: SupportsFloat = 1.0,
    num_segments: SupportsInt = 24
) None

Draw a Bezier curve with 3 or 4 control points.

Args

  • control_points : The control points (3 for quadratic, 4 for cubic).
  • color : The color of the curve.
  • thickness : The line thickness. Defaults to 1.0.
  • num_segments : Number of segments to approximate the curve. Defaults to 24.

Capsule

capsule(
    capsule: Capsule,
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 24
) None

Draw a capsule to the renderer.

Args

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

Capsules

capsules(
    capsules: Sequence[Capsule],
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 24
) None

Draw an array of capsules in bulk to the renderer.

Args

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

Circle

circle(
    circle: Circle,
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 24
) 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 24.

Circles

circles(
    circles: Sequence[Circle],
    color: Color,
    thickness: SupportsFloat = 0,
    num_segments: SupportsInt = 24
) 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 24.

Ellipse

ellipse(
    bounds: Rect,
    color: Color,
    thickness: SupportsFloat = 0.0,
    num_segments: SupportsInt = 24
) None

Draw an ellipse to the renderer.

Args

  • bounds : The bounding box of the ellipse.
  • color : The color of the ellipse.
  • thickness : The line thickness. If <= 0 or >= radius, draws filled ellipse. Defaults to 0 (filled).
  • num_segments : Number of segments to approximate the ellipse. Higher values yield smoother ellipses. Defaults to 24.

Ellipses

ellipses(
    bounds: Sequence[Rect],
    color: Color,
    thickness: SupportsFloat = 0.0,
    num_segments: SupportsInt = 24
) None

Draw an array of ellipses in bulk to the renderer.

Args

  • bounds : The bounding boxes of the ellipses to draw in bulk.
  • color : The color of the ellipses.
  • thickness : The line thickness. If <= 0 or >= radius, draws filled ellipses. Defaults to 0 (filled).
  • num_segments : Number of segments to approximate each ellipse. Higher values yield smoother ellipses. Defaults to 24.

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: SupportsFloat = 1.0
) 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.0.

Lines

lines(
    lines: Sequence[Line],
    color: Color,
    thickness: SupportsFloat = 1.0
) None

Batch draw an array of lines to the renderer.

Args

  • lines : The lines to batch draw.
  • color : The color of the lines.
  • thickness : The line thickness in pixels. Defaults to 1.0.

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 True.

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

Polyline

polyline(
    points: Sequence[Vec2],
    color: Color,
    thickness: SupportsFloat = 1.0,
    closed: bool = False
) None

Draw connected line segments through a sequence of points.

Args

  • points : The vertices of the polyline (must have at least 2).
  • color : The color of the polyline.
  • thickness : The line thickness in pixels. Defaults to 1.0.
  • closed : If True, connects the last point back to the first. Defaults to False.

Rect

rect(
    rect: Rect,
    color: Color,
    thickness: SupportsInt = 0,
    border_radius: SupportsFloat = 0.0,
    radius_top_left: SupportsFloat = -1.0,
    radius_top_right: SupportsFloat = -1.0,
    radius_bottom_right: SupportsFloat = -1.0,
    radius_bottom_left: SupportsFloat = -1.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).
  • border_radius : Uniform corner radius for all four corners. Defaults to 0.
  • radius_top_left : Override radius for the top-left corner. -1 to ignore.
  • radius_top_right : Override radius for the top-right corner. -1 to ignore.
  • radius_bottom_right : Override radius for the bottom-right corner. -1 to ignore.
  • radius_bottom_left : Override radius for the bottom-left corner. -1 to ignore.

Rects

rects(
    rects: Sequence[Rect],
    color: Color,
    thickness: SupportsInt = 0,
    border_radius: SupportsFloat = 0.0,
    radius_top_left: SupportsFloat = -1.0,
    radius_top_right: SupportsFloat = -1.0,
    radius_bottom_right: SupportsFloat = -1.0,
    radius_bottom_left: SupportsFloat = -1.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).
  • border_radius : Uniform corner radius for all four corners. Defaults to 0.
  • radius_top_left : Override radius for the top-left corner of all rectangles. -1 to ignore.
  • radius_top_right : Override radius for the top-right corner of all rectangles. -1 to ignore.
  • radius_bottom_right : Override radius for the bottom-right corner of all rectangles. -1 to ignore.
  • radius_bottom_left : Override radius for the bottom-left corner of all rectangles. -1 to ignore.

Sector

sector(
    circle: Circle,
    start_angle: SupportsFloat,
    end_angle: SupportsFloat,
    color: Color,
    thickness: SupportsFloat = 0.0,
    num_segments: SupportsInt = 24
) None

Draw a circular sector or arc.

Args

  • circle : The circle defining the sector.
  • start_angle : The start angle in radians.
  • end_angle : The end angle in radians.
  • color : The color of the sector.
  • thickness : The line thickness. If <= 0 or >= radius, draws filled sector. Defaults to 0 (filled).
  • num_segments : Number of segments to approximate the arc. Defaults to 24.