【问题标题】:processing.js examples not workingprocessing.js 示例不起作用
【发布时间】:2016-02-25 01:31:42
【问题描述】:

我正在查看 Processing.js 快速入门示例: http://processingjs.org/articles/jsQuickStart.html 并尝试复制这个“简单”示例:

 <!DOCTYPE html>
 <html>
 <head>
   <title>Hello Web - Processing.js Test</title>
   <script src="https://cdn.rawgit.com/processing-js/processing-js/v1.4.8/processing.js"></script>
</head>
<body>
  <h1>Processing.js Test</h1>
    <p>This is my first Processing.js web-based sketch:</p>
    <canvas data-processing-sources="hello.pde"></canvas>
</body>
</html>

这是我的hello.pde 文件的样子:

void setup() {
size(200, 200);
background(100);
stroke(255);
ellipse(50, 50, 25, 25);
println("hello web!");
}

另外,我已将 .pde 和 .html 两个文件都放入我的 MAMP 服务器,并通过localhost:http://localhost:8888/testprocessing.html 访问它们

但是画布上什么也没有出现,我在控制台中收到此错误: processing.js:799 Uncaught SyntaxError: Unexpected string。 这是第 799 行 processing.js 中的代码:

function loadBlock(index, filename) {
  function callback(block, error) {
    code[index] = block;
    ++loaded;
    if (error) {
      errors.push(filename + " ==> " + error);
    }
    if (loaded === sourcesCount) {
      if (errors.length === 0) {
        try {
          return new Processing(canvas, code.join("\n"));
        } catch(e) {
          console.log("Processing.js: Unable to execute pjs sketch.");
          throw e; //this is line 799
        }
      } else {
        throw "Processing.js: Unable to load pjs sketch files: " + errors.join("\n");
      }
    }
  }

我对javascript很陌生,错误来自processing.js文件,而不是我的代码,谁能解释一下?谢谢!

【问题讨论】:

  • 尝试使用非缩小版本,也许它会更能描述错误可能是什么cdn.rawgit.com/processing-js/processing-js/v1.4.8/processing.js
  • @ClaytonSmith 我按照你的建议做了,这就是我得到的......
  • @ClaytonSmith 非常感谢!从 .js 文件中的错误中,我回顾了我的 .pde 文件,发现当我复制粘贴代码时,我将行号留在了.. oups... 我删除了这些,一切正常。哎呀..

标签: processing.js


【解决方案1】:

您需要使用当前使用的库的全名重写处理库的路径。

例如,如果你使用 1.4.8 版本,你必须写://./././processing-1.4.8.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 2013-12-04
    • 2016-08-31
    • 2015-01-23
    • 2017-09-11
    • 1970-01-01
    • 2011-11-13
    相关资源
    最近更新 更多