Canvas 绘制矩形(rect(),strokeRect(),fillRect())


demo.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="cvs" width="500" height="500"></canvas>
    <script>
        var cvs = document.getElementById('cvs');
        var ctx = cvs.getContext('2d');

        /*
        * 画一个矩形路径:
        * ctx.rect( 起点x轴坐标,起点y轴坐标,宽,高 );
        * */
        ctx.rect( 30, 10, 50, 50 );
        ctx.stroke();  //需要手动调用 stroke()或fill()方法绘制。

        /*
        * 绘制一个描边矩形,直接绘制,不需要手动调用stroke():
        * ctx.strokeRect( 起点x轴坐标,起点y轴坐标,宽,高 )
        * */
        ctx.strokeRect( 30, 100, 50, 50 );

        /*
         * 绘制一个填充矩形,直接绘制,不需要手动调用fill():
         * ctx.fillRect( 起点x轴坐标,起点y轴坐标,宽,高 )
         * */
        ctx.fillRect( 30, 170, 50, 50 );
    </script>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值