var canvas=document.getElementById("canvas");
var cxt= canvas.getContext("2d");
cxt.beginPath();
cxt.moveTo(250,50);
cxt.lineTo(200,200);
cxt.lineTo( 300,300);
cxt.closePath();//Pengisian atau penutupan memerlukan penutupan laluan sebelum melukis
//Segitiga berongga
cxt.strokeStyle="red";
cxt.stroke();
//Segitiga pepejal
cxt.beginPath();
cxt.moveTo(350,50);
cxt.lineTo(300,200);
cxt.lineTo(400,300);
cxt. closePath();
cxt.fill();