<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        使用JS+canvas如何制作圓錐

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 19:36:07
        文檔

        使用JS+canvas如何制作圓錐

        使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數(shù)配合JS畫出一個圓錐形的圖形實例,有需要的朋友學(xué)習(xí)測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
        推薦度:
        導(dǎo)讀使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數(shù)配合JS畫出一個圓錐形的圖形實例,有需要的朋友學(xué)習(xí)測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
        本篇文章給大家講解html中用canvas函數(shù)配合JS畫出一個圓錐形的圖形實例,有需要的朋友學(xué)習(xí)測試下吧。

        以下是我們給大家分享是實例代碼:

        <html>
        <head>
        <title>我的第一個 HTML 頁面</title>
        </head>
        <body>
        <canvas id='cvs' width='1000' height="800">
        </canvas>
        <script>
        const cvs =document.getElementById('cvs');
        
         // 計算畫布的寬度
         const width = cvs.offsetWidth;
         // 計算畫布的高度
         const height = cvs.offsetHeight;
        const ctx = cvs.getContext('2d');
         // 設(shè)置寬高
         cvs.width = width;
         cvs.height = height;
        /**
        ctx:context
        x,y:偏移 縱橫坐標(biāo)
        w:度
        h:高
        color:顏色 數(shù)組,可以把顏色提取出來方便自定義
        */
        var Cone = function(ctx,x,y,w,h,d,color){
        ctx.save();
        ctx.translate(x, y);
        var blockHeight=h;
        // 中點
        var x2 = 0;
        var y2 = 20;
        var k2 = 10;
        var w2 = w;
        var h2 = h;
        // 遞減度
        var decrease = d; 
         ctx.beginPath();
        ctx.moveTo(x2+w2,y2);
        // 橢圓加了邊框,所以加1減1
        ctx.bezierCurveTo(x2+w2, y2+k2, x2-w2, y2+k2, x2-w2-1, y2);
        
        ctx.lineTo(x2-w2+decrease,y2+blockHeight);
        ctx.bezierCurveTo(x2-w2+decrease, y2+blockHeight+k2, x2+w2-decrease, y2+blockHeight+k2, x2+w2-decrease, y2+blockHeight);
        ctx.lineTo(x2+w2+1,y2);
        var linear = ctx.createLinearGradient(x2-w2, y2,x2+w2-decrease, y2+blockHeight);
        linear.addColorStop(0,color[0]);
        linear.addColorStop(1,color[1]);
        ctx.fillStyle = linear ; 
        ctx.strokeStyle=linear 
        ctx.fill();
        //ctx.stroke();
        ctx.closePath();
        //畫橢圓
        ctx.beginPath();
        ctx.moveTo(x2-w2, y2);
        ctx.bezierCurveTo(x2-w2, y2-k2, x2+w2, y2-k2, x2+w2, y2);
        ctx.bezierCurveTo(x2+w2, y2+k2, x2-w2, y2+k2, x2-w2, y2);
        var linear = ctx.createLinearGradient(x2-w2, y2,x2+w2-decrease, y2+blockHeight);
        linear.addColorStop(1,color[0]);
        linear.addColorStop(0,color[1]);
        ctx.fillStyle = linear ; 
        ctx.strokeStyle=linear 
        ctx.closePath();
        
        ctx.fill();
        ctx.stroke();
        
        ctx.restore();
        };
        function dr(m){
        const colorList =[
        {
        color:['#76e3ff','#2895ea'],
        height:60
        },
        {
        color:['#17ead9','#5d7ce9'],
        height:30
        },
        {
        color:['#1ca5e5','#d381ff'],
        height:40
        },
        {
        color:['#ffa867','#ff599e'],
        height:70
        },
        {
        color:['#ffa6e3','#ec6a70'],
        height:50
        },
        {
        color:['#f9c298','#d9436a'],
        height:30
        },
        {
        color:['#eb767b','#9971dc'],
        height:30
        },
        {
        color:['#f06af9','#5983ff'],
        height:100
        },
        ];
        const space = 20;
        let coneHeight = 0;
        // 間隔
        const gap = 20;
        const x = 380;
        const y = 20;
        const angle = 30;
        let coneWidth=0;
        colorList.forEach((item)=>{
        coneHeight += item.height +space;
        });
        // 最下面的先畫(層級)
        colorList.reverse().forEach((item,index)=>{
        const decrease =Math.tan(Math.PI*angle/180)*(item.height+space);
        coneWidth=coneWidth + decrease;
        coneHeight = coneHeight-item.height - space;
        //圓錐
        Cone(ctx,x,coneHeight ,coneWidth ,item.height,decrease,item.color);
        // 中點
        const cX =parseInt(x)+0.5;
        const cY = parseInt(coneHeight + space+ item.height/2)+0.5;
        //文字
        ctx.save();
        ctx.translate(cX , cY );
        ctx.textBaseline='top';
        ctx.textAlign='center';
        const fontSize = item.height/2>=40?40:item.height/2;
        ctx.font = fontSize + 'px serif';
        //const textMetrics = ctx.measureText('Hello World');
        ctx.fillStyle = '#ffffff';
        ctx.fillText('5000',0,-fontSize/3);
        ctx.restore();
        const xLineA =parseInt(coneWidth-decrease/2)+10;
        const xLine =parseInt(m+xLineA )>=x?x:m+xLineA ;
        //線
        ctx.save();
        ctx.translate(cX , cY );
        ctx.setLineDash([3,2]); 
        ctx.strokeStyle = '#a4a4a4'; 
        ctx.beginPath(); 
        ctx.moveTo(xLineA , 0); 
        ctx.lineTo(xLine +20, 0); 
        ctx.stroke();
        ctx.restore();
        //描述文字
        ctx.save();
        ctx.translate(cX , cY );
        ctx.textBaseline='middle';
        ctx.textAlign='left';
        ctx.font = '22px serif';
        //const textMetrics = ctx.measureText('Hello World');
        ctx.fillStyle = '#4a4a4a';
        ctx.fillText('進(jìn)入收件列表2',xLine+gap ,0);
        ctx.restore();
        //轉(zhuǎn)化率文字
        ctx.save();
        ctx.translate(cX , cY );
        ctx.textBaseline='middle';
        ctx.textAlign='left';
        ctx.font = '28px bold serif ';
        ctx.fillStyle = '#007dfd';
        ctx.fillText('20%',xLine+gap ,(item.height+gap)/2 );
        ctx.restore();
        });
        }
        let m=0; 
        let gravity =10; 
        (function drawFrame(){
         window.requestAnimationFrame(drawFrame,cvs);
         ctx.clearRect(0,0,cvs.width,cvs.height);
        m += gravity;
         dr(m);
        })();
        </script>
        </body>
        </html>

        這是腳本之家測試后的完成圖:

        上面是我整理給大家的,希望今后會對大家有幫助。

        相關(guān)文章:

        在Django與Vue語法中存在沖突問題如何解決

        有關(guān)JS抽象工廠模式(詳細(xì)教程)

        使用Javascript如何開發(fā)二維周視圖日歷

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        使用JS+canvas如何制作圓錐

        使用JS+canvas如何制作圓錐:本篇文章給大家講解html中用canvas函數(shù)配合JS畫出一個圓錐形的圖形實例,有需要的朋友學(xué)習(xí)測試下吧。以下是我們給大家分享是實例代碼:<html> <head> <title>我的第一個 HTML 頁面</title> </head>
        推薦度:
        標(biāo)簽: js 怎么 圓錐
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲欧洲校园自拍都市| 国产午夜免费福利红片| 亚洲精品乱码久久久久久中文字幕 | 亚洲成AV人片久久| 性色午夜视频免费男人的天堂| 亚洲中文字幕久久精品无码APP| 一级成人a免费视频| 亚洲XX00视频| 亚洲国产成人91精品| 久久99毛片免费观看不卡| 久久亚洲AV成人无码国产最大| 久久99九九国产免费看小说| 亚洲国产日韩在线| 97视频热人人精品免费| 日韩精品视频免费网址| 亚洲AV无码一区二区三区电影| 国产极品粉嫩泬免费观看| 四虎精品成人免费视频| 国产精品免费大片一区二区| 国产精品亚洲mnbav网站| 国产色无码精品视频免费| 亚洲国语精品自产拍在线观看| 亚洲w码欧洲s码免费| 亚洲日韩国产一区二区三区在线 | 2021免费日韩视频网| 亚洲电影日韩精品| 久久性生大片免费观看性| 亚洲日本中文字幕区| 午夜成年女人毛片免费观看| 国产成人亚洲精品91专区高清| 亚洲免费在线观看| 免费视频成人片在线观看| 国产精品高清视亚洲一区二区| 亚洲?V无码乱码国产精品| 特级精品毛片免费观看| 亚洲一卡2卡3卡4卡5卡6卡| 国产精品视频免费| 最新亚洲人成无码网站| 亚洲爆乳精品无码一区二区三区| 亚洲色大成WWW亚洲女子| 久久久久亚洲精品中文字幕|