CANVAS:fill poly

CANVAS:fill_poly(xytable, color)

Fill the content of a polygon through the points defined in the xytable with a specific color. The polygon must be a closed simple polygon.

Parameters:

xytable

A Lua table {{x=x1,y=y1},{x=x2,y=y2}...}.

Alternatively two tables of parameters containing an array of points may be provided, as in {x1,x2,..}, {y1,y2,..} similar to gre.poly_string.

color

An RGB color value as an integer value.

Example:

-- Fill a triangle using a polygon
function FillRedTrianglePoly(name)
    local canvas = gre.get_canvas(name)
    local size = canvas:get_dimensions()
    local mid = size.width / 2

    -- Shrink the bounds to make the lines visible
    size.height = size.height - 2
    size.width = size.width - 2

    local pts = {}
    table.insert(pts, {x=2,y=2})
    table.insert(pts, {x=mid,y=size.height})
    table.insert(pts, {x=size.width,y=2})
    table.insert(pts, pts[1])               --Close the polygon
    canvas:fill_poly(pts, 0xff0000)
end
Was this article helpful?
0 out of 0 found this helpful