Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

draw polygon html canvas

// 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();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #draw #polygon #html #canvas
ADD COMMENT
Topic
Name
8+7 =