Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,887 questions

51,813 answers

573 users

How to draw, fill circle and write text 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 = 'green';
context.fill();
context.font = "20px Arial";
// fillText(text, x, y, maxWidth - Optional);
context.fillText("Circle", 95, 30);

context.fillStyle = 'red';
context.fill();
context.lineWidth = 3;
// context.strokeStyle = color|gradient|pattern;
context.strokeStyle = '#00ff00';
context.font = "20px Arial";
context.fillText("Circle", 95, 170);
context.stroke();
</script>


answered May 21, 2014 by avibootz
edited May 21, 2014 by avibootz

Related questions

1 answer 525 views
1 answer 338 views
338 views asked May 20, 2014 by avibootz
1 answer 295 views
2 answers 367 views
367 views asked May 27, 2016 by avibootz
...