有关如何在处理中定义布尔值的问题

发布于 2025-01-24 02:23:56 字数 1016 浏览 0 评论 0原文

我是编码的新手,并且对以下代码有疑问。 (这是我试图开始处理处理的Java程序)我希望它能用Count_up增长圆圈,但是当其中一个圆圈达到最大宽度时(以某种方式循环循环操作)我试图通过进行此操作,如果... else,但我不知道该如何定义它,以使其正常工作。

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 

  if ( count_up < width/2) {
  
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
  }
 else {
    fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up -= 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down += 2;
  }
}

这是该代码应该做的,但并非无关紧要:

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 
  background (233);
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
 
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
 
 }

I am very new to coding and have a question regarding the code below. (It's a Java program I'm trying to get to work in processing) I'd like it to grow the circle with the count_up, but when one of the circles reaches the max width to go back again (in a way to loop the action) I was trying to make this happen with if...else but I don't know how I should define the if so that it's working.

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 

  if ( count_up < width/2) {
  
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
  }
 else {
    fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up -= 1;
  
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down += 2;
  }
}

This is what the code is supposed to do but without growing indefinetly:

int count_up = 0;
int count_down = 500;

void setup() 
{
  size(500, 500);
}

void draw() { 
  background (233);
fill(170, 172, 204, 150);
  circle(width/2, height/2, count_up);
  count_up += 1;
 
  fill(250, 191, 171, 100);
  circle(width/2, height/2, count_down);
  count_down -= 2;
 
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2025-01-31 02:23:56

我实际上是用这个简单的技巧来的,以:

} else {

count_up = 0;
count_down = 500;

}
}

I actually got it with this simple trick, to define else as:

} else {

count_up = 0;
count_down = 500;

}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文