Last active
November 16, 2020 23:54
-
-
Save codingedgar/c8bd2cc6974b9e5810ff01f952d0ce8e to your computer and use it in GitHub Desktop.
Draw different shapes to demonstrate arc
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
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <canvas id="myCanvas" width="150" height="200" style="border:1px solid #d3d3d3;"> | |
| Your browser does not support the HTML canvas tag. | |
| </canvas> | |
| <script> | |
| const canvas = document.querySelector('canvas'); | |
| const ctx = canvas.getContext('2d'); | |
| // Draw shapes | |
| for (let i = 0; i <= 3; i++) { | |
| for (let j = 0; j <= 2; j++) { | |
| ctx.beginPath(); | |
| let x = 25 + j * 50; // x coordinate | |
| let y = 25 + i * 50; // y coordinate | |
| let radius = 20; // Arc radius | |
| let startAngle = 0; // Starting point on circle | |
| let endAngle = Math.PI + (Math.PI * j) / 2; // End point on circle | |
| let anticlockwise = i % 2 == 1; // Draw anticlockwise | |
| ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise); | |
| if (i > 1) { | |
| ctx.fill(); | |
| } else { | |
| ctx.stroke(); | |
| } | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment