How to pause and resume draw loop with processing

Simple thing for pause the draw loop in processing using keyboard :
void keyPressed(){ 
final int k = keyCode;
if (k == 'a'){
if (looping){
noLoop();
}else{
loop();
}
 in this case you use the letter a in keyboard to pause and resume the draw loop.

An other way to delay the sketch loop :
in setup :

lastTime = 0;

make it in the loop :
if (millis() <= lastTime){
  Do what you want
 }

and do this for exemple :

void keyPressed(){
  if (lastTime <= millis()){
  lastTime = millis() + 30000;
}else{
  lastTime = millis() - 30000;
}
}

your keyPressed wiat 30s to restart the loop, and if you keyPressed a second time before the and of the 30s, the loop restart. 

Commentaires