Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  183] [ 1]  / answers: 1 / hits: 16703  / 13 Years ago, thu, september 1, 2011, 12:00:00

Is there a sleep() function for Processing.js? If not what would be a suitable alternative to add a delay in the draw() loop?



I am using JQuery with Processing - can I use a JQuery or Javascript function to cause a sleep type delay in the loop?



Thanks!


More From » jquery

 Answers
80

Processing has a delay() function but unfortunately that is not implemented into Processing.js yet.



You can mix JS(JQuery,etc.) with Processing though.
Processing 1.9.9 has a Javascript mode now and there are examples for Processing/DOM integration, like SelectionFlower.
In the sketch/pde file there is a method setup to be called form js:



// called from JavaScript
void setSelectionText ( String txt )
{
selectedText = txt;
}


and in the js file, a timeout is set to make sure the sketch is initialized and can be accessed:



var mySketchInstance;

// called once the page has fully loaded
window.onload = function () {
getSketchInstance();
}

// this is called (repeatedly) to find the sketch
function getSketchInstance() {
var s = Processing.instances[0];
if ( s == undefined ) {
setTimeout(getSketchInstance, 200); // try again a bit later

} else {
mySketchInstance = s;
monitorSelection();
}
}


Then when the sketch instance is available, you can simply call a method/function on the sketch:



function monitorSelection () {
//bla bla
mySketchInstance.setSelectionText(txt); // set the text in the sketch
}


HTH


[#90306] Wednesday, August 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emileef

Total Points: 724
Total Questions: 108
Total Answers: 102

Location: Romania
Member since Sun, Dec 20, 2020
3 Years ago
;