问题描述
我正在尝试使用三个椭圆创建一个垂直旋转木马。 我可以用两个椭圆来完成这个任务——轮播会一遍又一遍地重复。 到目前为止一切顺利——它认为我可以对三个使用相同的逻辑,但我错了。我开始认为它适用于更多变量,但又错了……我在逻辑中遗漏了什么?我真的不知道如何设置值以使其无缝重复......
这里有两个例子(这个是“无缝的”):
float yspeed = 5;
float circleY;
int d = 720;
void setup() {
size(1080,1620 );
circleY = 0;
}
void draw() {
background(255);
fill(0);
nostroke();
ellipse(width/2,circleY+height/2,d,d);
ellipse(width/2,circleY-height/2,d );
circleY = circleY + yspeed;
if (circleY > height) {
circleY=0;}
}
这是我的 WIP 和三个……(顺便说一句,颜色只是为了看得更清楚):
float yspeed1 = 5;
float yspeed2 = 5;
float yspeed3 = 5;
float circleY1;
float circleY2;
float circleY3;
int d = 720;
void setup() {
size(1080,1620);
circleY1 = 0;
circleY2 = 0;
circleY3 = 0;
}
void draw() {
background(255);
nostroke();
fill(255,0);
ellipse(width/2,circleY1,d);
circleY1= circleY1 + yspeed1;
if (circleY1 > height+d/2 ) {
circleY1=0;
}
fill(0,255,circleY2-810,d);
circleY2= circleY2 + yspeed2;
if (circleY2 > height+d/2 ) {
circleY2=0 ;
}
fill(0,255);
ellipse(width/2,circleY2-1620,d);
circleY3= circleY3 + yspeed3;
if (circleY3 > height+d/2 ) {
circleY3=0 ;
}
}
三个总是从初始点开始 - 但我认为使用单个变量会改变它吗?
感谢您的任何帮助!
解决方法
我自己找到了解决方案!我使用了一个技巧——我用一个循环来做到这一点,并使用了四个而不是三个——无论如何你最终只能看到三个!
float yspeed = 1;
float circleY;
int d = 360;
void setup() {
size(540,810 );
circleY = 0;
}
void draw() {
background(255);
fill(0);
noStroke();
// fill(255,0);
translate(0,- height/2);
for (int i = 0; i< 5; i++) {
ellipse(width/2,circleY+height/2*i,d,d);
}
circleY = circleY + yspeed;
if (circleY > 405) {
circleY= 0;
}
}