canvas.fillPoly(xarray, yarray, color)


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.

    xarray - An array of x values 
    yarray - An array of y values   
    xyarray - An array of objects that each contain an x and y variable.  Used instead of the xarray and yarray 
    color - The color to draw the polygon in


// 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);
Was this article helpful?
0 out of 0 found this helpful