javascript - Canvas 弧线绘制奇怪的形状 - CoffeeScript

标签 javascript html canvas coffeescript drawing

@.ctx.lineWidth = 20
@.ctx.moveTo(i.x, i.y)
@.ctx.arc(i.x, i.y, 3, 0, Math.PI * 2)

enter image description here

为什么该代码会生成上面的图像?

最佳答案

我尝试了你的弧线版本,但我发现很难理解你实际上在问什么。因此我制作了两个版本,以便直观地向您展示发生了什么。

你可以在这里查看它们! 更新的 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/

相关文章:

javascript - 内部 html 单选按钮数组值被写入 for 循环

java - Selenium 无法在 Iframe 中找到元素,即使它们可见

javascript - Paper.js 鼠标事件不与 Canvas 转换一起翻译

javascript - 我无法使用 Canvas 从 blob URL 中裁剪图像

未使用 Moment.js 定义 Javascript 函数

javascript - "Sleep"异步迭代内执行 "for await"(ES2018)

javascript - 更改数据表中特定列的颜色

javascript - 在 html 中作为 id 传递的 jQuery 值

javascript - 角色 ="button"是什么意思?

css - 只有一个 Ddiv 时如何将背景图像置于最前面