dynamic loading and unloading of sketch.

 

Why?

 

well, say you change the images for a PImage which has to be preloaded (NB: maybe not?)
or you want to change the canvas size, which has to be the first thing set up in setup.

 

Processing.loadSketchFromSources(canvas, ["pixel8.pde"]);

 

Also, dynamic unloading of previously loaded code, because otherwise it’ll just start running again

 

 

var oldp = Processing.getInstanceById('jstest');
if (oldp) oldp.exit();

 

 

Processing.instances[n] does not appear to work, despite assurances in this bug

 

 

http://stackoverflow.com/questions/10281747/how-to-know-when-a-processingjs-sketch-has-been-loaded - not evaluated
http://stackoverflow.com/questions/11178450/dynamically-unload-a-processing-js-sketch-from-canvas

 

 

TODO: some morel links to sources, and notes.

 

Also, I’ve found that pre-loading a PImage with a data-uri still takes time to load.

 


  // wait until image is REALLY loaded from URI
  // crude
  if (img.pixels.length <= 10) return;