MODULE v1.8.0

draw

pykraken.draw

Functions for drawing shape objects

Reference

PYTHON API

bezier

function
bezier(control_points: Sequence[Vec2], color: Color, thickness: float = 1.0, num_segments: int = 24) -> None

Draw a Bezier curve with 3 or 4 control points.

Args

  • control_points (Sequence[Vec2]) — The control points (3 for quadratic, 4 for cubic).
  • color (Color) — The color of the curve.
  • thickness (float, optional) — The line thickness. Defaults to 1.0.
  • num_segments (int, optional) — Number of segments to approximate the curve. Defaults to 24.

capsule

function
capsule(capsule: Capsule, color: Color, thickness: float = 0, num_segments: int = 24) -> None

Draw a capsule to the renderer.

Args

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

capsules

function
capsules(capsules: Sequence[Capsule], color: Color, thickness: float = 0, num_segments: int = 24) -> None

Draw an array of capsules in bulk to the renderer.

Args

  • capsules (Sequence[Capsule]) — The capsules to draw in bulk.
  • color (Color) — The color of the capsules.
  • thickness (float, optional) — The line thickness. If <= 0 or >= radius, draws filled capsules. Defaults to 0 (filled).
  • num_segments (int, optional) — Number of segments to approximate each capsule end. Higher values yield smoother capsules. Defaults to 24.

circle

function
circle(circle: Circle, color: Color, thickness: float = 0, num_segments: int = 24) -> None

Draw a circle to the renderer.

Args

  • circle (Circle) — The circle to draw.
  • color (Color) — The color of the circle.
  • thickness (float, optional) — The line thickness. If <= 0 or >= radius, draws filled circle. Defaults to 0 (filled).
  • num_segments (int, optional) — Number of segments to approximate the circle. Higher values yield smoother circles. Defaults to 24.

circles

function
circles(circles: Sequence[Circle], color: Color, thickness: float = 0, num_segments: int = 24) -> None

Draw an array of circles in bulk to the renderer.

Args

  • circles (Sequence[Circle]) — The circles to draw in bulk.
  • color (Color) — The color of the circles.
  • thickness (float, optional) — The line thickness. If <= 0 or >= radius, draws filled circle. Defaults to 0 (filled).
  • num_segments (int, optional) — Number of segments to approximate each circle. Higher values yield smoother circles. Defaults to 24.

ellipse

function
ellipse(bounds: Rect, color: Color, thickness: float = 0.0, num_segments: int = 24) -> None

Draw an ellipse to the renderer.

Args

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

ellipses

function
ellipses(bounds: Sequence[Rect], color: Color, thickness: float = 0.0, num_segments: int = 24) -> None

Draw an array of ellipses in bulk to the renderer.

Args

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

geometry

function
geometry(texture: Texture | None, vertices: Sequence[Vertex], indices: Sequence[int] = []) -> None

Draw arbitrary geometry using vertices and optional indices.

Args

  • texture (Texture | None) — The texture to apply to the geometry. Can be None.
  • vertices (Sequence[Vertex]) — A list of Vertex objects.
  • indices (Sequence[int] | None) — A list of indices defining the primitives. If None or empty, vertices are drawn sequentially.

line

function
line(line: Line, color: Color, thickness: float = 1.0) -> None

Draw a line to the renderer.

Args

  • line (Line) — The line to draw.
  • color (Color) — The color of the line.
  • thickness (float, optional) — The line thickness in pixels. Defaults to 1.0.

lines

function
lines(lines: Sequence[Line], color: Color, thickness: float = 1.0) -> None

Batch draw an array of lines to the renderer.

Args

  • lines (Sequence[Line]) — The lines to batch draw.
  • color (Color) — The color of the lines.
  • thickness (float, optional) — The line thickness in pixels. Defaults to 1.0.

point

function
point(point: Vec2, color: Color) -> None

Draw a single point to the renderer.

