How to have multiple processing.js sketches running at the same time

不问归期 提交于 2019-12-22 06:36:02

问题


I'm trying to run multiple sketches on the same page.

The init script specifies that:

/*
* 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.
*/

When I specify the target canvas of each sketch, it does not work:

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

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

but it isn't working? is this even possible? Any help would be much appreciated. Im trying to have a document with inline canvas elements running a sketches in sync with each other.


回答1:


Got it working by setting ids for the script and canvas tags:

<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:


I couldn't get the above implementation to work, but this works for me...

    <!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>

Make "script1.pde" & "script2.pde" a functioning Processing program and store in the same directory as the html page.



来源:https://stackoverflow.com/questions/1918347/how-to-have-multiple-processing-js-sketches-running-at-the-same-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!