|
retroPy's glitchi
╔══════════════════════════════════════════════════════════════╗
β•‘                     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 pixelCh as a legacy or advanced helper. The implementation includes debug print output and several branching cases, so draw.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 font
  • 1 β†’ 5Γ—5 font
  • 2 β†’ 8Γ—8 font
  • 3 β†’ 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.

  • mul controls block size
  • space adds 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()