Processing 我能不能使我的代码的一部分在处理中不活跃?

Processing 我能不能使我的代码的一部分在处理中不活跃?,processing,Processing,我试图在夜空中制造星星。问题是,由于某种原因,当星星不停地闪烁,不停地停留在原地时。现在,我的代码如下所示: float r1 = 14; float r2 = 59; float g1 = 4; float g2 = 136; float b1 = 77; float b2 = 237; int smX = 350; int smY = 310; void setup() { size(500, 600); smooth(); noStroke(); } void draw ()

我试图在夜空中制造星星。问题是,由于某种原因,当星星不停地闪烁,不停地停留在原地时。现在,我的代码如下所示:

float r1 = 14;
float r2 = 59;
float g1 = 4;
float g2 = 136;
float b1 = 77;
float b2 = 237;
int smX = 350;
int smY = 310;
void setup() {
  size(500, 600);
  smooth();
  noStroke();
}
void draw () {

  //sky&background stuff
  for(float i = 0; i <= 600; i++) {
   float r = lerp(r1, r2, i/600);
   float g = lerp(g1, g2, i/600);
   float b = lerp(b1, b2, i/600);
   stroke(r, g, b);
   line(0, i, width, i);
 }

   for (int s = 0; s < 40; s++) {
   stroke(255);
   float starX = random(0, 500);
   float starY = random(0, 600);
   if (s < 40) {
   line(starX, starY,starX, starY);
   }
}
}
float r1=14;
浮点数r2=59;
浮点数g1=4;
浮点数g2=136;
浮点数b1=77;
浮点数b2=237;
int smX=350;
int smY=310;
无效设置(){
大小(500600);
光滑的();
仰泳();
}
无效提款(){
//天空和背景材料

对于(float i=0;i而不是每次调用draw()时重新计算新的随机值,您能否在setup()中只计算一次随机值,然后将它们存储到两个数组中,然后让draw()使用数组中的值绘制星星?这样,每次draw()时星星的位置都会相同调用。

您只需将函数添加到设置方法的末尾即可

void setup() {
 //rest of your code
 noLoop();
}

这将停止处理在
draw()

中连续执行代码,这将起作用,但实际上这正是noLoop方法的用途。