Method: Ruby2D::Canvas#draw_polyline

Defined in:
lib/ruby2d/canvas.rb

#draw_polyline(coordinates:, stroke_width: 1, color: nil, colour: nil, closed: false) ⇒ Object

Draw a poly-line between N points.

Parameters:

  • coordinates (Array)

    An array of numbers x1, y1, x2, y2 … with at least three coordinates (6 values)

  • stroke_width (Numeric) (defaults to: 1)

    The line’s thickness in pixels; defaults to 1.

  • color (Color) (defaults to: nil)

    (or colour) The line colour

  • closed (Boolean) (defaults to: false)

    Use true to draw this as a closed shape



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/ruby2d/canvas.rb', line 239

def draw_polyline(coordinates:, stroke_width: 1, color: nil, colour: nil, closed: false)
  return if coordinates.nil? || coordinates.count < 6

  clr = color || colour
  clr = Color.new(clr) unless clr.is_a? Color
  config = [stroke_width, clr.r, clr.g, clr.b, clr.a]
  if closed
    ext_draw_polygon(config, coordinates)
  else
    ext_draw_polyline(config, coordinates)
  end
  update_texture if @update
end