How to Draw a Circle in JavaScript?18 Apr 2025 | 4 min read The drawing of the circle is an important functionality of the JavaScript language. JavaScript is a web application programming language to operate functions. The javascript function is used to add required functionalities on the web pages. We created the empty and filled circle on a web page using single and multiple colours. Programmers are working with JavaScript to require a "canvas", like an artist is required to create art. A javascript canvas is showing a rectangular shape on an HTML page. We can add colours, create shapes (circles), and digital artwork using javascript Canvas and other methods. Setting the Canvas1. We are setting the javascript canvas. It is necessary before starting the draw circle on the web page using JavaScript. We can set the canvas with the 2d animation as shown below. 2. We have obtained a reference to the canvas using the getElementById function. Imagine this is locating your canvas using a unique identifier among a stack of canvases. 3. The javascript function is showing a 2D drawing using the "getContext('2d') " on the web page. 4. Imaging, we are preparing our brush for painting on the canvas. Use the '2d' symbol in the script tag for a two-dimensional context. Drawing a JavaScript CircleWe are using the arc() method for drawing circles using a unique tool in our toolbox. The arc requires six parameters () method: The circle's coordinates are as follows: - x for the circle's x-coordinate; - y for the circle's y-coordinate; - radius for the circle; - startAngle for the circle's radian starting point; - endAngle for the circle's radian ending point; - anticlockwise for a Boolean value that controls the circle's movement. This describes how to draw a circle:
ExamplesThe following examples show the circle with the javascript function. Example 1: The following example shows the basic circle drawn using the javascript function and style tags. Output The output shows the required circle using javascript. ![]() Example 2: The following example shows the draw-filled circle using the javascript function and style tags. Output The output shows the required circle using javascript. ![]() Example 3: The following example shows the draw-filled and multicolour circle using the JavaScript function and style tags. Output The output shows the required circle using javascript. ![]() ConclusionJavaScript resembles a toolset for digital artists. It provides a range of tools and techniques, such as arc(), for working with and creating visuals. At the same time, drawing a circle might seem like a modest step, but it represents a significant advancement in knowledge about how JavaScript can be used to interact with the HTML canvas. Next TopicJavaScript Bin |
What is ? In JavaScript, Jasmine is a very popular tool that is used by developers to deal with complex testing processes. With the use of jasmine.js, developers can test any kind of JavaScript application. In JavaScript, Jasmine follows a procedure that is known as Behavior Driven Development...
7 min read
What is Axios in JavaScript? In JavaScript, Axios is a library that is used to make HTTP requests from both the browser and Node.js. Basically, it provides a simple and elegant API to interact with the XMLHttpRequests and handles the responses with the use of promises. Using Axios...
6 min read
? Radio button is an input type that is used to get input from the user by selecting one value from multiple choices. You have seen the radio buttons to choose gender between male and female. We select only one entry, either male or female and...
4 min read
We will understand string formatting in JavaScript in this article. Let us first understand the JavaScript string. JavaScript string The JavaScript string is the series of characters that are kept inside single or double quotes. The string's first character is indexed at 0 and the second character is...
4 min read
Introduction Designing websites has been implemented by a lot of tech companies where the programming language JavaScript has become efficient usage. Its inherent single-threading is one of its fundamental qualities, despite its diversity. JavaScript runs code in a single-threaded environment, in contrast to languages like C++ or...
7 min read
What is Selenium in JavaScript? In JavaScript, selenium is a browser automation library. It is most often used for testing web applications, Selenium may be used for any task that requires automating interaction with the browser. It is an open-source web testing framework that is used for automated...
6 min read
An important asset for anyone wanting to work as a web developer is JavaScript. According to the Developer Survey, JavaScript holds the top spot as the most frequently utilized programming language. In a year, the top JavaScript boot camp schools will teach you all the practical...
14 min read
JavaScript, a versatile and widely used programming language, offers numerous functionalities to developers for building dynamic and interactive web applications. One such feature is the ability to access and manipulate various components of a webpage, including its hostname. In this article, we delve into the concept...
8 min read
What is WebAssembly (Wasm)? Wasm, short for WebAssembly, is the binary instruction format used by compilers to turn high-level languages like C, Rust, and C++ into low-level machine code that the browser can then execute or whatever it is that you are compiling for. By letting developers...
17 min read
The Greatest Common Divisor (GCD) is a fundamental mathematical concept used in various computational tasks, ranging from cryptography to optimization algorithms. Computing the GCD is a common requirement in many applications in JavaScript. In this article, we'll explore what GCD is, its significance, and how to...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India