@.ctx.lineWidth = 20
@.ctx.moveTo(i.x, i.y)
@.ctx.arc(i.x, i.y, 3, 0, Math.PI * 2)
该代码使上面的图像具有任何原因?
最佳答案
我尝试了您的弧形版本,但很难理解您的要求。因此,我制作了两个版本,以便直观地显示正在发生的事情。
你可以在这里看看他们!
更新的JSFIDDLE
http://jsfiddle.net/hqB6b/2/
的HTML
First with the line inside.
<canvas id="ex" width="300" height="300">
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>
Second with NO line inside!
<canvas id="example" width="300" height="300">
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>
JS
var example = document.getElementById('example');
var ctx = example.getContext('2d');
var i = {x:100,
y:100}
ctx.strokeStyle = '#ff0000';
ctx.lineWidth = 1;
ctx.moveTo(i.x, i.y)
//HERE BEGINPATH IS USED AFTER MOVETO
ctx.beginPath();
ctx.arc(i.x, i.y, 50, 0, Math.PI * 2)
ctx.stroke();
var ex = document.getElementById('ex');
var ct = ex.getContext('2d');
var i = {x:100,
y:100}
ct.strokeStyle = '#ff0000';
ct.lineWidth = 1;
//HERE BEGINPATH IS USED BEFORE MOVETO
ct.beginPath();
ct.moveTo(i.x, i.y)
ct.arc(i.x, i.y, 50, 0, Math.PI * 2)
ct.stroke();
关于javascript - Canvas 弧线绘制奇怪的形状-Coffeescript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21354651/