我试图在处理过程中创建一个带有三个椭圆的垂直轮播。我可以用两个椭圆来完成这件事--旋转木马一遍又一遍地重复自己。到目前为止还不错-它认为我可以对三个使用相同的逻辑,但我错了。我开始认为它适用于更多的变量,但又错了…我在逻辑中遗漏了什么?我真的想不出如何设置这些值来使其无缝地重复自身…
下面是两个例子(这个是“无缝”的):
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;}
}这是我的三个…的在制品(顺便说一句,颜色只是为了看得更好):
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 ;
}
}有三个变量的第一个总是从所有变量的初始点开始-但我认为使用单独的变量会改变它?
感谢您的任何帮助!
发布于 2021-01-17 06:23:15
我自己找到了一个解决方案!我使用了一个技巧--我使用了一个循环,并且使用了四个而不是三个--最后你只能看到三个!
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;
}
}https://stackoverflow.com/questions/65754784
复制相似问题