“Desenhe Canvas HTML Polygon” Respostas de código

Canvas JS desenham polígono

var ctx = canvas.getContext('2d');
ctx.fillStyle = '#f00';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(100,50);
ctx.lineTo(50, 100);
ctx.lineTo(0, 90);
ctx.closePath();
ctx.fill();
inibir

Desenhe Canvas HTML Polygon

// accepts a vector array
// vector is simpy typeof {x: number, y: number}
function drawPolygon(points: Vector[]) {
  this.context.beginPath();

  this.context.moveTo(points[0].x, points[0].y);
  for (let i = 1; i < points.length; i++) {
    this.context.lineTo(points[i].x, points[i].y);
  }

  this.context.closePath();
  this.context.fill();
  this.context.stroke();
}
Himanshu Jangid

Respostas semelhantes a “Desenhe Canvas HTML Polygon”

Perguntas semelhantes a “Desenhe Canvas HTML Polygon”

Procure respostas de código populares por idioma

Procurar outros idiomas de código