我的循环不会运行我的程序

时间:2016-04-25 11:28:09

标签: loops for-loop processing

我的音板几乎完成了,我想添加一个forloop来在屏幕上制作正方形。 但是我使用的代码不允许我与屏幕交互,我想知道为什么。谢谢 继承我的代码

class sound {


 float x;
 float y;

 public sound(float x, float y) {
  this.x = x;
  this.y = y;
 }
 void run() {
  draw();
  mousePressed();
 }

 void draw() {
  for (int y = 100; y < width;) {
   for (int x = 100; x < width;) {
    ellipse(x, y, 99, 99);
   }
  }
 }
 public void mousePressed() {
  if (mouseX > 1 && mouseX < 99 && mouseY > 1 && mouseY < 99) {
   s2.play();
   image(p7, 1, 1);
  } else {
   s2.pause();
   s2.rewind();
  }

  if (mouseX > 100 && mouseX < 199 && mouseY > 1 && mouseY < 99) {
   player.play();
   image(p9, 100, 1);
  } else {
   player.pause();
   player.rewind();
  }
  if (mouseX > 200 && mouseX < 300 && mouseY > 1 && mouseY < 99) {
   s7.play();
   image(p6, 200, 1);
  } else {
   s7.pause();
   s7.rewind();
  }

  if (mouseX > 1 && mouseX < 99 && mouseY > 100 && mouseY < 199) {
   s8.play();
   image(p8, 1, 100);
  } else {
   s8.pause();
   s8.rewind();
  }

  if (mouseX > 100 && mouseX < 199 && mouseY > 100 && mouseY < 199) {
   s3.play();
   image(p2, 100, 100);
  } else {
   s3.pause();
   s3.rewind();
  }

  if (mouseX > 200 && mouseX < 300 && mouseY > 100 && mouseY < 199) {
   s6.play();
   image(p5, 200, 100);
  } else {
   s6.pause();
   s6.rewind();
  }

  if (mouseX > 1 && mouseX < 99 && mouseY > 200 && mouseY < 299) {
   s1.play();
   image(p1, 1, 202);
  } else {
   s1.pause();
   s1.rewind();
  }
  if (mouseX > 100 && mouseX < 199 && mouseY > 200 & mouseY < 299) {
   s4.play();
   image(p3, 100, 200);
  } else {
   s4.pause();
   s4.rewind();
  }
  if (mouseX > 200 && mouseX < 299 && mouseY > 200 && mouseY < 299) {
   s5.play();
   image(p4, 200, 200);
  } else {
   s5.pause();
   s5.rewind();
  }

 }

}

1 个答案:

答案 0 :(得分:1)

你没有递增x和y,所以你有无限循环:

  void draw() {
    for(int y = 100; y<width;y++){ // here y++
  for(int x = 100; x<width;x++){ // here x++
    ellipse(x,y,99,99);
  }}
  }