关于 html canvas 画圆弧的小技巧

首先,这个代码不是我写的,但是在网上找的资料都太麻烦,需要各种画线,其实完全没有必要,两局核心代码就搞定了,代码来源于网上的转盘游戏的源码:

提取关键的两句代码,整理一下

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-2.1.4.js"></script>
	</head>
	<body style="width: 100%;height: 100%;margin: 0;padding: 0;">
		<div style="width: 600px;height: 600px;margin: 0 auto;">
			<canvas width="500px" height="500px" id="wheelCanvas"></canvas>
		</div>
		<script>
			var canvas = document.getElementById("wheelCanvas");
			
			var ctx = canvas.getContext("2d");
			
			ctx.beginPath();
			ctx.fillStyle="#FFBE04";
			
			ctx.strokeStyle="red";
			
			ctx.arc(canvas.width*0.5,canvas.height*0.5,200,0,Math.PI*2/16,false);
			ctx.arc(canvas.width*0.5,canvas.height*0.5,0,Math.PI*2/16,0,true);
			
			ctx.closePath();
		
			ctx.stroke();
			ctx.fill();
			
		</script>
	</body>
</html>

 效果如图:

 

当然,想要修改角度也很简单

 

转载于:https://www.cnblogs.com/alfrag/p/6296625.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值