有关如何在处理中定义布尔值的问题
我是编码的新手,并且对以下代码有疑问。 (这是我试图开始处理处理的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上是用这个简单的技巧来的,以:
} 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;
}
}