2017-03-14 6 views
0

사용자 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(); 
} 

답변

0

내가 대신 숭고한 텍스트 편집기에서 프로젝트를 열고 WAMP를 사용하여 로컬 서버를 실행

컴파일러는 나에게 다음과 같은 오류를 제공합니다/MAMP와 javascript는 잘 돌아갑니다.

이 오류는 처리 클라이언트가 필요한 파일 (예 : index.html)을 작성하려고했기 때문에 발생했다고 생각합니다.

오류의 원인은 무엇인지 모르지만 처리 클라이언트 외부의 p5js와 작업하면이 경우 문제가 해결됩니다.