Processing.js - 睡眠、等待、超时、暂停、延迟?

发布于 2024-12-02 07:17:28 字数 148 浏览 2 评论 0原文

Processing.js 有 sleep() 函数吗?如果不是,在draw()循环中添加延迟的合适替代方案是什么?

我正在使用 JQuery 进行处理 - 我可以使用 JQuery 或 Javascript 函数在循环中引起睡眠类型延迟吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薯片软お妹 2024-12-09 07:17:28

Processing 有一个 delay() 函数,但不幸的是,它还没有在Processing.js 中实现。

不过,您可以将 JS(JQuery 等)与处理混合在一起。
Processing 1.9.9 现在有 Javascript 模式,并且有 Process/DOM 的示例集成,例如 选择花
草图中/pde 文件 有一个方法设置要调用表单 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
}

HTH

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

晚风撩人 2024-12-09 07:17:28

这是我的解决方案。

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

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;
   }
}
污味仙女 2024-12-09 07:17:28

一个消耗资源的解决方案:

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

A resource consuming solution:

int timer = 0;
void draw() {
 if (timer%50 == 0) {
  //some code here
 }
 timer = timer +1;
}
探春 2024-12-09 07:17:28

jQuery

.delay( period [, queueName] )

描述: 设置一个计时器来延迟队列中后续项目的执行。

请参阅链接 http://api.jquery.com/delay/

jQuery

.delay( duration [, queueName] )

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文