【问题标题】:How to have multiple processing.js sketches running at the same time如何同时运行多个 processing.js 草图
【发布时间】:2009-12-16 22:43:55
【问题描述】:

我正在尝试在同一页面上运行多个草图。

初始化脚本指定:

/*
* This code searches for all the <script type="application/processing" target="canvasid">
* in your page and loads each script in the target canvas with the proper id.
* It is useful to smooth the process of adding Processing code in your page and starting
* the Processing.js engine.
*/

当我指定每个草图的目标画布时,它不起作用:

<script type="application/processing" target="canvas1">..</script>
<script type="application/processing" target="canvas2">..</script>

<canvas id="canvas1".. />
<canvas id="canvas2".. />

但它不起作用?这甚至可能吗?任何帮助将非常感激。我试图让一个带有内联画布元素的文档彼此同步运行草图。

【问题讨论】:

    标签: processing.js


    【解决方案1】:

    通过为脚本和画布标签设置 id 使其工作:

    <script type="application/processing" id="script1">..</script>
    <script type="application/processing" id="script2">..</script>
    
    <canvas id="canvas1" width="200px" height="200px"></canvas>
    <canvas id="canvas2" width="200px" height="200px"></canvas>
    <script>
      canvas1 = document.getElementById("canvas1");
      script1 = document.getElementById("script1").text;
      canvas2 = document.getElementById("canvas2");
      script2 = document.getElementById("script2").text;
      Processing(canvas1, script1);
      Processing(canvas2, script2);
    </script>
    

    【讨论】:

      【解决方案2】:

      我无法让上述实现工作,但这对我有用...

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" >
          <head>
              <script src="processing-1.4.1.min.js"></script>
              <title>title</title>
          </head>
          <body>
      
              <script type="application/processing" id="script1" src="script1.pde" data-processing-target="pjs1"></script>
              <canvas id="pjs1"> </canvas>
      
              <script type="application/processing" id="script2" src="script2.pde" data-processing-target="pjs2"></script>
              <canvas id="pjs2"> </canvas>
      
          </body>
          </html>
      

      使“script1.pde”和“script2.pde”成为一个正常运行的处理程序,并存储在与html页面相同的目录中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多