Skip to main content
Version: 9.0.2

canvas.strokePoly

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

Stroke a polygon through the points defined in xytable with a specific color. The width of the line is the last value passed to canvas.setLineWidth or 1 if no width has ever been specified.

Parameters

ParameterTypeDescription
xarraynumber[]An array of x values.
yarraynumber[]An array of y values.
colornumberAn RGB color value as an integer value.

OR

ParameterTypeDescription
xyarray{x: number, y: number}[]An array of objects that each contain an x and y variable such as [{x:x1,y:y1},{x:x2,y:y2}...].  Used instead of the xarray and yarray.
colornumberAn RGB color value as an integer value.

Example

// Stroke a triangle using a polygon
function StrokeRedTrianglePoly(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.strokePoly(pts, 0xff0000)
}