Args

  • point (Vec2) — The position of the point.
  • color (Color) — The color of the point.

Raises

  • RuntimeError — If point rendering fails.

points

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

Batch draw an array of points to the renderer.

Args

  • points (Sequence[Vec2]) — The points to batch draw.
  • color (Color) — The color of the points.

Raises

  • RuntimeError — If point rendering fails.
points_from_ndarray(points: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu', writable=False], 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 (ndarray) — Array with shape (N,2) containing x,y coordinates.
  • color (Color) — The color of the points.

Raises

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

polygon

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

Draw a polygon to the renderer.

Args

  • polygon (Polygon) — The polygon to draw.
  • color (Color) — The color of the polygon.
  • filled (bool, optional) — Whether to draw a filled polygon or just the outline. Defaults to True.

polygons

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

Draw an array of polygons in bulk to the renderer.

Args

  • polygons (Sequence[Polygon]) — The polygons to draw in bulk.
  • color (Color) — The color of the polygons.
  • filled (bool, optional) — Whether to draw filled polygons or just the outlines. Defaults to True (filled).

polyline

function
polyline(points: Sequence[Vec2], color: Color, thickness: float = 1.0, closed: bool = False) -> None

Draw connected line segments through a sequence of points.

Args

  • points (Sequence[Vec2]) — The vertices of the polyline (must have at least 2).
  • color (Color) — The color of the polyline.
  • thickness (float, optional) — The line thickness in pixels. Defaults to 1.0.
  • closed (bool, optional) — If True, connects the last point back to the first. Defaults to False.

rect

function
rect(rect: Rect, color: Color, thickness: int = 0, border_radius: float = 0.0, radius_top_left: float = -1.0, radius_top_right: float = -1.0, radius_bottom_right: float = -1.0, radius_bottom_left: float = -1.0) -> None

Draw a rectangle to the renderer.

Args

  • rect (Rect) — The rectangle to draw.
  • color (Color) — The color of the rectangle.
  • thickness (int, optional) — The border thickness. If 0 or >= half width/height, draws filled rectangle. Defaults to 0 (filled).
  • border_radius (float, optional) — Uniform corner radius for all four corners. Defaults to 0.
  • radius_top_left (float, optional) — Override radius for the top-left corner. -1 to ignore.
  • radius_top_right (float, optional) — Override radius for the top-right corner. -1 to ignore.
  • radius_bottom_right (float, optional) — Override radius for the bottom-right corner. -1 to ignore.
  • radius_bottom_left (float, optional) — Override radius for the bottom-left corner. -1 to ignore.

rects

function
rects(rects: Sequence[Rect], color: Color, thickness: int = 0, border_radius: float = 0.0, radius_top_left: float = -1.0, radius_top_right: float = -1.0, radius_bottom_right: float = -1.0, radius_bottom_left: float = -1.0) -> None

Batch draw an array of rectangles to the renderer.

Args

  • rects (Sequence[Rect]) — The rectangles to batch draw.
  • color (Color) — The color of the rectangles.
  • thickness (int, optional) — The border thickness of the rectangles. If 0 or >= half width/height, draws filled rectangles. Defaults to 0 (filled).
  • border_radius (float, optional) — Uniform corner radius for all four corners. Defaults to 0.
  • radius_top_left (float, optional) — Override radius for the top-left corner of all rectangles. -1 to ignore.
  • radius_top_right (float, optional) — Override radius for the top-right corner of all rectangles. -1 to ignore.
  • radius_bottom_right (float, optional) — Override radius for the bottom-right corner of all rectangles. -1 to ignore.
  • radius_bottom_left (float, optional) — Override radius for the bottom-left corner of all rectangles. -1 to ignore.

sector

function
sector(circle: Circle, start_angle: float, end_angle: float, color: Color, thickness: float = 0.0, num_segments: int = 24) -> None

Draw a circular sector or arc.

Args

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

Find your next step

Start typing to search the manual.