您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页H5-canvas 入门

H5-canvas 入门

来源:二三娱乐
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
</head>
<body>
    <canvas width="600px" height="600px" id="mycanvas"></canvas>
    <script type="text/javascript">
        var canvas=document.getElementById('mycanvas');
        if(canvas.getContext){
            var ctx=canvas.getContext('2d');
        }
        ////绘制线
        ctx.beginPath();
        ctx.moveTo(50,50);
        ctx.lineTo(100,100);
        ctx.lineTo(80,90);
        ctx.lineWidth=2;
        //线条颜色
        ctx.strokeStyle='#ff0000';
        ctx.stroke();
        ////绘制矩形(实心)
        ctx.clearRect(60,50,20,20);
        //清除指定矩形区域
        ctx.fillRect(160,150,70,80);
        ctx.strokeStyle='orange'
        ctx.strokeRect(170,160,50,50);
        ////绘制文本
        ctx.font='Bold 20px Arial';
        ctx.textAlign='left';
        ctx.fillStyle='brown';
        ctx.fillText('hello canvas',0,200);
        ////绘制空心文本
        ctx.strokeStyle='gray';
        ctx.strokeText('hello.canvas',0,260);
        ////绘制圆
        ctx.beginPath();
        ctx.arc(80,360,40,0,Math.PI*2,true);
        ctx.fillStyle='yellow';
        ctx.fill();
        ////绘制空心圆
        ctx.beginPath();
        ctx.arc(180,360,40,0,Math.PI*2,true);
        ctx.strokeStyle='green';
        ctx.lineWidth=1.0;
        ctx.stroke();
        ////绘制渐变色,填充矩形
        var myGradient=ctx.createLinearGradient(0,700,160,160);
        myGradient.addColorStop(0,'red');
        myGradient.addColorStop(1,'yellow');
        ctx.fillStyle=myGradient;
        //绘制阴影
        ctx.shadowOffsetX=2;
        ctx.shadowOffsetY=2;
        ctx.shadowBlur=3;
        ctx.shadowColor='rgba(22,22,22,.5)';
        ctx.fillRect(0,420,160,160);

    </script>
</body>
</html>

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务