Last active
July 5, 2018 15:55
-
-
Save LiamChapman/4bea1614317daad1375fd313a25d7807 to your computer and use it in GitHub Desktop.
Canvas Draw Polygon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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