draw circle in javascript

Here is a basic example of drawing a circle on an HTML5 canvas using JavaScript:

<canvas id="myCanvas"></canvas>
32 chars
2 lines
index.tsx
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const x = canvas.width / 2;
const y = canvas.height / 2;
const radius = 50;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.stroke();
235 chars
9 lines

This code will create a canvas element with an id of "myCanvas" and draw a circle in the center of the canvas with a radius of 50 pixels. The ctx.beginPath() method starts a new path, while ctx.arc(x, y, radius, 0, Math.PI * 2) draws the circle with the specified center (x, y), radius, and angle range. Finally, ctx.stroke() draws the circle's outline.

gistlibby LogSnag