在Javascript中添加点
我需要一些帮助。我需要创建一个代码,广告指向我的圈子,并提供一个下拉栏。 这是我到目前为止创建sircle的代码在Javascript中添加点,javascript,Javascript,我需要一些帮助。我需要创建一个代码,广告指向我的圈子,并提供一个下拉栏。 这是我到目前为止创建sircle的代码 var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); var punkter = []; // List over all the points. var antall = 16 ++; // Number of points the s
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var punkter = []; // List over all the points.
var antall = 16 ++; // Number of points the sircle should have .
var step = 2 * Math.PI / antall; // Angle ran between each point.
var r = 300; // The radius of the circle.
var v = 0; // The angle of the circle.
//----- Background ------
ctx.beginPath();
ctx.rect(0,0,800,800);
ctx.fillStyle = "#ffd083";
ctx.fill();
function calculate() {
//Calculates all the points
for (var i = 0; i < antall; i++) { // i = []
var x = 400 + r * Math.cos(v); //Placement
var y = 400 + r * Math.sin(v); //Placement
punkter[i] = new Point(x, y);
v += step; // For each point, the angle changes.
}
}
function draw() {
//Drawing the sircle
ctx.beginPath(); // Starting a line.
ctx.moveTo(punkter[0].x, punkter[0].y); // Draws line from one point to a new one.
for (var i = 1; i < antall; i++) {
ctx.lineTo(punkter[i].x, punkter[i].y);
}
ctx.closePath();
ctx.stroke();
}
function Point(x, y) {
this.x = x;
this.y = y;
}
calculate();
draw();
var canvas=document.getElementById(“myCanvas”);
var ctx=canvas.getContext(“2d”);
var punkter=[];//列出所有要点。
var antall=16++;//sircle应具有的点数。
var step=2*Math.PI/antall;//每个点之间都有一个角度。
var r=300;//圆的半径。
var v=0;//圆的角度。
//-----背景------
ctx.beginPath();
ctx.rect(0,0800);
ctx.fillStyle=“#ffd083”;
ctx.fill();
函数计算(){
//计算所有点
对于(var i=0;i
所以重点是创建一个圆,在其中可以添加绘制点并更改绘制点(我认为)
正如您所看到的,我对编码非常陌生。如果您想让我们现在就理解这些注释,您可能需要英文注释。感谢tipI还建议您构建一个代码笔(),以便更好地展示您的案例: