Qu

draw_circle

Builtin index · Images

result = draw_circle(img, cx, cy, radius, color=, [thickness=1], [filled=false])

Input: img, cx, cy, radius, color, thickness, filled · Output: result

What it is

img is an Image; cx, cy are the center (pixel coordinates); radius is a positive number. filled=true fills the digital disk (every pixel with dx^2+dy^2 <= radius^2); filled=false (default) strokes the boundary using the textbook midpoint (Bresenham) circle algorithm at the given thickness.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = draw_circle(img, cx, cy, radius, color=, [thickness=1], [filled=false])
img Imageimg is an Image.
cx —cx, cy are the center (pixel coordinates).
cy —cx, cy are the center (pixel coordinates).
radius numberradius is a positive number.
color —not documented yet
thickness optional (default 1)filled=false (default) strokes the boundary using the textbook midpoint (Bresenham) circle algorithm at the given thickness.
filled optional (default false)filled=true fills the digital disk (every pixel with dx^2+dy^2 <= radius^2).
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_circle(img, cx, cy, radius, color=, [thickness=1], [filled=false]) -- filled=true fills the digital disk dx^2+dy^2 <= radius^2; filled=false strokes the midpoint (Bresenham) circle boundary. See Image::draw_circle's own doc comment for why those are two different algorithms.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.