Mating Processingjs and JQuery

In my latest weekend project, I wanted to integrate jquery with processingjs. The way processingjs is developed, it’s requires a little trick to fire up processingjs at will. Though after much struggling I came up with following.


$(document).ready(function() {

dom_el = $("#canvas").get(0);

code = ''; /* fetch source string using ajax or hard code it */

stage.set_stage(function() {
stage_instance = new Processing(dom_el, code);
});
}

Code is pretty much self explanatory. The real essence is the Processing() constructor. It takes two arguments viz: Canvas DOM element and the source code string.

You can always fetch source code from a file using $.ajax(). I am using $.get();