Javascript 仅在保存p5.js草图后发生语法错误

Javascript 仅在保存p5.js草图后发生语法错误,javascript,processing,p5.js,Javascript,Processing,P5.js,我正在试验用户Alex()在openprocessing.org上找到的代码 如果我在使用p5.js模式进行处理时在未保存的草图中运行该代码,那么该代码执行得很好,但一旦我尝试保存项目以稍后打开它,它就会出现语法错误并拒绝运行。我被难住了,因为代码在保存项目之前似乎运行得很好 有人知道这是什么原因吗 编译器给了我以下错误: SyntaxError:预期的;但是找到了保利 代码如下: // polygon array and number of verts let poly = []; let n

我正在试验用户Alex()在openprocessing.org上找到的代码

如果我在使用p5.js模式进行处理时在未保存的草图中运行该代码,那么该代码执行得很好,但一旦我尝试保存项目以稍后打开它,它就会出现语法错误并拒绝运行。我被难住了,因为代码在保存项目之前似乎运行得很好

有人知道这是什么原因吗

编译器给了我以下错误:

SyntaxError:预期的;但是找到了保利

代码如下:

// polygon array and number of verts
let poly = [];
let n = 100;

// canvas size variables
let w = 500;
let h = 500;

// setup and draw functions ---

function setup() {
  createCanvas(w, h);
  strokeWeight(12);
  noFill();
  cursor(HAND);
  noStroke();
  n++; // add extra point for closing the polygon

  for (let i = 0; i < n; i++) {
    // populate regular polygon vertices given number of points n
    let a = {
      x: (w/2) + 100*sin(map(i, 0, n-1, 0, TAU)),
      y: (h/2) + 100*cos(map(i, 0, n-1, 0, TAU))
    };
    poly.push(a);
  }      
}

function draw() {
  // use default blend mode for background
  blendMode(BLEND);
  background(0, 0, 0);

  // use additive blend mode to separate color channels
  blendMode(ADD);
  stroke(255, 0, 0);
  drawPoly(1000, 1000);

  stroke(0, 255, 0);
  drawPoly(1200, 1500);

  stroke(0, 0, 255);
  drawPoly(2000, 1700);    
} 

// helper function implementations ---

function logMap(value, start1, stop1, start2, stop2) {
  // based off of linear regression + existing p5.map function

  start2 = log(start2);
  stop2 = log(stop2);

  return exp(start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)));
}

function drawPoly(dx, dy) {
  // draws polygon given vertices in the poly[] array, adds mouse bias using params

  let g = 0;
  if (mouseIsPressed)
    g = random(-2, 2);

  beginShape();
  for (let i = 0; i < n; i++) {
    let bias = dist(mouseX, mouseY, poly[i].x, poly[i].y);
    vertex(poly[i].x + dx / logMap(bias, w, 0, dx, 45) + g, poly[i].y + dy / logMap(bias, h, 0, dy, 45) + g);
  }
  endShape();
}
//多边形数组和顶点数
设poly=[];
设n=100;
//画布大小变量
设w=500;
设h=500;
//设置和绘制功能---
函数设置(){
createCanvas(w,h);
冲程重量(12);
noFill();
光标(手);
仰泳();
n++;//为闭合多边形添加额外点
for(设i=0;i
我在Sublime文本编辑器中打开了该项目,并使用WAMP/MAMP在本地服务器上运行它,javascript运行正常

我相信这个错误是由于处理客户端试图构建必要的文件(例如index.html)造成的

仍然不确定是什么导致了错误,但在处理客户机之外简单地使用p5js就解决了本例中的问题