Skip to content
draw_ellipse

draw_ellipse

Mojo function 🡭

draw_ellipse

fn def draw_ellipse(mut canvas: Canvas, cx: Int, cy: Int, rx: Int, ry: Int, color: Color)

The midpoint ellipse algorithm – draw_circle’s generalization to independent x/y radii.

Two regions, split where the boundary’s slope magnitude crosses 1 (region 1 shallow, stepping x; region 2 steep, stepping y), each with its own decision parameter, since unequal radii leave no single symmetric stepping rule for the whole curve. 4-way symmetry, not the circle’s 8-way: swapping x and y preserves the ellipse equation only when rx == ry.

Integer-only. The decision parameters are scaled by 4 throughout to absorb the 0.25 term from evaluating the ellipse equation at a half-pixel-offset midpoint.

Args:

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