如何使用html5繪制圓形多角圖案

本篇文章為大家展示了如何使用html5繪制圓形多角圖案,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站重做改版、天臺(tái)網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為天臺(tái)等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。

先看看最簡(jiǎn)單的效果圖:

如何使用html5繪制圓形多角圖案

代碼如下:

JavaScript Code復(fù)制內(nèi)容到剪貼板

  1. var canvas = document.getElementById('my'), ctx = canvas.getContext('2d');   
      setInterval(function(){   
        ctx.clearRect(0,0,400,400);   
        ctx.save();   
        ctx.translate(200,200);   
        var ci =90, pi = Math.PI / ci, x1 = 100, y1 =0, x2 =0, y2 =0, x3 =0, y3 =0;   
        ctx.beginPath();   
        for(var i = ci *2; i >0; i--){   
          ctx.rotate(pi);   
          ctx.moveTo(x1,y1);   
          y2 = x1 * Math.sin(pi);   
          x2 = x1 * Math.cos(pi);   
          x3 = (x1 - x2) /2+ x2 +10+ Math.random() *20;   
          y3 = y2 /2;   
          ctx.lineTo(x3,y3);   
          ctx.lineTo(x2,y2);   
        }   
        ctx.stroke();   
        ctx.restore();   
      },100);


在上面多角形的基礎(chǔ)上進(jìn)一步之后為:

如何使用html5繪制圓形多角圖案

代碼如下:

JavaScript Code復(fù)制內(nèi)容到剪貼板

  1. var canvas = document.getElementById('my'), ctx = canvas.getContext('2d'), r =10;   
        setInterval(function(){   
          ctx.clearRect(0,0,400,400);   
          ctx.save();   
          ctx.translate(200,200);   
          var grad = ctx.createRadialGradient(0,0,0,0,0,r+20);   
          grad.addColorStop(0.2,'white');   
          grad.addColorStop(0.7,'yellow');   
          grad.addColorStop(0.8,'orange');   
          ctx.beginPath();   
          ctx.fillStyle = grad;   
          ctx.arc(0,0,r,0,Math.PI*2,true);   
          ctx.fill();   
        var ci =90, pi = Math.PI / ci, x2 =0, y2 =0, x3 =0, y3 =0;   
          x1 =100;   
          y1 =0;   
          ctx.beginPath();   
          for(var i = ci *2; i >0; i--){   
            ctx.rotate(pi);   
            ctx.moveTo(r,0);   
            y2 = r * Math.sin(pi);   
            x2 = r * Math.cos(pi);   
      
            x3 = (r - x2) /2+ x2 +10+ Math.random() *20;   
            y3 = y2 /2;   
      
            ctx.lineTo(x3,y3);   
            ctx.lineTo(x2,y2);   
          }   
          ctx.fill();   
          ctx.restore();   
          r <=100&& (r +=2);   
       },100);

上述內(nèi)容就是如何使用html5繪制圓形多角圖案,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享標(biāo)題:如何使用html5繪制圓形多角圖案
網(wǎng)頁(yè)URL:http://bm7419.com/article38/pcgjpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)定制開(kāi)發(fā)、微信小程序、軟件開(kāi)發(fā)、ChatGPT微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)