Is there a sleep() function for Processing.js? If not what would be a suitable alternative to add a delay in the draw() loop?
是否有一个用于处理。js的sleep()函数?如果不是,那么在draw()循环中添加延迟的合适替代方案是什么?
I am using JQuery with Processing - can I use a JQuery or Javascript function to cause a sleep type delay in the loop?
我正在使用JQuery进行处理——我可以使用JQuery或Javascript函数在循环中导致睡眠类型延迟吗?
Thanks!
谢谢!
4 个解决方案
#1
3
Processing has a delay() function but unfortunately that is not implemented into Processing.js yet.
Processing有一个delay()函数,但不幸的是,它没有实现为Processing。js。
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:
不过,您可以将JS(JQuery等)与处理混合使用。Processing 1.9.9现在有一个Javascript模式,有一些用于处理/DOM集成的例子,比如SelectionFlower。在sketch/pde文件中有一个方法设置为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:
在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();
}
}
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
HTH
#2
3
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;
}
}
#3
2
A resource consuming solution:
资源消耗的解决方案:
int timer = 0;
void draw() {
if (timer%50 == 0) {
//some code here
}
timer = timer +1;
}
#4
0
jQuery
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/
看到这个链接http://api.jquery.com/delay/
#1
3
Processing has a delay() function but unfortunately that is not implemented into Processing.js yet.
Processing有一个delay()函数,但不幸的是,它没有实现为Processing。js。
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:
不过,您可以将JS(JQuery等)与处理混合使用。Processing 1.9.9现在有一个Javascript模式,有一些用于处理/DOM集成的例子,比如SelectionFlower。在sketch/pde文件中有一个方法设置为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:
在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();
}
}
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
HTH
#2
3
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;
}
}
#3
2
A resource consuming solution:
资源消耗的解决方案:
int timer = 0;
void draw() {
if (timer%50 == 0) {
//some code here
}
timer = timer +1;
}
#4
0
jQuery
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/
看到这个链接http://api.jquery.com/delay/