清除矩形

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas id="clear" width="400" height="400" style="background-color: darkmagenta;"></canvas>
<script>
var mycon = document.getElementById("clear").getContext("2d");
mycon.fillStyle = "red";
mycon.fillRect(0,0,100,100);
mycon.clearRect(20,20,50,50);//清除矩形


//第一张图为三角形,是自定义的形状,没有闭合,所以需要beginPath和closePath
mycon.beginPath();
mycon.lineWidth = 20;
mycon.lineJoin = "round";//两条线相交之处设置为圆角
mycon.moveTo(10,200);
mycon.lineTo(200,200);
mycon.lineTo(100,50);
mycon.closePath();
mycon.stroke();

//第二张图为矩形,不需要beginPath和closePath
mycon.rect(10,100,200,50);
mycon.stroke();
mycon.clip();//将矩形设置为剪裁区域
mycon.fillStyle = "aquamarine";//将两张图绘制完后再进行填充渲染
mycon.fill();
</script>
</body>
</html>

转载于:https://www.cnblogs.com/996158041chenlu/p/5730690.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值