2.6_路径描边与填充

2.6_路径描边与填充

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>路径描边与填充</title>
        <style>
        body{
            background: #000000;
        }
            #canvas{
                background: #fff;
            }
        </style>
    </head>
    <body>
        <canvas id="canvas" width="1100" height="650"></canvas>
    </body>
    <script>
        var canvas = document.getElementById('canvas'),
            context = canvas.getContext('2d');

            //设置样式
            context.font = '48pt Helvetica';
            context.strokeStyle = 'blue';
            context.fillStyle = 'red';
            context.lineWidth = '2';

            //第一排文字
            context.strokeText('stroke',60,110);
            context.fillText('Fill',440,110);
            context.strokeText('Stroke&Fill',650,110);
            context.fillText('Stroke&Fill',650,110);

            //第二排四边形
            context.lineWidth = '5';
            context.beginPath();
            context.rect(80,150,150,100);
            context.stroke();

            context.beginPath();
            context.rect(400,150,150,100);
            context.fill();

            context.beginPath();
            context.rect(750,150,150,100);
            context.fill();
            context.stroke();

            //开放路径的弧形
            context.beginPath();
            context.arc(150,370,60,0,Math.PI*3/2);
            context.stroke();

            context.beginPath();
            context.arc(475,370,60,0,Math.PI*3/2);
            context.fill();

            context.beginPath();
            context.arc(820,370,60,0,Math.PI*3/2);
            context.stroke();
            context.fill();

            //第四排闭合路径的弧形
            context.beginPath();
            context.arc(150,550,60,0,Math.PI*3/2);
            context.closePath();
            context.stroke();

            context.beginPath();
            context.arc(475,550,60,0,Math.PI*3/2);
            context.closePath();
            context.fill();

            context.beginPath();
            context.arc(820,550,60,0,Math.PI*3/2);
            context.closePath();
            context.stroke();
            context.fill();
    </script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值