Html5-Canvas draw line

Source: Internet
Author: User

Function draw (){
Var canvas = document. getElementById ("canvas ");
Var cxi = canvas. getContext ("2d ");

Cxi. fillStyle = "rgb (200,0, 0 )";

Cxi. beginPath ();
Cxi. moveTo (75, 50 );
Cxi. lineTo (100,85 );
Cxi. lineTo (100,20 );
Cxi. fill ();
} <Body onLoad = "draw ();">

<Canvas id = "canvas" width = "150" height = "150"> </canvas> <br>

</Body>

 
Cxi. beginPath (); initialize path painting; cxi. moveTo (); Determine the "Starting Point" coordinate of the path; cxi. lineTo (); Determine the coordinates of another "Node"; cxi. lineTo (); Determine the coordinates of the other two "nodes"; (the nodes here can be understood as the path tool points out in PhotoShop, points) cxi. fill (); the "starting point", "first node", and "second node" are drawn. Three vertices are directly linked. Form a triangle. For example:



 

A point on the left of the triangle is: cxi. moveTo );

A point above the triangle is: cxi. lineTo );

A point below the triangle is: cxi. lineTo );

The parameter coordinates here are the coordinates 0. 0 relative to the canvas element, that is, the upper left corner;

 

From Captain op

Related Article

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.