How to draw a circle in HTML5 Canvas using JavaScript

0 votes
How to draw a simple circle in HTML5 Canvas using minimum JavaScript code?
Nov 14, 2022 in Java by Nicholas
• 7,760 points
962 views

1 answer to this question.

0 votes

Here's how to draw a circle in HTML5 using JavaScript:

const canvas = document.getElementById('myCanvas');
const context = canvas.getContext('2d');
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const radius = 70;

context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'green';
context.fill();
context.lineWidth = 5;
context.strokeStyle = '#003300';
context.stroke();
body {
  margin: 0;
  padding: 0;
}
<canvas id="myCanvas" width="578" height="200"></canvas>
answered Nov 15, 2022 by Damonlang
• 1,230 points

Related Questions In Java

0 votes
0 answers

How to decode jwt token in javascript without using a library?

How can I decode the payload of ...READ MORE

Apr 21, 2022 in Java by Rahul
• 3,380 points
1,573 views
0 votes
1 answer

How to decode jwt token in javascript without using a library?

Working unicode text JWT parser function: function parseJwt ...READ MORE

answered Nov 4, 2022 in Java by Damonlang
• 700 points
7,367 views
0 votes
1 answer

How to call a method after a delay in Android using Java?

final Handler handler = new Handler(); handler.postDelayed(new Runnable() ...READ MORE

answered Jun 11, 2018 in Java by Akrati
• 3,190 points
5,351 views
0 votes
1 answer

How to store an array in localstorage?

Localstorage only supports Strings. So you can ...READ MORE

answered Jul 1, 2019 in Others by sunshine
• 1,300 points
23,057 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,520 points
948 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 1,174 views
0 votes
1 answer

Calculate string value in javascript, not using eval

You could use the Function() constructor: function evil(fn) ...READ MORE

answered Nov 15, 2022 in Java by Damonlang
• 1,230 points
2,718 views
0 votes
1 answer

Check if a variable is a string in JavaScript

This is what I've found to be ...READ MORE

answered Nov 15, 2022 in Java by Damonlang
• 1,230 points
463 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP