canvas画布 矩形圆角

canva 画布圆角


function drawRoundRect(ctx, x, y, width, height, radius){    
	ctx.beginPath();    
	ctx.arc(x + radius, y + radius, radius, Math.PI, Math.PI * 3 / 2);    
	ctx.lineTo(width - radius + x, y);    
	ctx.arc(width - radius + x, radius + y, radius, Math.PI * 3 / 2, Math.PI * 2);    
	ctx.lineTo(width + x, height + y - radius);    
	ctx.arc(width - radius + x, height - radius + y, radius, 0, Math.PI * 1 / 2);    
	ctx.lineTo(radius + x, height +y);    
	ctx.arc(radius + x, height - radius + y, radius, Math.PI * 1 / 2, Math.PI);    
	ctx.closePath();    
}

调用方法

var canvas = document.getElementById('cvs');
canvas.width = drawdata.boardwidth;//画布大小
canvas.height = drawdata.boardheight;//画布大小
var ctx = canvas.getContext("2d");

drawRoundRect(ctx, 矩形距离x坐标位置, 矩形距离y坐标的位置, 矩形的宽, 矩形的长,圆角角度);

drawRoundRect(ctx, 300, 200, 150, 80, 6);
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值