Dynamically “unload” a Processing JS sketch from canvas

前端 未结 3 1828
攒了一身酷
攒了一身酷 2021-01-02 15:28

I\'m using some javascript to allow users to dynamically load a sketch on click to a canvas element using:

Processing.loadSketchFromSources(\'canvas_i

3条回答
  •  甜味超标
    2021-01-02 16:02

    As of processing.js 1.4.8, Andrew's accepted answer (and the other answers I've found in here) do not seem to work anymore.

    This is what worked for me:

        var pjs = Processing.getInstanceById('pjs');
        if (typeof pjs !== "undefined") {
          pjs.exit();
        }
    
        var canvas = document.getElementById('pjs')
        new Processing(canvas, scriptText);
    

    where pjs is the id of the canvas element where the scrips is being run.

提交回复
热议问题