strokeRectとかfillRectと同じように三角形を使いたいので・・・。
CanvasRenderingContext2D.prototype.strokeTriangle = function(x,y,w,h){
this.beginPath();
this.moveTo(x+(w/2) , y);
this.lineTo(x+w , y+h);
this.lineTo(x , y+h);
this.closePath();
this.stroke();
}
CanvasRenderingContext2D.prototype.fillTriangle = function(x,y,w,h) {
this.strokeTriangle(x,y,w,h);
this.fill();
};
// ctxにはコンテキストをセット。三角形を描画する場合は辺の比率に気をつける。
// 正三角形を描画するのであれば以下の様な感じ
ctx.fillTriangle(30,30,15*2,15*Math.sqrt(3));