For filled circles, you can use the Pythagoras Theorem. However, this algorithm draws a few extra pixels, but it shows one of the ways you can draw them.
for y = -radius, radius do
for x = -radius, radius do
if x * x + y * y <= radius * radius then
--# draw pixel at x + originX, y + originY
end
end
end
Another method,
and this is the method I would recommend you use for both non-filled and filled, is
Bresenham's Midpoint Circle Algorithm. This is the most accurate way to draw a circle, and it is fairly fast. I'd suggest reading up on how it works. Wikipedia shows you an implementation for outlined circles in C and JavaScript, which should be easy to port to Lua.
In order to draw filled circles, you can change the algorithm slightly, so instead of:
plot(x0 + x, y0 + y)
plot(x0 - x, y0 + y)
and similar lines, you instead do:
paintutils.drawLine(x0 - x, y0 + y, x0 + x, y0 + y)
Generally, I would also suggest allowing the user to pass in their own term objects to draw the circles with, instead of having to redirect to the term object just to use paintutils. This means you need to implement line drawing. Luckily,
Bresenham also came up with a line drawing algorithm. Allowing users to pass in their own term object would let them use your API in a buffer such as a framebuffer, or BLittle's drawing buffer.
Edited by Lemmmy, 04 July 2016 - 10:52 PM.