html5 繪製類似牆型的背景,html5繪製背景

來源:互聯網
上載者:User

html5 繪製類似牆型的背景,html5繪製背景

最近開發的項目中要使用html5繪製各種虛線包括貝塞爾虛線、圓形虛線、各種虛線段,還包括各種形式的背景牆,如下:


從這張圖片中可以看出有很多種形式的虛線和背景牆,下面主要介紹一下牆型背景,如下如:

                                                                                                             

這中背景圖有一定的規律,首先應該繪製一個矩形,填充色為藍色,然後在矩形上面繪製背景牆。

背景牆的繪製步驟如下:

1、繪製橫線

2、繪製豎線

3、進行描邊

上述三個步驟中不叫麻煩的是繪製豎線,但是如果繪製過所示的背景就簡單很多了:

                                                                                                                    

這個就是繪製豎線了,設定好的線寬就能看起來很不錯了。下面給出繪製牆型的源碼:

/** * 繪製牆 * @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++) {        //是否偶數條資料        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));            }        }        //奇數條資料        else        {            for (var j = 0; j < indexy; j+=2) {                context.moveTo(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();}

在上面的代碼中可以很明確的看出繪製步驟。


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.