draw
pykraken.draw Functions for drawing shape objects
At a glance
19 membersReference
PYTHON APIbezier
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionBatch 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
functionDraw 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
functionBatch 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
functionpoints_from_ndarray(points: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu', writable=False], color: Color) -> NoneBatch 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
functionDraw 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
functionDraw 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
functionDraw 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
functionDraw 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
functionBatch 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
functionDraw 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.