noLoop函数用于从循环中停止draw()函数,附加函数loop()和redraw()提供了当组合使用鼠标和键盘事件函数时的更多选择。
如果一个程序被noLoop()函数暂停,loop()函数可恢复其运行。因为在程序被noLoop()函数暂停之后,只有事件函数能继续运行,在事件函数中能拥loop()函数继续运行draw()函数中的代码。
1 int wi; 2 int col; 3 void setup() { 4 size(500, 400); 5 colorMode(HSB, 100); 6 noStroke(); 7 wi = int(random(500)); 8 col = int(random(100)); 9 } 10 void draw() { 11 int x = 0; 12 fill(col, 80, 80); 13 rect(x, 0, wi, height); 14 x = x + wi; 15 } 16 void mousePressed() { 17 setup(); 18 redraw(); 19 }
效果图: