I'm learning NASM and already have a _Make_Pixel routine that can draw individual pixels. I want to write a reasonably short algorithm for drawing a filled circle with a specified center and radius. Ideally it should use only a few data labels, stay under roughly 300 lines, and rely on straightforward high-school-level math. Please explain the approach in programming terms rather than giving only equations. I've tried several perimeter and distance-based algorithms, but they either didn't work or only drew an outline.
3 Answers
Bresenham normally gives you the circumference, which is why it does not automatically produce a filled circle. To adapt it, use its calculated boundary points to draw horizontal lines between the matching left and right points on each row. Alternatively, scan each row directly with the squared-distance test; it is easier to debug and is probably the best starting point for learning assembly.
You can calculate the horizontal extent with x = sqrt(radius*radius - y*y), then fill the pixels between the two endpoints. If your processor or code does not have convenient multiplication or square-root support, use a small lookup table for x values based on each y offset. That keeps the drawing loop short and avoids expensive calculations.
The simplest approach is to scan the square surrounding the circle. For every pixel position, calculate its horizontal and vertical distance from the center. If dx*dx + dy*dy is less than or equal to radius*radius, draw that pixel. You only need to scan from centerX - radius through centerX + radius, and the same range vertically. Squared distances avoid using a square-root instruction.

That makes sense. I was trying something similar, but I probably had the distance comparison or coordinate offsets wrong.