为了账号安全,请及时绑定邮箱和手机立即绑定

月亮只出来一个弧

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>createMood</title>
</head>
<body>
<canvas id="canvas" style="border:1px solid #ddd;"></canvas>

<script>
window.onload = function(){
var canvas = document.getElementById("canvas");
canvas.width = 800;
canvas.height = 800;
var context = canvas.getContext("2d");
//以400 400 为圆心,300为半径,逆时针绘制半弧,月亮的外圆
context.arc(400,400,300,0.5*Math.PI,1.5*Math.PI,true);
context.moveTo(400,100);
//以1200 400 为圆心 画内弧
context.arcTo(1200,400,400,700,(400 - 100)*dis(400,100,1200,400)/(1200 - 400));
context.stroke();
}
function dis(x1,y1,x2,y2){
return Math.sqrt(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
</script>
</body>
</html>

http://img3.sycdn.imooc.com/6322d7760001276209681342.jpg

正在回答

举报

0/150
提交
取消

月亮只出来一个弧

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信