我对HTML中的画布元素很陌生,并试图使用.arc()方法来制作类似于.arc()的东西。
下面是我的代码:(或JSFiddle)
<canvas height = "500" width = "500" id = "myCanvas"></canvas>Javascript
let canvas = document.getElementById('myCanvas');
let ctx = canvas.getContext("2d");
ctx.strokeStyle = '#000';
ctx.fillStyle = "red";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(50, 50, 50, 0, Math.PI, true);
ctx.arc(150, 50, 50, 0, Math.PI);
ctx.fill();
ctx.stroke(); 我得到了一条横线连接开始和结束的两个连接的半圆。我怎么才能把它移除?
发布于 2019-05-30 00:44:02
你需要moveTo你的第二个弧的开头: cx + rad,cy
let canvas = document.getElementById('myCanvas');
let ctx = canvas.getContext("2d");
ctx.strokeStyle = '#000';
ctx.fillStyle = "red";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(50, 50, 50, 0, Math.PI, true);
// move the pointer to the next drawing point without tracing anything
ctx.moveTo(150 + 50, 50);
ctx.arc(150, 50, 50, 0, Math.PI);
ctx.fill();
ctx.stroke();<canvas height="500" width="500" id="myCanvas"></canvas>
https://stackoverflow.com/questions/56370055
复制相似问题