Using paths to draw arcs in HTML5 canvas

Source: Internet
Author: User

In a canvas drawing, an "arc" can be either an integral circle or a part of a circle.

The code is as follows:

Context.arc ()

Context.arc (x, y, radius, startangle, Endangle, anticlockwise)

In the above method description, X and Y define the center of the circle, and radius defines the radius of the circumference. StartAngle and Endangle are expressed in polar coordinates. Anticlockwise (Boolean value) defines the direction of the arc.

For example, if we want to draw a circle with a radius of 20 at the center of a point (100, 100), we can use the following code:

The code is as follows:

Context.arc (math.pi/180) *0, (math.pi/180) *360, false);

The execution effect is:

It is worth noting that in the code above, we need to convert the starting angle (0) and the end Angle (360) by multiplying (math.pi/180) to the polar coordinate radians. When the starting angle is 0 and the end angle is 360, an integral circle is obtained.

In addition to the whole circle, we can also draw arc fragments. The following code depicts One-fourth circles:

The code is as follows:

Context.arc (math.pi/180) *0, (math.pi/180) *90, false);

We can set anticlockwise to true if we want to draw three-fourths other circles apart from the above arc:

The code is as follows:

Context.arc (math.pi/180) *0, (math.pi/180) *90, true);

1: In the canvas coordinate system, the Y axis is in the downward direction.

2: Using the Context.arcto () method can also be used to draw arcs. The description of the method in the HTML5 Canvas original of Steve Fulton & Jeff Fulton is completely wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.