Code
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; } }
Results:
Analysis:
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