draw_rect
result = draw_rect(img, x, y, width, height, color=, [thickness=1], [filled=false])
Input: img, x, y, width, height, color, thickness, filled · Output: result
What it is
img is an Image; x, y are the top-left corner (pixel coordinates); width, height are positive numbers. filled=true paints the whole interior (thickness is ignored — a fill has no stroke width); filled=false (default) strokes the four edges with the given thickness. At thickness=1 the outline is exactly 2*(width+height-2) pixels for width, height >= 2 — the same formula image.regions's own perimeter column documents for a solid rectangle's boundary walk.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = draw_rect(img, x, y, width, height, color=, [thickness=1], [filled=false]) | img Imageimg is an Image.x —x, y are the top-left corner (pixel coordinates).y —x, y are the top-left corner (pixel coordinates).width numberwidth, height are positive numbers.height numberwidth, height are positive numbers.color —not documented yetthickness optional (default 1)filled=false (default) strokes the four edges with the given thickness.filled optional (default false)filled=true paints the whole interior (thickness is ignored — a fill has no stroke width). | 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
draw_rect(img, x, y, width, height, color=, [thickness=1], [filled=false]) -- axis-aligned rectangle, top-left corner (x, y). filled=true ignores thickness (a fill has no stroke width — see Image::draw_rect's own doc comment).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.