Skip to content
draw_circle

draw_circle

Mojo function 🡭

draw_circle

fn def draw_circle(mut canvas: Canvas, cx: Int, cy: Int, radius: Int, color: Color)

The midpoint circle algorithm: integer-only, plotting via 8-way symmetry around the center.

At y==0 and x==y several of the 8 symmetric expressions collapse onto one pixel – (cx+y,cy+x) and (cx-y,cy+x) both become (cx,cy+x) when y==0 – so plotting all 8 unconditionally would set_pixel there more than once and multiply-blend a translucent color.

Args:

  • canvas (Canvas): Canvas to draw into.
  • cx (Int): Center x.
  • cy (Int): Center y.
  • radius (Int): Circle radius in pixels.
  • color (Color): Outline color.