Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js canvas draw polygon

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();
Comment

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();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native remove darkmode 
Javascript :: yeet 
Javascript :: jquery reset select2 
Javascript :: angular viewchild input element value 
Javascript :: dangerouslySetInnerHTML did not match error in React 
Javascript :: check jquery version in chrome 
Javascript :: add quotes to array values javascript 
Javascript :: delete cr eslint 
Javascript :: create react app node 12 
Javascript :: Code to Unsubscribe all youtube channels. 
Javascript :: nodejs open default browser on specific web page 
Javascript :: react after deployment givin nginx 404 
Javascript :: javascript sort array of objects by number 
Javascript :: text to speech using javascript 
Javascript :: how to check if enter is pressed javascript 
Javascript :: js how to convert all string in array into integer 
Javascript :: hide bootstrap modal jquery 
Javascript :: javascript pad number with leading zeros 
Javascript :: js urlencode 
Javascript :: javascript add new array element to start of array 
Javascript :: javascript group by on array of objects 
Javascript :: active link color different in react js 
Javascript :: How to change favicon in nextjs. 
Javascript :: refresh date and time every second angular 
Javascript :: mui usetheme 
Javascript :: js get url parameter 
Javascript :: change style of class divs jquery 
Javascript :: how to make something spawn on a random x axis p5.js 
Javascript :: get rid of header bar react native 
Javascript :: Delete object in array with filter 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =