Skip to main content
Version: 9.0.2

canvas.fillPoly

canvas.fillPoly(xarray, yarray, color)
//OR
canvas.fillPoly(xyarray, color)

Fill the content of a polygon through the points defined in the xyarray with a specific color. The polygon must be a closed simple polygon. Alternatively, two arrays containing a series of points may be provided, as in {x1,x2,..}, {y1,y2,..} similar to sb.polyString.

Parameters

ParameterTypeDescription
xarraynumber[]An array of x values. 
yarraynumber[]An array of y values. 
colornumberThe color to draw the polygon in.

OR

ParameterTypeDescription
xyarray{x: number, y: number}[]An array of objects that each contain an x and y variable.  Used instead of the xarray and yarray.
colornumberThe color to draw the polygon in.

Example

// Fill a triangle using a polygon
function FillRedTrianglePoly(name) {   
var canvas = sb.getCanvas(name);   
var mid = canvas.width / 2;   

//Shrink the bounds to make the lines visible   
var height = canvas.height - 2;   
var width = canvas.width - 2;   
const pts = [];   
pts[0] = {x:2,y:2};   
pts[1] = {x:mid,y :height};   
pts[2] = {x:width,y:2};   
pts[3] = pts[0]; //Close the polygon   
canvas.fillPoly(pts, 0xff0000);
}