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 in Java by Nicholas
• 7,120 points
57 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 by Damonlang
• 300 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 in Java by Rahul
• 3,380 points
917 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 in Java by Damonlang
• 700 points
146 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
4,672 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,280 points
20,264 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,510 points
472 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,800 points

edited Jan 21, 2020 by Niroj 466 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 in Java by Damonlang
• 300 points
73 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 in Java by Damonlang
• 300 points
38 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