HTML5 drawing a wall-like background

Source: Internet
Author: User

The most recently developed projects use HTML5 to draw various dashed lines, including Bezier dashes, round dashed lines, various imaginary segments, and various forms of background walls, as follows:


From this picture can be seen there are many forms of dashed and background wall, the following mainly introduce the wall-type background, as follows:


This background map has a certain pattern, you should first draw a rectangle, fill color is blue, and then draw the background wall above the rectangle.

The background wall is drawn in the following steps:

1. Draw Horizontal Line

2. Draw Vertical Line

3. Perform strokes

It is not troublesome to draw a vertical bar in the above three steps, but it is much easier to draw the background as shown:


This is to draw a vertical line, the width of the set can be looked very good. The following is the source of the drawing wall type:

/** * Draw Wall * @param context * @param x * @param y * @param width * @param height * @param color */function drawwall (context    , X,y,width,height,color) {var space = 5;    var Indexx = Width/space;    var indexy = Height/space;    var isEven =false;    Context.beginpath (); for (var i = 0; i < Indexx; i++) {//Whether even number bar data if (IsEven) {for (var j = 1; J < Indexy ;                j+=2) {Context.moveto (x + space * I, Y + space * j);            Context.lineto (x + space * I, Y + space * (j+1)); }}//odd bar data else {for (var j = 0; j < indexy; j+=2) {Context.mo                VeTo (x + space * I, Y + space * j);            Context.lineto (x + space * I, Y + space * (j+1));    }} Iseven=!iseven;        } for (var t= 0;t<indexy;t++) {Context.moveto (x,y+t*space);    Context.lineto (X+width,y+t*space);    } context.linewidth=1; Context.strokestyle=color?color: ' Red'; Context.stroke ();}

The drawing step can be clearly seen in the code above.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HTML5 drawing a wall-like background

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.