HTML5 Canvas Learning

Source: Internet
Author: User

Canvas

First, add the canvas label to the HTML page

<canvas id= "Canvas" width= "1024x768" height= "742" display= "block" ></canvas>

Window.onload=function () {

var Canvas=document.getelementbyid ("Canvas");

You can also specify width,height directly here, which not only represents a wide height, but also represents the precision

canvas.width=1024, ...

var Context=canvas.getcontext ("2d");

Context.moveto (100,100);

Context.lineto (700,700);

Context.lineto (100,700);

Context.lineto (100,100);

context.linewidth=5;

Context.strokestyle= "#aabbcc";

Context.stroke ();//The drawing of triangles is done here
}

If you want to fill the graphic, do not use a stroke,

Code:

Context.fillstyle ("#aabbcc");

Context.fill ();

In the drawing process, the careful scholar will find that when drawing two graphics, the style ultimately depends on the last brush style, then how can solve this problem? Context.beginpath () and Context.closepath () are used.

Context.beginpath ()

Context.moveto (100,100);

Context.lineto (700,700);

Context.lineto (100,700);

Context.closepath ();

So you can make sure that the enclosing shape changes only once.

Context.lineto (100,100);

After learning to draw a line, what is the function of drawing an arc?

Context.arc (center x Point, center y Point, Radius, radian start value, Arc end value, false)//The last parameter indicates whether to draw clockwise or counterclockwise, by default false, drawn clockwise.

HTML5 Canvas Learning

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.