Canvas beginPath (), canvasbeginpath

Source: Internet
Author: User

Canvas beginPath (), canvasbeginpath

Let's give a simple example,

Var myCanvas = document. getElementById ("myCanvas ");
Var context = myCanvas. getContext ("2d ");

Context. beginPath ();
Context. moveTo (150, 50 );
Context. lineTo (250, 50 );
Context. strokeStyle = "green ";
Context. stroke ();

Context. beginPath ();
Context. moveTo (150, 80 );
Context. lineTo (250, 80 );
Context. strokeStyle = "yellow ";
Context. stroke ();

 

Context. beginPath ();
Context. moveTo (150,100 );
Context. lineTo (250,100 );
Context. strokeStyle = "blue ";
Context. stroke ();

In this example, three horizontal lines are drawn from top to bottom.

If you remove the third beginPath () method, you will find that the color of the third line is also drawn to the second yellow line. This will find beginPath () the method will allow the drawing to re-locate the start point during painting without overlapping with the previous drawing. In addition, it is still necessary.

 

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.