Processing.DynamicLoad History

Hide minor edits - Show changes to output - Cancel

 
 
April 08, 2014, at 04:07 PM by MichaelPaulukonis -
Added lines 1-39:
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.

(:source lang=javascript:)
Processing.loadSketchFromSources(canvas, ["pixel8.pde"]);
(:sourceend:)

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


(:source lang=javascript:)
var oldp = Processing.getInstanceById('jstest');
if (oldp) oldp.exit();
(:sourceend:)


@@Processing.instances[n]@@ does not appear to work, despite assurances in [[http://processing-js.lighthouseapp.com/projects/41284-processingjs/tickets/1881-processinginstances-is-empty-after-sketch-already-started|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.

(:source lang=javascript:)

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

(:sourceend:)