javascript - Processing.js - Sleep, Wait, TimeOut, Pause, Delay? - Stack Overflow

Is there a sleep() function for Processing.js? If not what would be a suitable alternative to add a del

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!

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!

Share Improve this question asked Sep 1, 2011 at 18:04 logic-unitlogic-unit 4,31312 gold badges49 silver badges74 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

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

Here is my solution.

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

A resource consuming solution:

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

jQuery

.delay( duration [, queueName] )

Description: Set a timer to delay execution of subsequent items in the queue.

See the link http://api.jquery./delay/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1740237764a4213738.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信