Study Notes on HTML5 canvas (2)-deep learning

Source: Internet
Author: User

Small man (Bill man) Personal Original, welcome to reprint, reprint please indicate the address, small man (Bill man) column address http://blog.csdn.net/bill_man

The previous article introduced the basic concepts of HTML5 canvas. it is not difficult for most programmers who have learned how to use the canvas of j2s and Android for drawing. This article continues with the previous article to explain how to draw straight lines and arcs.

The following code first explains how to draw a straight line:

The beginpath and closepath methods are used here to indicate the start path and end path, each node in the middle of the path, and the moveTo parameter is the start coordinate, lineto parameter indicates the end point of the line segment. In this way, we have completed a path, but note that we have not completed the painting. The focus is on the following sentence. Stroke is a hollow painting, and fill is a solid filling. It should be noted that for a line segment, using fill will not have any effect. Using the beginpath, closepath, moveTo, and lineto functions can not only draw a straight line, but also draw a triangle and a rectangle. The first is the code of the flower triangle:

This code connects three points to form a triangle. The following code connects the four points to form a quadrilateral:

The effects of the two codes are as follows:

The following code draws an arc:

There is no difference from the above in other aspects. The key is the parameters of the arc function, which are the cross coordinate of the center, the vertical coordinate of the center, the radius of the circle, and the starting angle (in radians ), the arc angle drawn (in radians). If the last Boolean parameter is false, it is clockwise. If it is true, it is counterclockwise. The starting angle is the angle between the start side and the level, the Start side rotates clockwise around the horizontal position.

Context. ARC (400,100, 60, math. PI/18, math. Pi, false); effect:

Context. ARC (400,100, 60, math. PI/18, math. Pi, true); effect:

In case of any errors, I hope you can correct them more.

Next, continue to study the drawing style

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.