How to draw and fill circle in HTML5 and JavaScript

1 Answer

0 votes
<canvas id="myCanvas" width="200" height="200" style="border: #000000;">
</canvas>

<script>
var canvas = document.getElementById("myCanvas");
// canvas.getContext("2d") returns an object with methods and properties for drawing on the 
// canvas: circles, text, boxes, lines, and more.
var context = canvas.getContext("2d");

context.beginPath();
// context.arc(x, y, r, sAngle - Start, eAngle - End, counterclockwise - Optional);
context.arc(120, 90, 50, 0, 2 * Math.PI);

// context.fillStyle= color|gradient|pattern;
context.fillStyle = 'red';
context.fill();
context.lineWidth = 3;
// context.strokeStyle = color|gradient|pattern;
context.strokeStyle = '#00ff00';
context.stroke();
</script>


answered May 21, 2014 by avibootz

Related questions

1 answer 374 views
374 views asked May 20, 2014 by avibootz
1 answer 313 views
2 answers 402 views
402 views asked May 27, 2016 by avibootz
...