Processing.js - Sleep, Wait, TimeOut, Pause, Delay?

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

I use jQuery with processing - can I use a jQuery or Javascript function to cause a sleep delay in the loop?

Thank!

+5
source share
4 answers

Processing has a delay () function , but unfortunately it is not yet implemented in Processing.js.

JS (JQuery ..) . 1.9.9 Javascript, Processing/DOM, SelectionFlower. /pde , form js:

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

js , , :

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();
    }
}

, , / :

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

+3

.

void waitasec (int sec) {

   int minutes = minute();
   int seconds = second();
   int hour = hour();
   int starttime = (hour * 3600) + (minutes * 60) + seconds;
   int finaltime = starttime + sec;

   while (starttime < finaltime) {

       minutes = minute();
       seconds = second();
       starttime = (hour * 3600) + (minutes * 60) + seconds;
   }
}
+3

:

int timer = 0;
void draw() {
 if (timer%50 == 0) {
  //some code here
 }
 timer = timer +1;
}
+2

JQuery

.delay(duration [, queueName])

: .

. http://api.jquery.com/delay/

0

All Articles