Skip to main content

HTML5 canvas Polygon Tutorial

To create a polygon with Konva, we can instantiate a Konva.Line() object with the closed property set to true.

For full list of properties and methods, see the Line API Reference.

import Konva from 'konva';

const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});

const layer = new Konva.Layer();
stage.add(layer);

const polygon = new Konva.Line({
points: [73, 192, 73, 160, 340, 23, 500, 109, 499, 139, 342, 93],
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 5,
closed: true
});

layer.add(polygon);