如何将变量重置回其完整值?
How to reset a variable back to its full value?
我该如何将 y 重置为完整值?模运算符在 x 上工作,因为变量从 0 开始并且它一直增加到宽度,但我不知道要写什么 y 以将其重置回完整 value.I 不能使用超过声明的 2 variables.Thank求你帮忙
int y=height;
int x=0;
void setup()
{
size(100,100);
frameRate(30);
}
void draw()
{
background(200);
line(0,y,width,y); //bottom to top
line(0,x,width,x); // top to bottom
line(y,0,y,height); //left to right
line(x,0,x,height); //right to left
y=y-1;
x = (x+1) % width;
}
您可以只使用 if
语句在变量达到特定值时重置变量。像这样:
y = y - 1;
if(y < 0){
y = height;
}
无耻的自我推销:我在Processing中写了一个关于动画的教程,包括这个重置技术,可用here。
我该如何将 y 重置为完整值?模运算符在 x 上工作,因为变量从 0 开始并且它一直增加到宽度,但我不知道要写什么 y 以将其重置回完整 value.I 不能使用超过声明的 2 variables.Thank求你帮忙
int y=height;
int x=0;
void setup()
{
size(100,100);
frameRate(30);
}
void draw()
{
background(200);
line(0,y,width,y); //bottom to top
line(0,x,width,x); // top to bottom
line(y,0,y,height); //left to right
line(x,0,x,height); //right to left
y=y-1;
x = (x+1) % width;
}
您可以只使用 if
语句在变量达到特定值时重置变量。像这样:
y = y - 1;
if(y < 0){
y = height;
}
无耻的自我推销:我在Processing中写了一个关于动画的教程,包括这个重置技术,可用here。