ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β draw API Contents β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ π¦ draw ββ π₯ Import ββ π Overview ββ βοΈ Core functions β ββ πΉ draw.clear(color=0) β ββ πΉ draw.pixel(x, y, color=None) β ββ πΉ draw.pixelCh(...) β ββ π Lines and rectangles β ββ πΈ draw.line(...) β ββ πΈ draw.hline(...) β ββ πΈ draw.vline(...) β ββ πΈ draw.rect(...) β ββ πΈ draw.filled_rect(...) β ββ βͺ Circles, ellipses, and arcs β ββ πΈ draw.circle(...) β ββ πΈ draw.filled_circle(...) β ββ πΈ draw.ellipse(...) β ββ πΈ draw.filled_ellipse(...) β ββ πΈ draw.arc(...) β ββ βοΈ Dashed shapes β ββ πΈ draw.line_dashed(...) β ββ πΈ draw.hline_dashed(...) β ββ πΈ draw.vline_dashed(...) β ββ πΈ draw.rect_dashed(...) β ββ πΈ draw.circle_dashed(...) β ββ πΈ draw.ellipse_dashed(...) β ββ πΈ draw.arc_dashed(...) β ββ πΊ Triangles & polylines β ββ πΈ draw.triangle(...) β ββ πΈ draw.filled_triangle(...) β ββ πΈ draw.points(...) β ββ πΈ draw.polyline(...) β ββ π§© Grids and curves β ββ πΈ draw.grid(...) β ββ πΈ draw.grid_dashed(...) β ββ πΈ draw.bezier_quadratic(...) β ββ πΈ draw.bezier_quadratic_dashed(...) β ββ π Vector transforms β ββ πΈ draw.translate(...) β ββ πΈ draw.scale(...) β ββ πΈ draw.rotate(...) β ββ π€ Fonts and text β ββ πΈ draw.set_font(...) β ββ πΈ draw.get_font() β ββ πΈ draw.text(...) β ββ πΈ draw.text_E(...) β ββ π οΈ Low-level helpers β ββ πΈ draw.sprite(...) β ββ πΈ draw.drawSprite(...) β ββ πΈ draw.text_mono(...) β ββ βΆοΈ Typical example
π¦ API Reference: draw
The draw module provides immediate-mode drawing on the active 8-bit framebuffer.
In the current codebase it includes:
- screen clearing and pixel writes
- lines, rectangles, circles, ellipses, arcs, triangles
- dashed shape variants
- text rendering and font selection
- polyline / point helpers
- vector point-list transforms
- low-level sprite and mono-text helpers
π₯ Import
from retroPy import draw
π Overview
Most draw functions render into the current global draw target. By default that target is the main display framebuffer managed by disp.
If a canvas is turned on, the draw target changes to that canvas buffer until canvas.off() is called.
Most high-level drawing functions also apply the current camera transform through the engineβs world_to_screen(...) helper.
βοΈ Core functions
draw.clear(color=0)
Fills the active draw target with a palette index.
draw.clear(0)
draw.clear(8)
draw.pixel(x, y, color=None)
Draws a single pixel.
draw.pixel(10, 10, 15)
If the color is omitted, the module uses the current internal color value.
draw.pixelCh(...)
A more flexible pixel helper that accepts different argument shapes, including vector-like values.
*Status
- Treat
pixelChas a legacy or advanced helper. The implementation includes debug print output and several branching cases, sodraw.pixel(...)is the cleaner public API for normal use.
π Lines and rectangles
draw.line(x1, y1, x2, y2, color=None)
Draws a line.
draw.line(0, 0, 100, 40, 12)
draw.hline(x, y, length, color=None)
Draws a horizontal line.
draw.vline(x, y, length, color=None)
Draws a vertical line.
draw.rect(x, y, w, h, color=None)
Draws an outline rectangle.
draw.rect(20, 20, 40, 20, 15)
draw.filled_rect(x, y, w, h, color=None)
Draws a filled rectangle.
draw.filled_rect(20, 20, 40, 20, 8)
βͺ Circles, ellipses, and arcs
draw.circle(x, y, r, color=None)
Draws an outline circle.
draw.filled_circle(x, y, r, color=None)
Draws a filled circle.
draw.ellipse(x, y, rx, ry, color)
Draws an outline ellipse.
draw.filled_ellipse(x, y, rx, ry, color)
Draws a filled ellipse.
draw.arc(x, y, r, angle_start, angle_end, color)
Draws an arc.
draw.arc(80, 80, 20, 0.0, 1.57, 15)
βοΈ Dashed shapes
The current module also includes dashed variants:
draw.line_dashed(x1, y1, x2, y2, dash, gap, color)draw.hline_dashed(x, y, length, dash, gap, color)draw.vline_dashed(x, y, length, dash, gap, color)draw.rect_dashed(x, y, w, h, dash, gap, color)draw.circle_dashed(x, y, r, dash_deg, gap_deg, color)draw.ellipse_dashed(x, y, rx, ry, dash_deg, gap_deg, color)draw.arc_dashed(x, y, r, angle_start, angle_end, dash, gap, color)
These are useful for editor overlays, guides, construction lines, and UI effects.
πΊTriangles, point lists, and polylines
draw.triangle(p0, p1, p2, color)
Draws an outline triangle from three (x, y) points.
draw.triangle((10, 10), (40, 20), (20, 50), 15)
draw.filled_triangle(p0, p1, p2, color)
Draws a filled triangle from three (x, y) points.
draw.points(point_list, color)
Draws a list of points.
pts = [(10, 10), (12, 14), (16, 20)]
draw.points(pts, 9)
draw.polyline(point_list, color, closed=False)
Draws connected line segments through a list of points.
draw.polyline([(10, 10), (40, 20), (20, 50)], 15)
draw.polyline([(10, 10), (40, 20), (20, 50)], 15, True)
When closed=True, the final point is connected back to the first.
π§© Grids and curves
draw.grid(x, y, w, h, cell_w, cell_h, color)
Draws a rectangular grid.
draw.grid_dashed(x, y, w, h, cell_w, cell_h, dash, gap, color)
Draws a dashed grid.
draw.bezier_quadratic(p0, control, p1, color)
Draws a quadratic BΓ©zier curve using three (x, y) points.
draw.bezier_quadratic_dashed(p0, control, p1, dash_len, gap_len, color)
Draws a dashed quadratic BΓ©zier curve.
π Vector list transforms
These helpers work on lists of (x, y) points and return transformed point data.
draw.translate(points, delta)
Translates a list of points.
draw.scale(points, scale)
Scales a list of points.
draw.rotate(points, angle)
Rotates a list of points.
These are useful for lightweight vector graphics workflows.
π€ Fonts and text
draw.set_font(id)
Selects the current built-in font.
Available font IDs in the current file:
0β 3Γ5 font1β 5Γ5 font2β 8Γ8 font3β larger row-wise font
draw.set_font(2)
draw.get_font()
Returns the current font ID.
draw.text(string, x, y, color)
Draws text using the current font.
draw.text("Hello", 10, 20, 15)
draw.text_E(string, x, y, color, mul, space)
Draws enlarged text.
mulcontrols block sizespaceadds spacing between enlarged pixels
draw.text_E("GO!", 10, 30, 15, 3, 0)
π οΈ Low-level helpers
draw.sprite(index, buffer, x, y, flip=0)
Draws a sprite frame from a raw sprite buffer.
This is a low-level helper that reads header information directly from a supplied buffer.
For normal game code, the higher-level sprite("file.rs8").draw(...) API is usually easier to use.
draw.drawSprite(filename, x, y)
Loads raw line-based data from a file and plots it.
Status
- Treat
draw.drawSprite(...)as specialized or legacy unless you know you need this exact file format.
draw.text_mono(...)
Draws text using a mono sprite font buffer.
Typical example
from retroPy import *
draw.clear(0)
draw.filled_rect(10, 10, 30, 20, 8)
draw.rect(10, 10, 30, 20, 15)
draw.line(0, 0, 80, 40, 12)
draw.circle(60, 60, 12, 14)
draw.text("retroPy", 8, 90, 15)
disp.show()