html5canvas繪圖的基本使用方法

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

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的榮成網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

繪制線段moveTo()和lineTo()

以下是一個(gè)簡(jiǎn)單的<canvas>繪圖示例:

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>canvas繪圖演示</title>

    <style type="text/css">

        #canvas{

            border: 1px solid #ADACB0;

            display: block;

            margin: 20px auto;

        }

    </style>

</head>

<body>

    <canvas id="canvas" width="300" height="300">

        你的瀏覽器還不支持canvas

    </canvas>

</body>

<script type="text/javascript">

    var canvas = document.getElementById("canvas");

    var context = canvas.getContext("2d");

    //設(shè)置對(duì)象起始點(diǎn)和終點(diǎn)

    context.moveTo(10,10);

    context.lineTo(200,200);

    //設(shè)置樣式

    context.lineWidth = 2;

    context.strokeStyle = "#F5270B";

    //繪制

    context.stroke();

</script>

</html>

繪制五角星

var canvas = document.getElementById("canvas");

    var context = canvas.getContext("2d");

    context.beginPath();

    //設(shè)置是個(gè)頂點(diǎn)的坐標(biāo),根據(jù)頂點(diǎn)制定路徑

    for (var i = 0; i < 5; i++) {

        context.lineTo(Math.cos((18+i*72)/180*Math.PI)*200+200,

                        -Math.sin((18+i*72)/180*Math.PI)*200+200);

        context.lineTo(Math.cos((54+i*72)/180*Math.PI)*80+200,

                        -Math.sin((54+i*72)/180*Math.PI)*80+200);

    }

    context.closePath();

    //設(shè)置邊框樣式以及填充顏色

    context.lineWidth="3";

    context.fillStyle = "#F6F152";

    context.strokeStyle = "#F5270B";

    context.fill();

    context.stroke();

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

網(wǎng)頁標(biāo)題:html5canvas繪圖的基本使用方法
轉(zhuǎn)載來源:http://muchs.cn/article8/jcpgip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、App開發(fā)營銷型網(wǎng)站建設(shè)、定制網(wǎng)站虛擬主機(jī)、微信小程序

廣告

聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)