Skip to content
draw_line

draw_line

Mojo function 🡭

draw_line

fn def draw_line(mut canvas: Canvas, x0: Int, y0: Int, x1: Int, y1: Int, color: Color, dashes: List[Float64] = List(), dash_offset: Float64 = 0)

Bresenham’s line algorithm – integer-only, works for any slope or direction.

dashes is an optional alternating on/off length pattern (see _is_dash_on); empty by default, drawing solid. Measured in the accumulated-raster-step distance _draw_line_core describes, not an idealized straight-line one.

Args:

  • canvas (Canvas): Canvas to draw into.
  • x0 (Int): Start point x.
  • y0 (Int): Start point y.
  • x1 (Int): End point x.
  • y1 (Int): End point y.
  • color (Color): Line color.
  • dashes (List[Float64]): On/off segment lengths in pixels, cycled along the line. Empty (default) draws a solid line.
  • dash_offset (Float64): Distance into the dash pattern the line starts at.