How in JavaScript draw a circle with radius 10 pixels in a html canvas?
- User
How in JavaScript draw a circle with radius 10 pixels in a html canvas?
- Assistant
To draw a circle with a radius of 10 pixels in a HTML canvas using JavaScript, you can use the following code:
context.beginPath(); context.arc(100, 100, 10, 0, 2 * Math.PI); context.fillStyle = "blue"; context.fill(); context.stroke(); } </script>In this example, getElementById is used to obtain a reference to the canvas element in the HTML document, and getContext is used to obtain a 2D rendering context for the canvas. beginPath is called to start a new path, arc is used to create an arc with a given center, radius, start angle, and end angle, and fill and stroke are used to fill and outline the circle, respectively.
You can adjust the position of the circle by changing the values passed to the arc method, and you can change the color of the fill by changing the value assigned to fillStyle.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.