Method: Ruby2D::Canvas#fill_polygon

Defined in:
lib/ruby2d/canvas.rb

#fill_polygon(coordinates:, color: nil, colour: nil) ⇒ Object

Note:

Currently only supports convex polygons or simple polygons with one concave corner.

Note:

Supports per-vertex coloring, but the triangulation may change and affect the coloring.

Fill a polygon made up of N points.

Parameters:

  • coordinates (Array)

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

  • color (Color, Color::Set) (defaults to: nil)

    (or colour) Set one or per-vertex colour; at least one colour must be specified.



258
259
260
261
262
263
264
# File 'lib/ruby2d/canvas.rb', line 258

def fill_polygon(coordinates:, color: nil, colour: nil)
  return if coordinates.nil? || coordinates.count < 6 || (color.nil? && colour.nil?)

  colors = colors_to_a(color || colour)
  ext_fill_polygon(coordinates, colors)
  update_texture if @update
end