{"id":12838,"date":"2023-01-02T14:04:19","date_gmt":"2023-01-02T19:04:19","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=12838"},"modified":"2023-01-02T14:04:22","modified_gmt":"2023-01-02T19:04:22","slug":"draw-circle-in-javascript-example","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/draw-circle-in-javascript-example\/","title":{"rendered":"How to Draw Circle in JavaScript Example Code"},"content":{"rendered":"\n
Use this to draw a circle in JavaScript:<\/p>\n\n\n\n
The HTML Code:<\/p>\n\n\n\n
<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8 \/>\n <title>Draw a circle<\/title>\n <\/head>\n <body onload="draw();">\n <canvas id="circle" width="150" height="150"><\/canvas>\n <\/body>\n<\/html><\/code><\/pre>\n\n\n\nThe JavaScript Code:<\/p>\n\n\n\n
function draw()\n{\n var canvas = document.getElementById('circle');\n if (canvas.getContext)\n {\n var ctx = canvas.getContext('2d'); \n var X = canvas.width \/ 2;\n var Y = canvas.height \/ 2;\n var R = 45;\n ctx.beginPath();\n ctx.arc(X, Y, R, 0, 2 * Math.PI, false);\n ctx.lineWidth = 3;\n ctx.strokeStyle = '#FF0000';\n ctx.stroke();\n }\n}<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[953,23,25,27,15,16,18],"tags":[31,328,424,433,449,544],"yoast_head":"\nHow to Draw Circle in JavaScript Example Code [Snippet]<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n