Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Last active July 5, 2018 15:55
Show Gist options
  • Select an option

  • Save LiamChapman/4bea1614317daad1375fd313a25d7807 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/4bea1614317daad1375fd313a25d7807 to your computer and use it in GitHub Desktop.
Canvas Draw Polygon
// ctx and RAD defined globally etc
function drawPolygon(x,y, rot, radius, sides, colour) {
ctx.fillStyle = colour;
ctx.beginPath();
var step = (360 / sizes) + rot;
var tx, ty;
for(var i = 0; i < sides; i++ ) {
tx = radius * Math.cos((step * i) / RAD);
ty = radius * Math.sin((step * i) / RAD);
}
ctx.closePath();
ctx.fill();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment