我一直在 HTML 画布上绘制矩形很好,但我的项目也需要使用圆形,这似乎不起作用。矩形是用这个绘制的:
var myGameArea = {
canvas: document.createElement("canvas"),
start: function () {
this.canvas.width = 300;
this.canvas.height = 500;
this.context = this.canvas.getContext("2d");
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
}
}
function component(width, height, color, x, y, ) {
this.width = width;
this.height = height;
this.x = x;
this.y = y;
ctx = myGameArea.context;
ctx.fillStyle = color;
ctx.fillRect(this.x, this.y, this.width, this.height);
}
如何使用类似的方法绘制圆圈?
一个很好的起点是 HTML Canvas 参考:https : //www.w3schools.com/tags/ref_canvas.asp它提供了这个特定问题的提示,甚至为您的项目的进一步要求提供了提示。
根据此参考,您的特定问题可以使用 arc() 方法解决。https://www.w3schools.com/tags/canvas_arc.asp
如果你想填充它,提到的 fill() 方法有帮助:https : //www.w3schools.com/tags/canvas_fill.asp
希望解决这个问题和进一步的挑战。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句