作者:点提土八撇又254 | 来源:互联网 | 2023-05-19 16:37
IamtryingtocreateSimongameusingHTML5canvasandvanillaJavaScript.Iamconfusedaboutthe
I am trying to create Simon game using HTML5 canvas and vanilla Javascript. I am confused about the coordinate system in the arc() method. I have divided the circle into 4 quadrants and would like to alert the number of the quadrant clicked. But, I am not sure how to find out which part of the circle was clicked. https://jsfiddle.net/xawpLdys/1/
我正在尝试使用HTML5 canvas和vanilla Javascript创建Simon游戏。我对arc()方法中的坐标系感到困惑。我已将圆圈划分为4个象限,并想提醒点击的象限数量。但是,我不知道如何找出圈子的哪个部分被点击。 https://jsfiddle.net/xawpLdys/1/
var canvas = document.getElementById('myCanvas');
var cOntext= canvas.getContext('2d');
var x = canvas.width / 2;
var y = canvas.height / 2;
var pads = [];
var angle = 2 * Math.PI / 4;
var color = ["green","red","blue","yellow"];
var Pads = function(x, y, radius, start, end) {
this.x = x;
this.y = y;
this.radius = radius;
this.start = start;
this.end = end;
};
function drawSimon(radius) {
for (var i = 0; i <4; i++) {
context.beginPath();
context.moveTo(x, y);
context.arc(x, y, radius, i*angle, (i+1)*angle, false);
context.lineWidth = radius;
context.fillStyle = color[i];
context.fill();
context.lineWidth = 2;
context.strokeStyle = '#444';
context.stroke();
var pad = new Pads(x, y, radius, i*angle, (i+1)*angle);
pads.push(pad);
}
}
drawSimon(150);
$('#myCanvas').click(function (e) {
/*for (var i = 0; i
2 个解决方案