我正在尝试使用三个椭圆创建一个垂直轮播。 我可以用两个省略号来完成此操作 - 旋转木马一遍又一遍地重复。 到目前为止一切顺利——它认为我可以对三个使用相同的逻辑,但我错了。我开始认为它适用于更多变量,但又错了……我在逻辑中遗漏了什么?我真的不知道如何设置值以使其无缝重复......
这是两个示例(这个是“无缝”):
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,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, 0);
ellipse(width/2, circleY1, d, d);
circleY1= circleY1 + yspeed1;
if (circleY1 > height+d/2 ) {
circleY1=0;
}
fill(0, 255, 0);
ellipse(width/2, circleY2-810, d, d);
circleY2= circleY2 + yspeed2;
if (circleY2 > height+d/2 ) {
circleY2=0 ;
}
fill(0, 0, 255);
ellipse(width/2, circleY2-1620, d, 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,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;
}
}
关于processing - 处理中三个椭圆的轮播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65754784/