draw_line
result = draw_line(img, x0, y0, x1, y1, color=, [thickness=1])
Input: img, x0, y0, x1, y1, color, thickness · Output: result
What it is
img is an Image; x0, y0, x1, y1 are numbers (pixel coordinates, rounded to the nearest integer). color= is required, in the same colour spelling every other color= keyword in this codebase accepts (a CSS name, #rrggbb/#rgb hex, or rgb(...)/rgba(...)). thickness= is an optional named positive integer (default 1), a square brush stamped at every point of a Bresenham line from (x0,y0) to (x1,y1) inclusive.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = draw_line(img, x0, y0, x1, y1, color=, [thickness=1]) | img Imageimg is an Image.x0 numberx0, y0, x1, y1 are numbers (pixel coordinates, rounded to the nearest integer).y0 numberx0, y0, x1, y1 are numbers (pixel coordinates, rounded to the nearest integer).x1 numberx0, y0, x1, y1 are numbers (pixel coordinates, rounded to the nearest integer).y1 numberx0, y0, x1, y1 are numbers (pixel coordinates, rounded to the nearest integer).color —color= is required, in the same colour spelling every other color= keyword in this codebase accepts (a CSS name, #rrggbb/#rgb hex, or rgb(...)/rgba(...)).thickness optional (default 1)thickness= is an optional named positive integer (default 1), a square brush stamped at every point of a Bresenham line from (x0,y0) to (x1,y1) inclusive. | result Image | Returns a new Image, same dimensions as img. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
img = image_new(300, 200, r=20, g=20, b=20)
img = draw_line(img, 10, 10, 290, 10, color="yellow", thickness=2)
img = draw_rect(img, 20, 30, 60, 40, color="cyan", thickness=2)
img = draw_circle(img, 150, 100, 30, color="magenta", filled=true)
img = draw_arrow(img, 200, 150, 260, 180, color="white", head_size=12)
# A 100 px bar labeled "50 um" when pixel_size = 0.5 um/px.
img = draw_scale_bar(img, 50, pixel_size=0.5, unit="um", position="bottom-right", color="white")
save_image("/tmp/annotated.bmp", img)
from images
How it works
spec docs/design/toolkit-image.md §6 "Drawing/annotation", 2026-09-25) -- draws straight onto a pixel buffer and returns a NEW Image (same convention every other transform in this group already follows), distinct from the plotting system's own annotate/text/arrow builtins, which label a FIGURE (an SVG/PDF vector canvas with a data coordinate system), not a raw Image. Coordinates are plain pixel integers, top-left origin. See image::Image::draw_line/draw_rect/ draw_circle/draw_arrow/draw_text's own doc comments for the exact rasterization algorithm each uses.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.