EN
JavaScript - draw circle on canvas element
4 points
Simple solution:
xxxxxxxxxx
1
context.beginPath();
2
context.arc(x, y, radius, 0, 2 * Math.PI);
3
context.stroke();
Using JavaScript it is possible to draw circle in following way.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
#my-canvas { border: 1px solid gray; }
7
8
</style>
9
</head>
10
<body>
11
<canvas id="my-canvas" width="200" height="200"></canvas>
12
<script>
13
14
var canvas = document.querySelector('#my-canvas');
15
var context = canvas.getContext('2d');
16
17
function drawCircle(x, y, radius) {
18
context.beginPath();
19
context.arc(x, y, radius, 0, 2 * Math.PI);
20
context.stroke();
21
}
22
23
drawCircle(100, 100, 80);
24
25
</script>
26
</body>
27
</html>