Html5-beginpath precautions

Source: Internet
Author: User
Tags border color


 functionShow () {//Usebeginpath (); Notusebeginpath (); }   functionUsebeginpath () {varObj=document.getelementbyid ("Demo"); varContext=obj.getcontext ("2d");  for(vari=0;i<5;i++) {Context.beginpath (); Context.rect (10+I*20,10+I*20,210-I*40,210-I*40);//draw the path of the drip;Context.stroke ();//Start Stroke     }    }   functionNotusebeginpath () {varObj=document.getelementbyid ("Demo"); varContext=obj.getcontext ("2d");  for(vari=0;i<5;i++){          //Context.beginpath ();Context.rect (10+I*20,10+I*20,210-I*40,210-I*40);//draw the path of the drip;Context.stroke ();//Start Stroke          //because it has a stroke once, then his content will be in the front of the description of the first place AH;     }    }



Use the path in the Canvas, you should maintain a good habit, every time you start to draw a path before you call the Beginpath method, otherwise the effect of the painting is ugly, but also seriously affect performance.

In the following diagram, the left side of the graph calls one beginpath at a time before each draw of the rectangle to clear the previous path and starts drawing the new path again, and the subsequent graphic only calls a beginpath to clear the path before drawing all the graphics, so although the border color used here is # 666, but the graphic color on the right is darker than the left, because each time you use the stroke to draw the border, the previous path is drawn again, and the color is superimposed more deeply than the original.

Html5-beginpath precautions

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: 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.