사용자 Alex (https://www.openprocessing.org/user/74843)가 openprocessing.org에서 찾은 코드로 실험 중입니다.p5.js 스케치를 저장 한 후에 구문 오류 만 발생 함
p5.js 모드를 사용하여 처리중인 저장되지 않은 스케치에서 코드를 실행하면 코드가 제대로 실행되지만 나중에 프로젝트를 열려고하면 구문 오류가 발생하고 실행을 거부합니다. 프로젝트를 저장하기 전에 코드가 잘 돌아가는 것처럼 보였으므로 나는 혼란 스럽다.
이 문제의 원인을 아는 사람이 있습니까?
이SyntaxError: Expected ; but found poly
코드는 다음과 같습니다 :
// 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();
}