Kraken Logo

Kraken Engine

DocumentationGuidesShowcaseCommunity
Ctrl
K
Navigating the Docs
Building Docs
Overview
Camera
Color
Draw
Ease
Event
Fx
Gamepad
Input
Log
Math
Mixer
Mouse
Physics
Pixel Array
Renderer
Shaders
Time
Transform
Ui
Viewport
Window

Built bydurkisneer1.Kraken Engine is open source and available onGitHub.

  1. Docs
  2. Functions
  3. Draw

Draw

Functions for drawing shape objects


Point

point(point: Vec2, color: Color) → Nonepoint(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) → Nonepoints(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: NDArray[float64], color: Color) → Nonepoints_from_ndarray(points: NDArray[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.

Circle

circle(circle: Circle, color: Color, thickness: float = 0, num_segments: int = 24) → Nonecircle(circle: Circle, color: Color, thickness: float = 0, num_segments: int = 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: float = 0, num_segments: int = 24) → Nonecircles(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 : 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.

Capsule

capsule(capsule: Capsule, color: Color, thickness: float = 0, num_segments: int = 24) → Nonecapsule(capsule: Capsule, color: Color, thickness: float = 0, num_segments: int = 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: float = 0, num_segments: int = 24) → Nonecapsules(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 : 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.

Ellipse

ellipse(bounds: Rect, color: Color, thickness: float = 0.0, num_segments: int = 24) → Noneellipse(bounds: Rect, color: Color, thickness: float = 0.0, num_segments: int = 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: float = 0.0, num_segments: int = 24) → Noneellipses(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 : 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.

Line

line(line: Line, color: Color, thickness: float = 1.0) → Noneline(line: Line, color: Color, thickness: float = 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: float = 1.0) → Nonelines(lines: Sequence[Line], color: Color, thickness: float = 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.

Rect

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) → Nonerect(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 : 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: 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) → Nonerects(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 : 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.

Polygon

polygon(polygon: Polygon, color: Color, filled: bool = True) → Nonepolygon(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) → Nonepolygons(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).

Geometry

geometry(texture: Texture | None, vertices: Sequence[Vertex], indices: Sequence[int] = []) → Nonegeometry(texture: Texture | None, vertices: Sequence[Vertex], indices: Sequence[int] = []) → 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.

Bezier

bezier(control_points: Sequence[Vec2], color: Color, thickness: float = 1.0, num_segments: int = 24) → Nonebezier(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 : 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.

Sector

sector(circle: Circle, start_angle: float, end_angle: float, color: Color, thickness: float = 0.0, num_segments: int = 24) → Nonesector(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 : 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.

Polyline

polyline(points: Sequence[Vec2], color: Color, thickness: float = 1.0, closed: bool = False) → Nonepolyline(points: Sequence[Vec2], color: Color, thickness: float = 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.
PreviousColor
NextEase

On this page

PointPointsPoints From NdarrayCircleCirclesCapsuleCapsulesEllipseEllipsesLineLinesRectRectsPolygonPolygonsGeometryBezierSectorPolyline