2009-12-16 30 views
5

我試圖在同一頁上運行多個草圖。如何同時運行多個processing.js草圖

初始化腳本規定:

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

,但它不工作?這甚至有可能嗎?任何幫助將非常感激。我試圖讓一個文檔與內嵌畫布元素相互同步運行一個草圖。

回答

6

得到它通過設置IDS的腳本和帆布標籤工作:

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

我不能讓上面的實施工作,但這個工作對我來說...

<!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」一個正在運行的Processing程序並存儲在與html頁面相同的目錄中。